Skip to content

Commit 09cf145

Browse files
committed
test/system: merge artifact tests into single file
There is no need for several files here, it just means the setup and helpers get duplicated. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
1 parent 348617f commit 09cf145

File tree

2 files changed

+62
-82
lines changed

2 files changed

+62
-82
lines changed

test/system/702-artifact-created.bats

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,78 @@
11
#!/usr/bin/env bats -*- bats -*-
22
#
3-
# Tests for podman artifact functionality
3+
# Tests for podman artifact created date functionality
44
#
55

66
load helpers
77

88
# FIXME #27264: Artifact store does not seem to work properly with concurrent access. Do not the ci:parallel tags here!
99

10-
function setup() {
11-
basic_setup
10+
# Create temporary artifact file for testing
11+
function create_test_file() {
12+
local content="$(random_string 100)"
13+
local filename=$(random_string 12)
14+
local filepath="$PODMAN_TMPDIR/$filename.txt"
15+
echo "$content" > "$filepath"
16+
echo "$filepath"
1217
}
1318

1419
function teardown() {
20+
run_podman artifact rm --all --ignore
1521
basic_teardown
1622
}
1723

18-
# Helper function to create a test artifact file
19-
create_test_file() {
20-
local size=${1:-1024}
21-
local filename=$(mktemp --tmpdir="${PODMAN_TMPDIR}" artifactfile.XXXXXX)
22-
dd if=/dev/urandom of="$filename" bs=1 count="$size" 2>/dev/null
23-
echo "$filename"
24+
@test "podman artifact inspect shows created date in RFC3339 format" {
25+
local testfile1=$(create_test_file)
26+
local artifact_name="localhost/test/created-test"
27+
local testfile2=$(create_test_file)
28+
29+
# Record time before creation (in nanoseconds for comparison)
30+
local before_epoch=$(date +%s%N)
31+
32+
# Create artifact
33+
run_podman artifact add $artifact_name "$testfile1"
34+
35+
# Record time after creation
36+
local after_epoch=$(date +%s%N)
37+
38+
# Inspect the artifact
39+
run_podman artifact inspect --format '{{index .Manifest.Annotations "org.opencontainers.image.created" }}' $artifact_name
40+
local created_annotation="$output"
41+
assert "$created_annotation" != "" "Created annotation should not be empty"
42+
43+
# Verify it's a valid RFC3339 timestamp by trying to parse it
44+
# Convert to epoch for comparison
45+
local created_epoch=$(date -d "$created_annotation" +%s%N 2>/dev/null)
46+
47+
# Verify parsing succeeded
48+
assert "$?" -eq 0 "Created timestamp should be valid RFC3339 format"
49+
50+
# Verify timestamp is within reasonable bounds
51+
assert "$created_epoch" -ge "$before_epoch" "Created time should be after before_epoch"
52+
assert "$created_epoch" -le "$after_epoch" "Created time should be before after_epoch"
53+
54+
# Append to artifact
55+
run_podman artifact add --append $artifact_name "$testfile2"
56+
57+
# Get the created timestamp after append
58+
run_podman artifact inspect --format '{{index .Manifest.Annotations "org.opencontainers.image.created" }}\n{{len .Manifest.Layers}}' $artifact_name
59+
local current_created="${lines[0]}"
60+
local layer_count="${lines[1]}"
61+
62+
# Verify the created timestamp is preserved
63+
assert "$current_created" = "$created_annotation" "Created timestamp should be preserved during append"
64+
65+
# Verify we have 2 layers now
66+
assert "$layer_count" -eq 2 "Should have 2 layers after append"
2467
}
2568

69+
2670
@test "podman artifact add --replace basic functionality" {
2771
local artifact_name="localhost/test/replace-artifact"
2872
local file1 file2
2973

30-
file1=$(create_test_file 1024)
31-
file2=$(create_test_file 2048)
74+
file1=$(create_test_file)
75+
file2=$(create_test_file)
3276

3377
# Add initial artifact
3478
run_podman artifact add "$artifact_name" "$file1"
@@ -56,7 +100,7 @@ create_test_file() {
56100
local artifact_name="localhost/test/nonexistent-artifact"
57101
local file1
58102

59-
file1=$(create_test_file 1024)
103+
file1=$(create_test_file)
60104

61105
# Using --replace on nonexistent artifact should succeed
62106
run_podman artifact add --replace "$artifact_name" "$file1"
@@ -73,7 +117,7 @@ create_test_file() {
73117
local artifact_name="localhost/test/conflict-artifact"
74118
local file1
75119

76-
file1=$(create_test_file 1024)
120+
file1=$(create_test_file)
77121

78122
# Using --replace and --append together should fail
79123
run_podman 125 artifact add --replace --append "$artifact_name" "$file1"
@@ -86,8 +130,8 @@ create_test_file() {
86130
local artifact_name="localhost/test/existing-artifact"
87131
local file1 file2
88132

89-
file1=$(create_test_file 512)
90-
file2=$(create_test_file 1024)
133+
file1=$(create_test_file)
134+
file2=$(create_test_file)
91135

92136
# Create initial artifact
93137
run_podman artifact add "$artifact_name" "$file1"
@@ -109,3 +153,6 @@ create_test_file() {
109153
run_podman artifact rm "$artifact_name"
110154
rm -f "$file1" "$file2"
111155
}
156+
157+
158+
# vim: filetype=sh

0 commit comments

Comments
 (0)