-
Notifications
You must be signed in to change notification settings - Fork 677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
serialization: add test, make volumes null #151
Closed
philips
wants to merge
2
commits into
opencontainers:master
from
philips:serialization-make-volume-null
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// Copyright 2016 The Linux Foundation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package schema_test | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/opencontainers/image-spec/schema" | ||
) | ||
|
||
var compatMap = map[string]string{ | ||
"application/vnd.docker.distribution.manifest.list.v2+json": "application/vnd.oci.image.manifest.list.v1+json", | ||
"application/vnd.docker.distribution.manifest.v2+json": "application/vnd.oci.image.manifest.v1+json", | ||
"application/vnd.docker.image.rootfs.diff.tar.gzip": "application/vnd.oci.image.rootfs.tar.gzip", | ||
"application/vnd.docker.container.image.v1+json": "application/vnd.oci.image.serialization.config.v1+json", | ||
} | ||
|
||
// convertFormats converts Docker v2.2 image format JSON documents to OCI | ||
// format by simply replacing instances of the strings found in the compatMap | ||
// found in the input string. | ||
func convertFormats(input string) string { | ||
out := input | ||
for k, v := range compatMap { | ||
out = strings.Replace(out, v, k, -1) | ||
} | ||
return out | ||
} | ||
|
||
func TestBackwardsCompatibilityManifest(t *testing.T) { | ||
for i, tt := range []struct { | ||
manifest string | ||
digest string | ||
fail bool | ||
}{ | ||
// manifest pulled from docker hub using hash value | ||
// | ||
// curl -L -H "Authorization: Bearer ..." -H \ | ||
// "Accept: application/vnd.docker.distribution.manifest.v2+json" \ | ||
// https://registry-1.docker.io/v2/library/docker/manifests/sha256:888206c77cd2811ec47e752ba291e5b7734e3ef137dfd222daadaca39a9f17bc | ||
{ | ||
digest: "sha256:888206c77cd2811ec47e752ba291e5b7734e3ef137dfd222daadaca39a9f17bc", | ||
manifest: `{ | ||
"schemaVersion": 2, | ||
"mediaType": "application/vnd.docker.distribution.manifest.v2+json", | ||
"config": { | ||
"mediaType": "application/octet-stream", | ||
"size": 3210, | ||
"digest": "sha256:5359a4f250650c20227055957e353e8f8a74152f35fe36f00b6b1f9fc19c8861" | ||
}, | ||
"layers": [ | ||
{ | ||
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", | ||
"size": 2310272, | ||
"digest": "sha256:fae91920dcd4542f97c9350b3157139a5d901362c2abec284de5ebd1b45b4957" | ||
}, | ||
{ | ||
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", | ||
"size": 913022, | ||
"digest": "sha256:f384f6ab36adad485192f09379c0b58dc612a3cde82c551e082a7c29a87c95da" | ||
}, | ||
{ | ||
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", | ||
"size": 9861668, | ||
"digest": "sha256:ed0d2dd5e1a0e5e650a330a864c8a122e9aa91fa6ba9ac6f0bd1882e59df55e7" | ||
}, | ||
{ | ||
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", | ||
"size": 465, | ||
"digest": "sha256:ec4d00b58417c45f7ddcfde7bcad8c9d62a7d6d5d17cdc1f7d79bcb2e22c1491" | ||
} | ||
] | ||
}`, | ||
fail: false, | ||
}, | ||
} { | ||
sum := sha256.Sum256([]byte(tt.manifest)) | ||
got := fmt.Sprintf("sha256:%s", hex.EncodeToString(sum[:])) | ||
if tt.digest != got { | ||
t.Errorf("test %d: expected digest %s but got %s", i, tt.digest, got) | ||
} | ||
|
||
manifest := convertFormats(tt.manifest) | ||
r := strings.NewReader(manifest) | ||
err := schema.MediaTypeManifest.Validate(r) | ||
|
||
if got := err != nil; tt.fail != got { | ||
t.Errorf("test %d: expected validation failure %t but got %t, err %v", i, tt.fail, got, err) | ||
} | ||
} | ||
} | ||
|
||
func TestBackwardsCompatibilityConfig(t *testing.T) { | ||
for i, tt := range []struct { | ||
manifest string | ||
digest string | ||
fail bool | ||
}{ | ||
// manifest pulled from docker hub blob store | ||
// | ||
// curl -L -H "Authorization: Bearer ..." -H \ | ||
// -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \ | ||
// https://registry-1.docker.io/v2/library/docker/blobs/sha256:5359a4f250650c20227055957e353e8f8a74152f35fe36f00b6b1f9fc19c8861 | ||
{ | ||
digest: "sha256:5359a4f250650c20227055957e353e8f8a74152f35fe36f00b6b1f9fc19c8861", | ||
manifest: `{"architecture":"amd64","config":{"Hostname":"e5e5b3910a57","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","DOCKER_BUCKET=get.docker.com","DOCKER_VERSION=1.10.3","DOCKER_SHA256=d0df512afa109006a450f41873634951e19ddabf8c7bd419caeb5a526032d86d"],"Cmd":["sh"],"ArgsEscaped":true,"Image":"sha256:bda352ba7ab5823b7dc74b380c5ad1699edee278a6d2ebbe451129b108778742","Volumes":null,"WorkingDir":"","Entrypoint":["docker-entrypoint.sh"],"OnBuild":[],"Labels":{}},"container":"881be788b4387039b52fa195da9fe26f264385aa497ce650cfdcf3806c2d2021","container_config":{"Hostname":"e5e5b3910a57","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","DOCKER_BUCKET=get.docker.com","DOCKER_VERSION=1.10.3","DOCKER_SHA256=d0df512afa109006a450f41873634951e19ddabf8c7bd419caeb5a526032d86d"],"Cmd":["/bin/sh","-c","#(nop) CMD [\"sh\"]"],"ArgsEscaped":true,"Image":"sha256:bda352ba7ab5823b7dc74b380c5ad1699edee278a6d2ebbe451129b108778742","Volumes":null,"WorkingDir":"","Entrypoint":["docker-entrypoint.sh"],"OnBuild":[],"Labels":{}},"created":"2016-06-08T00:52:29.30472774Z","docker_version":"1.10.3","history":[{"created":"2016-06-08T00:48:01.932532048Z","created_by":"/bin/sh -c #(nop) ADD file:bca92e550bd2ce926584aef2032464b6ebf543ce69133b6602c781866165d703 in /"},{"created":"2016-06-08T00:52:10.503417531Z","created_by":"/bin/sh -c apk add --no-cache \t\tca-certificates \t\tcurl \t\topenssl"},{"created":"2016-06-08T00:52:10.700704697Z","created_by":"/bin/sh -c #(nop) ENV DOCKER_BUCKET=get.docker.com","empty_layer":true},{"created":"2016-06-08T00:52:25.746175479Z","created_by":"/bin/sh -c #(nop) ENV DOCKER_VERSION=1.10.3","empty_layer":true},{"created":"2016-06-08T00:52:25.954613633Z","created_by":"/bin/sh -c #(nop) ENV DOCKER_SHA256=d0df512afa109006a450f41873634951e19ddabf8c7bd419caeb5a526032d86d","empty_layer":true},{"created":"2016-06-08T00:52:28.173693898Z","created_by":"/bin/sh -c curl -fSL \"https://${DOCKER_BUCKET}/builds/Linux/x86_64/docker-$DOCKER_VERSION\" -o /usr/local/bin/docker \t\u0026\u0026 echo \"${DOCKER_SHA256} /usr/local/bin/docker\" | sha256sum -c - \t\u0026\u0026 chmod +x /usr/local/bin/docker"},{"created":"2016-06-08T00:52:28.924486515Z","created_by":"/bin/sh -c #(nop) COPY file:50006c902e7677711aeffe4ab7b7042d649618b96dec760f322a8566dd83ab25 in /usr/local/bin/"},{"created":"2016-06-08T00:52:29.121963047Z","created_by":"/bin/sh -c #(nop) ENTRYPOINT \u0026{[\"docker-entrypoint.sh\"]}","empty_layer":true},{"created":"2016-06-08T00:52:29.30472774Z","created_by":"/bin/sh -c #(nop) CMD [\"sh\"]","empty_layer":true}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:77f08abee8bf9334407f52d104e1891283018450b3c196118ddfe31505126b87","sha256:707d16737060172b977d5f7eaaddfcfaae1008472193d7e8e5a01111a5f8dd5c","sha256:44da042e7b2458ee0b3877f2321cdf4fd45a49b9b51e00492c2ba68055573eff","sha256:1bc2be83dce13b9bac9476c9c1d2ca6e0db3e07b443f7298fc5a1af75b2cb4ef"]}}`, | ||
fail: false, | ||
}, | ||
} { | ||
sum := sha256.Sum256([]byte(tt.manifest)) | ||
got := fmt.Sprintf("sha256:%s", hex.EncodeToString(sum[:])) | ||
if tt.digest != got { | ||
t.Errorf("test %d: expected digest %s but got %s", i, tt.digest, got) | ||
} | ||
|
||
manifest := convertFormats(tt.manifest) | ||
r := strings.NewReader(manifest) | ||
err := schema.MediaTypeImageSerializationConfig.Validate(r) | ||
|
||
if got := err != nil; tt.fail != got { | ||
t.Errorf("test %d: expected validation failure %t but got %t, err %v", i, tt.fail, got, err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look like
jq
;). Did you runmake fmt
(with the fix from #148)?