@@ -16,20 +16,20 @@ func TestStore(t *testing.T) {
16
16
}
17
17
18
18
bc := BuildCache {}
19
- if got := bc .LoadArchive (want .ImportPath ); got != nil {
19
+ if got := bc .LoadArchive (want .ImportPath , "" ); got != nil {
20
20
t .Errorf ("Got: %s was found in the cache. Want: empty cache." , got .ImportPath )
21
21
}
22
- bc .StoreArchive (want )
23
- got := bc .LoadArchive (want .ImportPath )
22
+ bc .StoreArchive (want , "" )
23
+ got := bc .LoadArchive (want .ImportPath , "" )
24
24
if got == nil {
25
- t .Errorf ("Got: %s wan not found in the cache. Want: archive is can be loaded after store." , want .ImportPath )
25
+ t .Errorf ("Got: %s was not found in the cache. Want: archive can be loaded after store." , want .ImportPath )
26
26
}
27
27
if diff := cmp .Diff (want , got ); diff != "" {
28
28
t .Errorf ("Loaded archive is different from stored (-want,+got):\n %s" , diff )
29
29
}
30
30
31
31
// Make sure the package names are a part of the cache key.
32
- if got := bc .LoadArchive ("fake/other" ); got != nil {
32
+ if got := bc .LoadArchive ("fake/other" , "" ); got != nil {
33
33
t .Errorf ("Got: fake/other was found in cache: %#v. Want: nil for packages that weren't cached." , got )
34
34
}
35
35
}
@@ -61,15 +61,57 @@ func TestInvalidation(t *testing.T) {
61
61
62
62
for _ , test := range tests {
63
63
a := & compiler.Archive {ImportPath : "package/fake" }
64
- test .cache1 .StoreArchive (a )
64
+ test .cache1 .StoreArchive (a , "" )
65
65
66
- if got := test .cache2 .LoadArchive (a .ImportPath ); got != nil {
66
+ if got := test .cache2 .LoadArchive (a .ImportPath , "" ); got != nil {
67
67
t .Logf ("-cache1,+cache2:\n %s" , cmp .Diff (test .cache1 , test .cache2 ))
68
68
t .Errorf ("Got: %v loaded from cache. Want: build parameter change invalidates cache." , got )
69
69
}
70
70
}
71
71
}
72
72
73
+ func TestDoNotReuseCacheWhenLoadingPackageForTest (t * testing.T ) {
74
+ cacheForTest (t )
75
+
76
+ sharedPkgArchive := & compiler.Archive {
77
+ ImportPath : "fake/sharedTestPkg" ,
78
+ }
79
+
80
+ bc := BuildCache {}
81
+ if got := bc .LoadArchive (sharedPkgArchive .ImportPath , "fake/pkg1" ); got != nil {
82
+ t .Errorf ("Got: %s was found in the cache. Want: empty cache." , got .ImportPath )
83
+ }
84
+ bc .StoreArchive (sharedPkgArchive , "fake/package_1" )
85
+
86
+ // sharedPkgArchive has not been stored with *_test.go sources, so it cannot be reused
87
+ if got := bc .LoadArchive (sharedPkgArchive .ImportPath , sharedPkgArchive .ImportPath ); got != nil {
88
+ t .Errorf ("Got: %s was found in the cache. Want: empty cache." , got .ImportPath )
89
+ }
90
+ }
91
+
92
+ func TestDifferentSourcesCanShareSameArchive (t * testing.T ) {
93
+ cacheForTest (t )
94
+
95
+ sharedPkgArchive := & compiler.Archive {
96
+ ImportPath : "fake/sharedTestPkg" ,
97
+ }
98
+
99
+ bc := BuildCache {}
100
+ if got := bc .LoadArchive (sharedPkgArchive .ImportPath , "fake/pkg1" ); got != nil {
101
+ t .Errorf ("Got: %s was found in the cache. Want: empty cache." , got .ImportPath )
102
+ }
103
+ bc .StoreArchive (sharedPkgArchive , "fake/package_1" )
104
+
105
+ // sharedPkgArchive has been stored without *_test.go sources, so it can be reused
106
+ if got := bc .LoadArchive (sharedPkgArchive .ImportPath , "fake/pkg2" ); got == nil {
107
+ t .Errorf ("Got: %s was not found in the cache. Want: archive can be loaded after store." , sharedPkgArchive .ImportPath )
108
+ }
109
+
110
+ if got := bc .LoadArchive (sharedPkgArchive .ImportPath , "" ); got == nil {
111
+ t .Errorf ("Got: %s was not found in the cache. Want: archive can be loaded after store." , sharedPkgArchive .ImportPath )
112
+ }
113
+ }
114
+
73
115
func cacheForTest (t * testing.T ) {
74
116
t .Helper ()
75
117
originalRoot := cacheRoot
0 commit comments