|
15 | 15 | package schema_test |
16 | 16 |
|
17 | 17 | import ( |
18 | | - "crypto/sha256" |
19 | | - "encoding/hex" |
20 | | - "fmt" |
21 | 18 | "strings" |
22 | 19 | "testing" |
23 | 20 |
|
@@ -110,16 +107,14 @@ func TestBackwardsCompatibilityManifestList(t *testing.T) { |
110 | 107 | fail: false, |
111 | 108 | }, |
112 | 109 | } { |
113 | | - sum := sha256.Sum256([]byte(tt.manifest)) |
114 | | - got := fmt.Sprintf("sha256:%s", hex.EncodeToString(sum[:])) |
115 | | - if tt.digest != got { |
116 | | - t.Errorf("test %d: expected digest %s but got %s", i, tt.digest, got) |
117 | | - } |
118 | | - |
119 | 110 | manifest := convertFormats(tt.manifest) |
120 | | - r := strings.NewReader(manifest) |
121 | | - err := schema.MediaTypeManifestList.Validate(r) |
122 | | - |
| 111 | + reader := strings.NewReader(manifest) |
| 112 | + descriptor := v1.Descriptor{ |
| 113 | + MediaType: v1.MediaTypeImageManifestList, |
| 114 | + Digest: tt.digest, |
| 115 | + Size: int64(len(manifest)), |
| 116 | + } |
| 117 | + err := schema.Validate(reader, &descriptor, true) |
123 | 118 | if got := err != nil; tt.fail != got { |
124 | 119 | t.Errorf("test %d: expected validation failure %t but got %t, err %v", i, tt.fail, got, err) |
125 | 120 | } |
@@ -173,16 +168,14 @@ func TestBackwardsCompatibilityManifest(t *testing.T) { |
173 | 168 | fail: false, |
174 | 169 | }, |
175 | 170 | } { |
176 | | - sum := sha256.Sum256([]byte(tt.manifest)) |
177 | | - got := fmt.Sprintf("sha256:%s", hex.EncodeToString(sum[:])) |
178 | | - if tt.digest != got { |
179 | | - t.Errorf("test %d: expected digest %s but got %s", i, tt.digest, got) |
180 | | - } |
181 | | - |
182 | 171 | manifest := convertFormats(tt.manifest) |
183 | | - r := strings.NewReader(manifest) |
184 | | - err := schema.MediaTypeManifest.Validate(r) |
185 | | - |
| 172 | + reader := strings.NewReader(manifest) |
| 173 | + descriptor := v1.Descriptor{ |
| 174 | + MediaType: v1.MediaTypeImageManifest, |
| 175 | + Digest: tt.digest, |
| 176 | + Size: int64(len(manifest)), |
| 177 | + } |
| 178 | + err := schema.Validate(reader, &descriptor, true) |
186 | 179 | if got := err != nil; tt.fail != got { |
187 | 180 | t.Errorf("test %d: expected validation failure %t but got %t, err %v", i, tt.fail, got, err) |
188 | 181 | } |
@@ -213,16 +206,14 @@ func TestBackwardsCompatibilityConfig(t *testing.T) { |
213 | 206 | fail: false, |
214 | 207 | }, |
215 | 208 | } { |
216 | | - sum := sha256.Sum256([]byte(tt.manifest)) |
217 | | - got := fmt.Sprintf("sha256:%s", hex.EncodeToString(sum[:])) |
218 | | - if tt.digest != got { |
219 | | - t.Errorf("test %d: expected digest %s but got %s", i, tt.digest, got) |
220 | | - } |
221 | | - |
222 | 209 | manifest := convertFormats(tt.manifest) |
223 | | - r := strings.NewReader(manifest) |
224 | | - err := schema.MediaTypeImageConfig.Validate(r) |
225 | | - |
| 210 | + reader := strings.NewReader(manifest) |
| 211 | + descriptor := v1.Descriptor{ |
| 212 | + MediaType: v1.MediaTypeImageConfig, |
| 213 | + Digest: tt.digest, |
| 214 | + Size: int64(len(manifest)), |
| 215 | + } |
| 216 | + err := schema.Validate(reader, &descriptor, true) |
226 | 217 | if got := err != nil; tt.fail != got { |
227 | 218 | t.Errorf("test %d: expected validation failure %t but got %t, err %v", i, tt.fail, got, err) |
228 | 219 | } |
|
0 commit comments