@@ -26,18 +26,7 @@ import (
26
26
"github.com/GoogleCloudPlatform/container-diff/pkg/cache"
27
27
)
28
28
29
- var c * cache.FileCache
30
-
31
- func TestCacheData (t * testing.T ) {
32
- data := "this is a test of caching some bytes. this could be any data."
33
- cacheAndTest (t , data , "sha256:realdata" )
34
- }
35
-
36
- func TestCacheEmpty (t * testing.T ) {
37
- cacheAndTest (t , "" , "sha256:emptydata" )
38
- }
39
-
40
- func cacheAndTest (t * testing.T , testStr string , layerId string ) {
29
+ func cacheAndTest (c * cache.FileCache , t * testing.T , testStr string , layerId string ) {
41
30
byteArr := []byte (testStr )
42
31
r := bytes .NewReader (byteArr )
43
32
@@ -60,18 +49,29 @@ func cacheAndTest(t *testing.T, testStr string, layerId string) {
60
49
}
61
50
}
62
51
63
- func TestMain (m * testing.M ) {
64
- var err error
52
+ func TestCache (t * testing.T ) {
65
53
cacheDir , err := ioutil .TempDir ("" , ".cache" )
66
54
if err != nil {
67
55
fmt .Printf (err .Error ())
68
56
os .Exit (1 )
69
57
}
70
58
defer os .RemoveAll (cacheDir )
71
- c , err = cache .NewFileCache (cacheDir )
59
+ c , err : = cache .NewFileCache (cacheDir )
72
60
if err != nil {
73
61
fmt .Printf (err .Error ())
74
62
os .Exit (1 )
75
63
}
76
- os .Exit (m .Run ())
64
+ testRuns := []struct {
65
+ Name string
66
+ Data string
67
+ LayerId string
68
+ }{
69
+ {"real data" , "this is a test of caching some bytes. this could be any data." , "sha256:realdata" },
70
+ {"empty data" , "" , "sha256:emptydata" },
71
+ }
72
+ for _ , test := range testRuns {
73
+ t .Run (test .Name , func (t * testing.T ) {
74
+ cacheAndTest (c , t , test .Data , test .LayerId )
75
+ })
76
+ }
77
77
}
0 commit comments