Skip to content

Commit cc9a461

Browse files
committed
tests: Get and Put
1 parent ad84286 commit cc9a461

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

internal/cache/cache_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,47 @@ func fakePackage() *packages.Package {
4444
}
4545
}
4646

47+
type Foo struct {
48+
Value string
49+
}
50+
51+
func TestCache_Put(t *testing.T) {
52+
t.Setenv("GOLANGCI_LINT_CACHE", t.TempDir())
53+
54+
pkgCache := setupCache(t)
55+
56+
pkg := fakePackage()
57+
58+
in := &Foo{Value: "hello"}
59+
60+
err := pkgCache.Put(pkg, HashModeNeedAllDeps, "key", in)
61+
require.NoError(t, err)
62+
63+
out := &Foo{}
64+
err = pkgCache.Get(pkg, HashModeNeedAllDeps, "key", out)
65+
require.NoError(t, err)
66+
67+
assert.Equal(t, in, out)
68+
69+
pkgCache.Close()
70+
}
71+
72+
func TestCache_Get_missing_data(t *testing.T) {
73+
t.Setenv("GOLANGCI_LINT_CACHE", t.TempDir())
74+
75+
pkgCache := setupCache(t)
76+
77+
pkg := fakePackage()
78+
79+
out := &Foo{}
80+
err := pkgCache.Get(pkg, HashModeNeedAllDeps, "key", out)
81+
require.Error(t, err)
82+
83+
require.ErrorIs(t, err, ErrMissing)
84+
85+
pkgCache.Close()
86+
}
87+
4788
func TestCache_buildKey(t *testing.T) {
4889
pkgCache := setupCache(t)
4990

internal/go/cache/default.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ func DefaultDir() (string, bool) {
8080

8181
defaultDirOnce.Do(func() {
8282
defaultDir = os.Getenv(envGolangciLintCache)
83+
println(envGolangciLintCache, defaultDir)
84+
8385
if defaultDir != "" {
8486
defaultDirChanged = true
8587
if filepath.IsAbs(defaultDir) || defaultDir == "off" {

0 commit comments

Comments
 (0)