mirror of
https://github.com/containers/podman.git
synced 2025-11-30 01:58:46 +08:00
test/system: rework artifact created test
- use nanoseconds, so we don't need to sleep a full second do put the time forward. - use the --format option instead of jq - run test via remote as well - don't use static file content Fixes: #27265 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@@ -7,56 +7,40 @@ load helpers
|
|||||||
|
|
||||||
# Create temporary artifact file for testing
|
# Create temporary artifact file for testing
|
||||||
function create_test_file() {
|
function create_test_file() {
|
||||||
local content="$1"
|
local content="$(random_string 100)"
|
||||||
local filename=$(random_string 12)
|
local filename=$(random_string 12)
|
||||||
local filepath="$PODMAN_TMPDIR/$filename.txt"
|
local filepath="$PODMAN_TMPDIR/$filename.txt"
|
||||||
echo "$content" > "$filepath"
|
echo "$content" > "$filepath"
|
||||||
echo "$filepath"
|
echo "$filepath"
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup() {
|
|
||||||
basic_setup
|
|
||||||
skip_if_remote "artifacts are not remote"
|
|
||||||
}
|
|
||||||
|
|
||||||
function teardown() {
|
function teardown() {
|
||||||
run_podman artifact rm --all --ignore || true
|
run_podman artifact rm --all --ignore
|
||||||
basic_teardown
|
basic_teardown
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "podman artifact inspect shows created date in RFC3339 format" {
|
@test "podman artifact inspect shows created date in RFC3339 format" {
|
||||||
local content="test content for created date"
|
local testfile1=$(create_test_file)
|
||||||
local testfile1=$(create_test_file "$content")
|
|
||||||
local artifact_name="localhost/test/created-test"
|
local artifact_name="localhost/test/created-test"
|
||||||
local content2="appended content"
|
local testfile2=$(create_test_file)
|
||||||
local testfile2=$(create_test_file "$content2")
|
|
||||||
|
|
||||||
# Record time before creation (in seconds for comparison)
|
# Record time before creation (in nanoseconds for comparison)
|
||||||
local before_epoch=$(date +%s)
|
local before_epoch=$(date +%s%N)
|
||||||
|
|
||||||
# Create artifact
|
# Create artifact
|
||||||
run_podman artifact add $artifact_name "$testfile1"
|
run_podman artifact add $artifact_name "$testfile1"
|
||||||
|
|
||||||
# Record time after creation (in seconds for comparison)
|
# Record time after creation
|
||||||
local after_epoch=$(date +%s)
|
local after_epoch=$(date +%s%N)
|
||||||
after_epoch=$((after_epoch + 1))
|
|
||||||
|
|
||||||
# Inspect the artifact
|
# Inspect the artifact
|
||||||
run_podman artifact inspect $artifact_name
|
run_podman artifact inspect --format '{{index .Manifest.Annotations "org.opencontainers.image.created" }}' $artifact_name
|
||||||
local output="$output"
|
local created_annotation="$output"
|
||||||
|
|
||||||
# Parse the JSON output to get the created annotation
|
|
||||||
local created_annotation
|
|
||||||
created_annotation=$(echo "$output" | jq -r '.Manifest.annotations["org.opencontainers.image.created"]')
|
|
||||||
|
|
||||||
# Verify created annotation exists and is not null
|
|
||||||
assert "$created_annotation" != "null" "Should have org.opencontainers.image.created annotation"
|
|
||||||
assert "$created_annotation" != "" "Created annotation should not be empty"
|
assert "$created_annotation" != "" "Created annotation should not be empty"
|
||||||
|
|
||||||
# Verify it's a valid RFC3339 timestamp by trying to parse it
|
# Verify it's a valid RFC3339 timestamp by trying to parse it
|
||||||
# Convert to epoch for comparison
|
# Convert to epoch for comparison
|
||||||
local created_epoch
|
local created_epoch=$(date -d "$created_annotation" +%s%N 2>/dev/null)
|
||||||
created_epoch=$(date -d "$created_annotation" +%s 2>/dev/null)
|
|
||||||
|
|
||||||
# Verify parsing succeeded
|
# Verify parsing succeeded
|
||||||
assert "$?" -eq 0 "Created timestamp should be valid RFC3339 format"
|
assert "$?" -eq 0 "Created timestamp should be valid RFC3339 format"
|
||||||
@@ -65,27 +49,19 @@ function teardown() {
|
|||||||
assert "$created_epoch" -ge "$before_epoch" "Created time should be after before_epoch"
|
assert "$created_epoch" -ge "$before_epoch" "Created time should be after before_epoch"
|
||||||
assert "$created_epoch" -le "$after_epoch" "Created time should be before after_epoch"
|
assert "$created_epoch" -le "$after_epoch" "Created time should be before after_epoch"
|
||||||
|
|
||||||
# Wait a bit to ensure timestamps would differ if created new
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
# Append to artifact
|
# Append to artifact
|
||||||
run_podman artifact add --append $artifact_name "$testfile2"
|
run_podman artifact add --append $artifact_name "$testfile2"
|
||||||
|
|
||||||
# Get the created timestamp after append
|
# Get the created timestamp after append
|
||||||
run_podman artifact inspect $artifact_name
|
run_podman artifact inspect --format '{{index .Manifest.Annotations "org.opencontainers.image.created" }}\n{{len .Manifest.Layers}}' $artifact_name
|
||||||
local current_created
|
local current_created="${lines[0]}"
|
||||||
current_created=$(echo "$output" | jq -r '.Manifest.annotations["org.opencontainers.image.created"]')
|
local layer_count="${lines[1]}"
|
||||||
|
|
||||||
# Verify the created timestamp is preserved
|
# Verify the created timestamp is preserved
|
||||||
assert "$current_created" = "$created_annotation" "Created timestamp should be preserved during append"
|
assert "$current_created" = "$created_annotation" "Created timestamp should be preserved during append"
|
||||||
|
|
||||||
# Verify we have 2 layers now
|
# Verify we have 2 layers now
|
||||||
local layer_count
|
|
||||||
layer_count=$(echo "$output" | jq '.Manifest.layers | length')
|
|
||||||
assert "$layer_count" -eq 2 "Should have 2 layers after append"
|
assert "$layer_count" -eq 2 "Should have 2 layers after append"
|
||||||
|
|
||||||
# Clean up
|
|
||||||
rm -f "$testfile1" "$testfile2"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# vim: filetype=sh
|
# vim: filetype=sh
|
||||||
|
|||||||
Reference in New Issue
Block a user