Skip to content

Commit 4e45b5e

Browse files
committed
Add "oci-import" test that validates full "oci-import" output
1 parent d70af73 commit 4e45b5e

14 files changed

+144
-2
lines changed

.test/meta-commands/out.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ jq -s '
115115
error("unsupported imageLayoutVersion: " + .imageLayoutVersion)
116116
else . end
117117
' temp/oci-layout > /dev/null
118-
jq -s '
118+
jq -s --tab '
119119
if length != 1 then
120120
error("unexpected '\''index.json'\'' document count: " + length)
121121
else .[0] end

.test/oci-import/in.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../builds.json

.test/oci-import/out.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
export BASHBREW_CACHE="${BASHBREW_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/bashbrew}"
2+
gitCache="$BASHBREW_CACHE/git"
3+
git init --bare "$gitCache"
4+
_git() { git -C "$gitCache" "$@"; }
5+
_git config gc.auto 0
6+
_commit() { _git rev-parse 'd0b7d566eb4f1fa9933984e6fc04ab11f08f4592^{commit}'; }
7+
if ! _commit &> /dev/null; then _git fetch 'https://github.com/docker-library/busybox.git' 'd0b7d566eb4f1fa9933984e6fc04ab11f08f4592:' || _git fetch 'refs/heads/dist-amd64:'; fi
8+
_commit
9+
mkdir temp
10+
_git archive --format=tar 'd0b7d566eb4f1fa9933984e6fc04ab11f08f4592:latest/glibc/amd64/' | tar -xvC temp
11+
jq -s '
12+
if length != 1 then
13+
error("unexpected '\''oci-layout'\'' document count: " + length)
14+
else .[0] end
15+
| if .imageLayoutVersion != "1.0.0" then
16+
error("unsupported imageLayoutVersion: " + .imageLayoutVersion)
17+
else . end
18+
' temp/oci-layout > /dev/null
19+
jq -s --tab '
20+
if length != 1 then
21+
error("unexpected '\''index.json'\'' document count: " + length)
22+
else .[0] end
23+
| if .schemaVersion != 2 then
24+
error("unsupported schemaVersion: " + .schemaVersion)
25+
else . end
26+
| if .manifests | length != 1 then
27+
error("expected only one manifests entry, not " + (.manifests | length))
28+
else . end
29+
| .manifests[0] |= (
30+
if .mediaType != "application/vnd.oci.image.manifest.v1+json" then
31+
error("unsupported descriptor mediaType: " + .mediaType)
32+
else . end
33+
| if .size < 0 then
34+
error("invalid descriptor size: " + .size)
35+
else . end
36+
| del(.annotations, .urls)
37+
| .annotations = {"org.opencontainers.image.source":"https://github.com/docker-library/busybox.git","org.opencontainers.image.revision":"d0b7d566eb4f1fa9933984e6fc04ab11f08f4592","org.opencontainers.image.created":"2024-02-28T00:44:18Z","org.opencontainers.image.version":"1.36.1","org.opencontainers.image.url":"https://hub.docker.com/_/busybox","com.docker.official-images.bashbrew.arch":"amd64","org.opencontainers.image.base.name":"scratch"}
38+
)
39+
' temp/index.json > temp/index.json.new
40+
mv temp/index.json.new temp/index.json
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../image-manifest.json
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../rootfs.tar.gz
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../image-config.json
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"config": {
3+
"Cmd": [
4+
"sh"
5+
]
6+
},
7+
"created": "2023-05-18T22:34:17Z",
8+
"history": [
9+
{
10+
"created": "2023-05-18T22:34:17Z",
11+
"created_by": "BusyBox 1.36.1 (glibc), Debian 12"
12+
}
13+
],
14+
"rootfs": {
15+
"type": "layers",
16+
"diff_ids": [
17+
"sha256:95c4a60383f7b6eb6f7b8e153a07cd6e896de0476763bef39d0f6cf3400624bd"
18+
]
19+
},
20+
"architecture": "amd64",
21+
"os": "linux"
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"schemaVersion": 2,
3+
"mediaType": "application/vnd.oci.image.manifest.v1+json",
4+
"config": {
5+
"mediaType": "application/vnd.oci.image.config.v1+json",
6+
"digest": "sha256:ba5dc23f65d4cc4a4535bce55cf9e63b068eb02946e3422d3587e8ce803b6aab",
7+
"size": 372
8+
},
9+
"layers": [
10+
{
11+
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
12+
"digest": "sha256:7b2699543f22d5b8dc8d66a5873eb246767bca37232dee1e7a3b8c9956bceb0c",
13+
"size": 2152262
14+
}
15+
],
16+
"annotations": {
17+
"org.opencontainers.image.url": "https://github.com/docker-library/busybox",
18+
"org.opencontainers.image.version": "1.36.1-glibc"
19+
}
20+
}

.test/oci-import/temp/index.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"schemaVersion": 2,
3+
"mediaType": "application/vnd.oci.image.index.v1+json",
4+
"manifests": [
5+
{
6+
"mediaType": "application/vnd.oci.image.manifest.v1+json",
7+
"digest": "sha256:4be429a5fbb2e71ae7958bfa558bc637cf3a61baf40a708cb8fff532b39e52d0",
8+
"size": 610,
9+
"platform": {
10+
"architecture": "amd64",
11+
"os": "linux"
12+
},
13+
"annotations": {
14+
"org.opencontainers.image.source": "https://github.com/docker-library/busybox.git",
15+
"org.opencontainers.image.revision": "d0b7d566eb4f1fa9933984e6fc04ab11f08f4592",
16+
"org.opencontainers.image.created": "2024-02-28T00:44:18Z",
17+
"org.opencontainers.image.version": "1.36.1",
18+
"org.opencontainers.image.url": "https://hub.docker.com/_/busybox",
19+
"com.docker.official-images.bashbrew.arch": "amd64",
20+
"org.opencontainers.image.base.name": "scratch"
21+
}
22+
}
23+
]
24+
}

.test/oci-import/temp/oci-layout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"imageLayoutVersion":"1.0.0"}

.test/oci-import/test.jq

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
include "meta";
2+
3+
first(.[] | select(normalized_builder == "oci-import"))
4+
5+
| build_command
6+
7+
# TODO find a better way to stop the SBOM bits from being included here
8+
| sub("(?s)\n+# SBOM.*"; "")

.test/oci-import/test.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
dir="$(dirname "$BASH_SOURCE")"
5+
6+
set -x
7+
8+
cd "$dir"
9+
10+
export BASHBREW_META_SCRIPTS=../..
11+
12+
rm -rf temp
13+
source out.sh
14+
15+
# make sure we don't commit the rootfs tarballs
16+
find temp -type f -size '+1k' -print -delete

.test/test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,10 @@ fi
279279

280280
# also run our "jq" tests (like generating example commands from the "builds.json" we just generated)
281281
"$dir/jq.sh"
282+
283+
# TODO a new helper to run these by themselves?
284+
for t in "$dir/"*"/test.sh"; do
285+
if [ -x "$t" ]; then
286+
"$t"
287+
fi
288+
done

meta.jq

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def build_command:
284284
@sh "jq -s \("{ schemaVersion: 2, manifests: . }") \("./" + .source.entries[0].File) > temp/index.json"
285285
else empty end,
286286

287-
@sh "jq -s \("
287+
@sh "jq -s --tab \("
288288
if length != 1 then
289289
error(\"unexpected 'index.json' document count: \" + length)
290290
else .[0] end

0 commit comments

Comments
 (0)