Skip to content

Commit 60a1b1b

Browse files
committed
test: add 'golden output' tests for umoci-stat
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
1 parent b945b66 commit 60a1b1b

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed

test/stat.bats

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ Descriptor:
139139
== CONFIG ==
140140
Created: 2025-09-05T13:05:10.12345+10:00
141141
Author: ""
142+
Platform:
143+
OS: $(go env GOOS)
144+
Architecture: $(go env GOARCH)
142145
Image Config:
143146
User: ""
144147
Command:
@@ -178,6 +181,151 @@ EOF
178181
[ "$status" -eq 0 ]
179182
}
180183

184+
IMAGE_STAT="$(cat <<EOF
185+
== MANIFEST ==
186+
Schema Version: 2
187+
Media Type: application/vnd.oci.image.manifest.v1+json
188+
Config:
189+
Descriptor:
190+
Media Type: application/vnd.oci.image.config.v1+json
191+
Digest: sha256:01a6fc95c8afce1ebfaca585848ff2c42fe89ea0f5913c8e8fd6a0f8b691cd39
192+
Size: 1.107kB
193+
Layers:
194+
Descriptor:
195+
Media Type: application/vnd.oci.image.layer.v1.tar+gzip
196+
Digest: sha256:088ca2b11e89a40e143aeb9d4564d0ffb69d26a380b3341af07fa28c2dbdaece
197+
Size: 238B
198+
Annotations:
199+
ci.umo.uncompressed_blob_size: 4608
200+
Descriptor:
201+
Media Type: application/vnd.oci.image.layer.v1.tar+zstd
202+
Digest: sha256:92226702a21491c696a910e56da759a2d6fe979211a7ad91c60ca715b89bc059
203+
Size: 119B
204+
Annotations:
205+
ci.umo.uncompressed_blob_size: 2048
206+
Annotations:
207+
ci.umo.abc: "foobar\tbaz"
208+
ci.umo.xyz: hello world
209+
Descriptor:
210+
Media Type: application/vnd.oci.image.manifest.v1+json
211+
Digest: sha256:58fa9705ecfc0ec7d1e8631a729c6cbab46206233d58e46fc55346ca9d25ed43
212+
Size: 737B
213+
Annotations:
214+
org.opencontainers.image.ref.name: latest
215+
216+
== CONFIG ==
217+
Created: 2025-09-05T13:05:10.12345+10:00
218+
Author: Aleksa Sarai <cyphar@cyphar.com>
219+
Platform:
220+
OS: gnu+linux
221+
Architecture: riscv64
222+
Image Config:
223+
User: foo:bar
224+
Entrypoint:
225+
/bin/sh
226+
-c
227+
Command:
228+
true
229+
Working Directory: /tmp
230+
Environment:
231+
HOME=/
232+
SHELL=/bin/false
233+
AAA=1234
234+
"ESCAPED=a\tb\nc\vd\re"
235+
Stop Signal: SIGKILL
236+
Exposed Ports: 80/tcp, 8080/udp
237+
Volumes: /tmp, /var, "/with, comma"
238+
Descriptor:
239+
Media Type: application/vnd.oci.image.config.v1+json
240+
Digest: sha256:01a6fc95c8afce1ebfaca585848ff2c42fe89ea0f5913c8e8fd6a0f8b691cd39
241+
Size: 1.107kB
242+
243+
== HISTORY ==
244+
LAYER CREATED CREATED BY SIZE COMMENT
245+
sha256:088ca2b11e89a40e143aeb9d4564d0ffb69d26a380b3341af07fa28c2dbdaece 1997-03-25T13:40:00Z umoci insert 238B basic insert
246+
sha256:92226702a21491c696a910e56da759a2d6fe979211a7ad91c60ca715b89bc059 1997-03-25T13:42:00Z umoci insert --opaque 119B whiteout /
247+
<none> 2025-09-05T13:05:10.12345+10:00 umoci config <none> dummy configuration
248+
EOF
249+
)"
250+
251+
@test "umoci stat [output snapshot]" {
252+
IMAGE="$(setup_tmpdir)/image" TAG="latest"
253+
STATFILE_DIR="$(setup_tmpdir)"
254+
255+
expected="${STATFILE_DIR}/expected"
256+
cat >"$expected" <<<"$IMAGE_STAT"
257+
258+
umoci init --layout "${IMAGE}"
259+
[ "$status" -eq 0 ]
260+
261+
umoci new --image "${IMAGE}:${TAG}"
262+
[ "$status" -eq 0 ]
263+
264+
umoci config --no-history --image "${IMAGE}:${TAG}" \
265+
--author="Aleksa Sarai <cyphar@cyphar.com>" \
266+
--created="2025-09-05T13:05:10.12345+10:00" \
267+
--os="gnu+linux" \
268+
--architecture="riscv64"
269+
[ "$status" -eq 0 ]
270+
271+
layer="$(setup_tmpdir)"
272+
echo "dummy data" >"$layer/file"
273+
ln -s "foo" "$layer/link"
274+
mkdir -p "$layer/foo/bar/baz"
275+
find "$layer" -print0 | xargs -0 touch -h -d "1997-03-25T13:40:00"
276+
277+
umoci insert --image "${IMAGE}:${TAG}" \
278+
--history.author='Aleksa Sarai <cyphar@cyphar.com>' \
279+
--history.comment="basic insert" \
280+
--history.created="1997-03-25T13:40:00Z" \
281+
"$layer" /
282+
[ "$status" -eq 0 ]
283+
284+
layer="$(setup_tmpdir)"
285+
find "$layer" -print0 | xargs -0 touch -h -d "1997-03-25T13:42:00"
286+
287+
umoci insert --image "${IMAGE}:${TAG}" \
288+
--compress=zstd \
289+
--history.author=$'Foo Bar <foo\tbar\nbaz@fake.email>' \
290+
--history.comment="whiteout /" \
291+
--history.created_by="umoci insert --opaque" \
292+
--history.created="1997-03-25T13:42:00Z" \
293+
--opaque "$layer" /foo
294+
[ "$status" -eq 0 ]
295+
296+
umoci config --image "${IMAGE}:${TAG}" \
297+
--config.user="foo:bar" \
298+
--config.exposedports=80/tcp \
299+
--config.exposedports=8080/udp \
300+
--config.env="HOME=/" \
301+
--config.env="SHELL=/bin/false" \
302+
--config.env="AAA=1234" \
303+
--config.env=$'ESCAPED=a\tb\nc\vd\re' \
304+
--config.entrypoint="/bin/sh" \
305+
--config.entrypoint="-c" \
306+
--config.cmd="true" \
307+
--config.volume="/tmp" \
308+
--config.volume="/var" \
309+
--config.volume="/with, comma" \
310+
--config.workingdir="/tmp" \
311+
--config.stopsignal="SIGKILL" \
312+
--manifest.annotation=$'ci.umo.abc=foobar\tbaz' \
313+
--manifest.annotation="ci.umo.xyz=hello world" \
314+
--history.created="2025-09-05T13:05:10.12345+10:00" \
315+
--history.author="Hello World <another dummy email@foo.com>" \
316+
--history.comment="dummy configuration"
317+
[ "$status" -eq 0 ]
318+
319+
umoci stat --image "${IMAGE}:${TAG}"
320+
[ "$status" -eq 0 ]
321+
322+
got="${STATFILE_DIR}/got"
323+
cat >"$got" <<<"$output"
324+
325+
sane_run diff -u "$expected" "$got"
326+
[ "$status" -eq 0 ]
327+
}
328+
181329
@test "umoci stat [invalid arguments]" {
182330
# Missing --image argument.
183331
umoci stat

0 commit comments

Comments
 (0)