Skip to content

Commit 0e8f01b

Browse files
trying json encoding
1 parent a848e87 commit 0e8f01b

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

build/cache/cache_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,47 @@ func TestOldCache(t *testing.T) {
114114
}
115115
}
116116

117+
func TestSkipOfTestPackage(t *testing.T) {
118+
cacheForTest(t)
119+
120+
const data = `fake/data`
121+
const importPath = "fake/package"
122+
want := &CacheableMock{Data: data}
123+
srcModTime := newTime(0.0)
124+
buildTime := newTime(5.0)
125+
126+
bc := BuildCache{}
127+
if !bc.Store(want, importPath, buildTime) {
128+
t.Errorf("Failed to store %s with %q.", importPath, want.Data)
129+
}
130+
131+
// Simulate writing a cache for a pacakge under test.
132+
bc.TestedPackage = importPath
133+
if bc.Store(want, importPath, buildTime) {
134+
t.Errorf("Got: cache stored for %q. Want: test packages to not write to cache.", importPath)
135+
}
136+
if bc.Store(want, importPath+"_test", buildTime) {
137+
t.Errorf("Got: cache stored for %q. Want: test packages to not write to cache.", importPath+"_test")
138+
}
139+
140+
// Simulate reading the cache for a pacakge under test.
141+
got := &CacheableMock{}
142+
if bc.Load(got, importPath, srcModTime) {
143+
t.Errorf("Got: cache with %q. Want: test package cache to not be loaded for %q.", got.Data, importPath)
144+
}
145+
got = &CacheableMock{}
146+
if bc.Load(got, importPath+"_test", srcModTime) {
147+
t.Errorf("Got: cache with %q. Want: test package cache to not be loaded for %q.", got.Data, importPath+"_test")
148+
}
149+
150+
// No package under test, cache should work normally and load previously stored non-test package.
151+
bc.TestedPackage = ""
152+
got = &CacheableMock{}
153+
if !bc.Load(got, importPath, srcModTime) || got.Data != want.Data {
154+
t.Errorf("Got: cache with %q. Want: up-to-date package cache to be loaded with %q.", got.Data, want.Data)
155+
}
156+
}
157+
117158
func cacheForTest(t *testing.T) {
118159
t.Helper()
119160
originalRoot := cacheRoot

0 commit comments

Comments
 (0)