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

Function TestConfigLayer

pkg/v1/partial/configlayer_test.go:48–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

46}
47
48func TestConfigLayer(t *testing.T) {
49 cases := []v1.Image{
50 &compressedImageExtender{
51 CompressedImageCore: testCIC{
52 configFile: []byte("{}"),
53 },
54 },
55 &uncompressedImageExtender{
56 UncompressedImageCore: testUIC{
57 configFile: []byte("{}"),
58 },
59 },
60 }
61
62 for _, image := range cases {
63 hash, err := image.ConfigName()
64 if err != nil {
65 t.Fatalf("Error getting config name: %v", err)
66 }
67
68 if _, err := image.LayerByDigest(hash); err == nil {
69 t.Error("LayerByDigest(config hash) returned nil error, wanted error")
70 }
71
72 layer, err := ConfigLayer(image)
73 if err != nil {
74 t.Fatalf("ConfigLayer: %v", err)
75 }
76 lr, err := layer.Uncompressed()
77 if err != nil {
78 t.Fatalf("Error getting uncompressed layer: %v", err)
79 }
80 zr, err := layer.Compressed()
81 if err != nil {
82 t.Fatalf("Error getting compressed layer: %v", err)
83 }
84
85 cfgLayerBytes, err := io.ReadAll(lr)
86 if err != nil {
87 t.Fatalf("Error reading config layer bytes: %v", err)
88 }
89 zcfgLayerBytes, err := io.ReadAll(zr)
90 if err != nil {
91 t.Fatalf("Error reading config layer bytes: %v", err)
92 }
93
94 cfgFile, err := image.RawConfigFile()
95 if err != nil {
96 t.Fatalf("Error getting raw config file: %v", err)
97 }
98
99 if string(cfgFile) != string(cfgLayerBytes) {
100 t.Errorf("Config file layer doesn't match raw config file")
101 }
102 if string(cfgFile) != string(zcfgLayerBytes) {
103 t.Errorf("Config file layer doesn't match raw config file")
104 }
105

Callers

nothing calls this directly

Calls 11

ConfigLayerFunction · 0.85
ConfigNameMethod · 0.65
LayerByDigestMethod · 0.65
UncompressedMethod · 0.65
CompressedMethod · 0.65
RawConfigFileMethod · 0.65
SizeMethod · 0.65
DigestMethod · 0.65
DiffIDMethod · 0.65
MediaTypeMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…