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

Function TestLayersLazy

pkg/v1/cache/cache_test.go:69–96  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

67}
68
69func TestLayersLazy(t *testing.T) {
70 img, err := random.Image(1024, 5)
71 if err != nil {
72 t.Fatalf("random.Image: %v", err)
73 }
74 m := &memcache{map[v1.Hash]v1.Layer{}}
75 img = Image(img, m)
76
77 layers, err := img.Layers()
78 if err != nil {
79 t.Fatalf("img.Layers: %v", err)
80 }
81
82 // After calling Layers, nothing is cached.
83 if got, want := len(m.m), 0; got != want {
84 t.Errorf("Cache has %d entries, want %d", got, want)
85 }
86
87 rc, err := layers[0].Uncompressed()
88 if err != nil {
89 t.Fatalf("layer.Uncompressed: %v", err)
90 }
91 io.Copy(io.Discard, rc)
92
93 if got, expected := len(m.m), 1; got != expected {
94 t.Errorf("expected %v layers in cache after reading, got %v", expected, got)
95 }
96}
97
98// TestCacheShortCircuit tests that if a layer is found in the cache,
99// LayerByDigest is not called in the underlying Image implementation.

Callers

nothing calls this directly

Calls 4

ImageFunction · 0.92
ImageFunction · 0.70
LayersMethod · 0.65
UncompressedMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…