mirror of
https://github.com/containers/podman.git
synced 2025-11-29 01:28:22 +08:00
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>
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
#!/usr/bin/env bats -*- bats -*-
|
||||
#
|
||||
# Tests for podman artifact created date functionality
|
||||
#
|
||||
|
||||
load helpers
|
||||
|
||||
# Create temporary artifact file for testing
|
||||
function create_test_file() {
|
||||
local content="$(random_string 100)"
|
||||
local filename=$(random_string 12)
|
||||
local filepath="$PODMAN_TMPDIR/$filename.txt"
|
||||
echo "$content" > "$filepath"
|
||||
echo "$filepath"
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
run_podman artifact rm --all --ignore
|
||||
basic_teardown
|
||||
}
|
||||
|
||||
@test "podman artifact inspect shows created date in RFC3339 format" {
|
||||
local testfile1=$(create_test_file)
|
||||
local artifact_name="localhost/test/created-test"
|
||||
local testfile2=$(create_test_file)
|
||||
|
||||
# Record time before creation (in nanoseconds for comparison)
|
||||
local before_epoch=$(date +%s%N)
|
||||
|
||||
# Create artifact
|
||||
run_podman artifact add $artifact_name "$testfile1"
|
||||
|
||||
# Record time after creation
|
||||
local after_epoch=$(date +%s%N)
|
||||
|
||||
# Inspect the artifact
|
||||
run_podman artifact inspect --format '{{index .Manifest.Annotations "org.opencontainers.image.created" }}' $artifact_name
|
||||
local created_annotation="$output"
|
||||
assert "$created_annotation" != "" "Created annotation should not be empty"
|
||||
|
||||
# Verify it's a valid RFC3339 timestamp by trying to parse it
|
||||
# Convert to epoch for comparison
|
||||
local created_epoch=$(date -d "$created_annotation" +%s%N 2>/dev/null)
|
||||
|
||||
# Verify parsing succeeded
|
||||
assert "$?" -eq 0 "Created timestamp should be valid RFC3339 format"
|
||||
|
||||
# Verify timestamp is within reasonable bounds
|
||||
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"
|
||||
|
||||
# Append to artifact
|
||||
run_podman artifact add --append $artifact_name "$testfile2"
|
||||
|
||||
# Get the created timestamp after append
|
||||
run_podman artifact inspect --format '{{index .Manifest.Annotations "org.opencontainers.image.created" }}\n{{len .Manifest.Layers}}' $artifact_name
|
||||
local current_created="${lines[0]}"
|
||||
local layer_count="${lines[1]}"
|
||||
|
||||
# Verify the created timestamp is preserved
|
||||
assert "$current_created" = "$created_annotation" "Created timestamp should be preserved during append"
|
||||
|
||||
# Verify we have 2 layers now
|
||||
assert "$layer_count" -eq 2 "Should have 2 layers after append"
|
||||
}
|
||||
|
||||
# vim: filetype=sh
|
||||
@@ -1,34 +1,78 @@
|
||||
#!/usr/bin/env bats -*- bats -*-
|
||||
#
|
||||
# Tests for podman artifact functionality
|
||||
# Tests for podman artifact created date functionality
|
||||
#
|
||||
|
||||
load helpers
|
||||
|
||||
# FIXME #27264: Artifact store does not seem to work properly with concurrent access. Do not the ci:parallel tags here!
|
||||
|
||||
function setup() {
|
||||
basic_setup
|
||||
# Create temporary artifact file for testing
|
||||
function create_test_file() {
|
||||
local content="$(random_string 100)"
|
||||
local filename=$(random_string 12)
|
||||
local filepath="$PODMAN_TMPDIR/$filename.txt"
|
||||
echo "$content" > "$filepath"
|
||||
echo "$filepath"
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
run_podman artifact rm --all --ignore
|
||||
basic_teardown
|
||||
}
|
||||
|
||||
# Helper function to create a test artifact file
|
||||
create_test_file() {
|
||||
local size=${1:-1024}
|
||||
local filename=$(mktemp --tmpdir="${PODMAN_TMPDIR}" artifactfile.XXXXXX)
|
||||
dd if=/dev/urandom of="$filename" bs=1 count="$size" 2>/dev/null
|
||||
echo "$filename"
|
||||
@test "podman artifact inspect shows created date in RFC3339 format" {
|
||||
local testfile1=$(create_test_file)
|
||||
local artifact_name="localhost/test/created-test"
|
||||
local testfile2=$(create_test_file)
|
||||
|
||||
# Record time before creation (in nanoseconds for comparison)
|
||||
local before_epoch=$(date +%s%N)
|
||||
|
||||
# Create artifact
|
||||
run_podman artifact add $artifact_name "$testfile1"
|
||||
|
||||
# Record time after creation
|
||||
local after_epoch=$(date +%s%N)
|
||||
|
||||
# Inspect the artifact
|
||||
run_podman artifact inspect --format '{{index .Manifest.Annotations "org.opencontainers.image.created" }}' $artifact_name
|
||||
local created_annotation="$output"
|
||||
assert "$created_annotation" != "" "Created annotation should not be empty"
|
||||
|
||||
# Verify it's a valid RFC3339 timestamp by trying to parse it
|
||||
# Convert to epoch for comparison
|
||||
local created_epoch=$(date -d "$created_annotation" +%s%N 2>/dev/null)
|
||||
|
||||
# Verify parsing succeeded
|
||||
assert "$?" -eq 0 "Created timestamp should be valid RFC3339 format"
|
||||
|
||||
# Verify timestamp is within reasonable bounds
|
||||
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"
|
||||
|
||||
# Append to artifact
|
||||
run_podman artifact add --append $artifact_name "$testfile2"
|
||||
|
||||
# Get the created timestamp after append
|
||||
run_podman artifact inspect --format '{{index .Manifest.Annotations "org.opencontainers.image.created" }}\n{{len .Manifest.Layers}}' $artifact_name
|
||||
local current_created="${lines[0]}"
|
||||
local layer_count="${lines[1]}"
|
||||
|
||||
# Verify the created timestamp is preserved
|
||||
assert "$current_created" = "$created_annotation" "Created timestamp should be preserved during append"
|
||||
|
||||
# Verify we have 2 layers now
|
||||
assert "$layer_count" -eq 2 "Should have 2 layers after append"
|
||||
}
|
||||
|
||||
|
||||
@test "podman artifact add --replace basic functionality" {
|
||||
local artifact_name="localhost/test/replace-artifact"
|
||||
local file1 file2
|
||||
|
||||
file1=$(create_test_file 1024)
|
||||
file2=$(create_test_file 2048)
|
||||
file1=$(create_test_file)
|
||||
file2=$(create_test_file)
|
||||
|
||||
# Add initial artifact
|
||||
run_podman artifact add "$artifact_name" "$file1"
|
||||
@@ -56,7 +100,7 @@ create_test_file() {
|
||||
local artifact_name="localhost/test/nonexistent-artifact"
|
||||
local file1
|
||||
|
||||
file1=$(create_test_file 1024)
|
||||
file1=$(create_test_file)
|
||||
|
||||
# Using --replace on nonexistent artifact should succeed
|
||||
run_podman artifact add --replace "$artifact_name" "$file1"
|
||||
@@ -73,7 +117,7 @@ create_test_file() {
|
||||
local artifact_name="localhost/test/conflict-artifact"
|
||||
local file1
|
||||
|
||||
file1=$(create_test_file 1024)
|
||||
file1=$(create_test_file)
|
||||
|
||||
# Using --replace and --append together should fail
|
||||
run_podman 125 artifact add --replace --append "$artifact_name" "$file1"
|
||||
@@ -86,8 +130,8 @@ create_test_file() {
|
||||
local artifact_name="localhost/test/existing-artifact"
|
||||
local file1 file2
|
||||
|
||||
file1=$(create_test_file 512)
|
||||
file2=$(create_test_file 1024)
|
||||
file1=$(create_test_file)
|
||||
file2=$(create_test_file)
|
||||
|
||||
# Create initial artifact
|
||||
run_podman artifact add "$artifact_name" "$file1"
|
||||
@@ -109,3 +153,6 @@ create_test_file() {
|
||||
run_podman artifact rm "$artifact_name"
|
||||
rm -f "$file1" "$file2"
|
||||
}
|
||||
|
||||
|
||||
# vim: filetype=sh
|
||||
Reference in New Issue
Block a user