Skip to content

Commit ee34953

Browse files
authored
Merge pull request #705 from q384566678/add-layout-test
schema: add layout test
2 parents edc826a + 9c4e19e commit ee34953

File tree

2 files changed

+63
-7
lines changed

2 files changed

+63
-7
lines changed

schema/fs.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ var _escData = map[string]*_escFile{
205205
"/config-schema.json": {
206206
local: "config-schema.json",
207207
size: 2771,
208-
modtime: 1495785272,
208+
modtime: 1498025574,
209209
compressed: `
210210
H4sIAAAJbogA/+RWQW/bPAy9+1cYbo9t/R2+U67dbgMyINh2KIZAsemEnSVqFD3MGPLfB8vJZtmym3XI
211211
aScDFB/f4xMl60eSplkJrmC0gmSyVZqtLZhHMqLQAKePZCrcpxsLBVZYKJ9118FuXXEArTrIQcSu8vzZ
@@ -223,7 +223,7 @@ b1D07fCyW0vviMlWxN4UcYpZ/Enjdtf+RQ3SGiZ/vj8oANpKu/UTMV9kR1SDMjPzGZ6y5MQwnZvwWfX7
223223
"/content-descriptor.json": {
224224
local: "content-descriptor.json",
225225
size: 1085,
226-
modtime: 1495785272,
226+
modtime: 1498025574,
227227
compressed: `
228228
H4sIAAAJbogA/5yTwW7UMBCG73mKUVqpl27NoeIQVb3AnQPcEAevPY6nbGwznlW1oL47mniXJoAo3Vsy
229229
+r+Zz8n4RwfQe6yOqQjl1A/QfyiY3uUklhIy6BMmgffHUGb4WNBRIGdn4lpbXFYXcbKKR5EyGPNQc9q0
@@ -238,7 +238,7 @@ ERcrb5b9zhBc4s2zO7r2jN/2xKhin3+/McttXS9NB/Cle+p+BgAA///HjexwPQQAAA==
238238
"/defs-descriptor.json": {
239239
local: "defs-descriptor.json",
240240
size: 922,
241-
modtime: 1495785272,
241+
modtime: 1498025574,
242242
compressed: `
243243
H4sIAAAJbogA/6STX2/TMBTF3/spLl7FgDZN4QFp0Ria2DsP42lTV93ZN/Ed8R/ZrqYy9bsjJ1naFYFA
244244
PCSyj67Pub8b52kCIBRFGdgndlZUIK6oZst5F8FjSCw3LQZIDr56sl+cTciWAlwNx1yAa0+Sa5bYecx7
@@ -254,7 +254,7 @@ ELULBvNXEJvAYtB3LzDQWpfw5fX8n7t46Dc2PQ1UZz9FdVw8RGdPyoPfojTor7ve+/cw50l+dpOfAQAA
254254
"/defs.json": {
255255
local: "defs.json",
256256
size: 1670,
257-
modtime: 1495785272,
257+
modtime: 1498025574,
258258
compressed: `
259259
H4sIAAAJbogA/7STza6bMBCF9zzFyO2S9oJtbGDb7hMpy6oLSiaJq2AjY6RWEe9e8RNChFuJKneRgGc8
260260
3zmeMbcAgByxKa2qnTKa5EC+4klp1a8aaBs8grtY054vpnXgLgi7GvUXo12hNFo41FiqkyqLoTwceTOA
@@ -269,7 +269,7 @@ fIvD7in0ryMEy+fK1G6UfmdTE+tvpoL+1wV/AgAA//96IpqyhgYAAA==
269269
"/image-index-schema.json": {
270270
local: "image-index-schema.json",
271271
size: 2993,
272-
modtime: 1495785272,
272+
modtime: 1498025574,
273273
compressed: `
274274
H4sIAAAJbogA/6yWv27bMBDGdz/FQQmQJYmKIuhgBFnaJVOHBl2KDAx5ki61SPVIJ3ELv3tBMrIlUXZt
275275
1Zt95H33+07892cGkCm0kqlxZHQ2h+xrg/qz0U6QRob7WpQI91rhG3xrUFJBUoSplz733MoKa+HzKuea
@@ -289,7 +289,7 @@ mOlZmY29BDtPuBnA42w9+xsAAP//IKe/nbELAAA=
289289
"/image-layout-schema.json": {
290290
local: "image-layout-schema.json",
291291
size: 439,
292-
modtime: 1495785272,
292+
modtime: 1498025574,
293293
compressed: `
294294
H4sIAAAJbogA/2yPQUvEMBCF7/0VQ/Sg4DYVPOW6pwVhD4IX8VDTaTvLNonJVFik/12SaRXRU5g38+W9
295295
91kBqA6TjRSYvFMG1DGg23vHLTmMcJjaAeGxvfiZ4cmOOLXqLlPXSQYDamQORutT8m4nau3joLvY9rxr
@@ -302,7 +302,7 @@ HrRoV8JRtyHJaO0DOruZpYLJtaZsrM/FWEi+BMysfzuhXbUQfcDIhEkZyG2yQyYl8TPGJLVk97fth1yA
302302
"/image-manifest-schema.json": {
303303
local: "image-manifest-schema.json",
304304
size: 921,
305-
modtime: 1495785272,
305+
modtime: 1498025574,
306306
compressed: `
307307
H4sIAAAJbogA/5ySMW8iMRCF+/0VI0MJ+O501bZXUZxSJEoTpXB2x7uDWNsZmygo4r9HtnHAkCKifTvv
308308
zTdv/dEAiB59x+QCWSNaEHcOzT9rgiKDDOtJDQj/lSGNPsC9w440dSpNL6J97rsRJxWtYwiulXLjrVlm

schema/imagelayout_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2016 The Linux Foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package schema_test
16+
17+
import (
18+
"strings"
19+
"testing"
20+
21+
"github.com/opencontainers/image-spec/schema"
22+
)
23+
24+
func TestImageLayout(t *testing.T) {
25+
for i, tt := range []struct {
26+
imageLayout string
27+
fail bool
28+
}{
29+
// expected faulure: imageLayoutVersion does not match pattern
30+
{
31+
imageLayout: `
32+
{
33+
"imageLayoutVersion": 1.0.0
34+
}
35+
`,
36+
fail: true,
37+
},
38+
39+
// validate layout
40+
{
41+
imageLayout: `
42+
{
43+
"imageLayoutVersion": "1.0.0"
44+
}
45+
`,
46+
fail: false,
47+
},
48+
} {
49+
r := strings.NewReader(tt.imageLayout)
50+
err := schema.ValidatorMediaTypeLayoutHeader.Validate(r)
51+
52+
if got := err != nil; tt.fail != got {
53+
t.Errorf("test %d: expected validation failure %t but got %t, err %v", i, tt.fail, got, err)
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)