Skip to content

Commit 92fd8c8

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

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-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

0 commit comments

Comments
 (0)