MCPcopy
hub / github.com/google/go-containerregistry / TestFilesystemCache

Function TestFilesystemCache

pkg/v1/cache/fs_test.go:29–151  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestFilesystemCache(t *testing.T) {
30 dir := t.TempDir()
31
32 numLayers := 5
33 img, err := random.Image(10, int64(numLayers))
34 if err != nil {
35 t.Fatalf("random.Image: %v", err)
36 }
37 c := NewFilesystemCache(dir)
38 img = Image(img, c)
39
40 // Read all the (compressed) layers to populate the cache.
41 ls, err := img.Layers()
42 if err != nil {
43 t.Fatalf("Layers: %v", err)
44 }
45 for i, l := range ls {
46 rc, err := l.Compressed()
47 if err != nil {
48 t.Fatalf("layer[%d].Compressed: %v", i, err)
49 }
50 if _, err := io.Copy(io.Discard, rc); err != nil {
51 t.Fatalf("Error reading contents: %v", err)
52 }
53 rc.Close()
54 }
55
56 // Check that layers exist in the fs cache.
57 dirEntries, err := os.ReadDir(dir)
58 if err != nil {
59 t.Fatalf("ReadDir: %v", err)
60 }
61 if got, want := len(dirEntries), numLayers; got != want {
62 t.Errorf("Got %d cached files, want %d", got, want)
63 }
64 for _, de := range dirEntries {
65 fi, err := de.Info()
66 if err != nil {
67 t.Fatal(err)
68 }
69 if fi.Size() == 0 {
70 t.Errorf("Cached file %q is empty", fi.Name())
71 }
72 }
73
74 // Read all (uncompressed) layers, those populate the cache too.
75 for i, l := range ls {
76 rc, err := l.Uncompressed()
77 if err != nil {
78 t.Fatalf("layer[%d].Compressed: %v", i, err)
79 }
80 if _, err := io.Copy(io.Discard, rc); err != nil {
81 t.Fatalf("Error reading contents: %v", err)
82 }
83 rc.Close()
84 }
85
86 // Check that double the layers are present now, both compressed and

Callers

nothing calls this directly

Calls 11

ImageFunction · 0.92
NewFilesystemCacheFunction · 0.85
ImageFunction · 0.70
LayersMethod · 0.65
CompressedMethod · 0.65
CloseMethod · 0.65
SizeMethod · 0.65
NameMethod · 0.65
UncompressedMethod · 0.65
DigestMethod · 0.65
DeleteMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…