Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit b8e9351

Browse files
committed
switch to subtests
1 parent 75eb378 commit b8e9351

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

util/file_cache_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,7 @@ import (
2626
"github.com/GoogleCloudPlatform/container-diff/pkg/cache"
2727
)
2828

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) {
4130
byteArr := []byte(testStr)
4231
r := bytes.NewReader(byteArr)
4332

@@ -60,18 +49,29 @@ func cacheAndTest(t *testing.T, testStr string, layerId string) {
6049
}
6150
}
6251

63-
func TestMain(m *testing.M) {
64-
var err error
52+
func TestCache(t *testing.T) {
6553
cacheDir, err := ioutil.TempDir("", ".cache")
6654
if err != nil {
6755
fmt.Printf(err.Error())
6856
os.Exit(1)
6957
}
7058
defer os.RemoveAll(cacheDir)
71-
c, err = cache.NewFileCache(cacheDir)
59+
c, err := cache.NewFileCache(cacheDir)
7260
if err != nil {
7361
fmt.Printf(err.Error())
7462
os.Exit(1)
7563
}
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+
}
7777
}

0 commit comments

Comments
 (0)