Files
podman/test/system/700-artifact.bats
Daniel J Walsh b765c91580 Add --replace option to podman artifact add command
This commit implements the --replace functionality for the artifact add command,
allowing users to replace existing artifacts without having to manually remove
them first.

Changes made:
- Add Replace field to ArtifactAddOptions entity types
- Add --replace CLI flag with validation to prevent conflicts with --append
- Implement replace logic in ABI backend to remove existing artifacts before adding
- Update API handlers and tunnel implementation for podman-remote support
- Add comprehensive documentation and examples to man page
- Add e2e and system BATS tests for --replace functionality
- Fix code formatting in pkg/bindings/artifacts/types_pull_options.go:
  * Reorder imports with proper spacing
  * Fix function declaration spacing
  * Convert spaces to proper tab indentation
  * Remove extraneous blank lines

The --replace option follows the same pattern as other podman replace options
like 'podman container create --replace' and 'podman pod create --replace'.
It gracefully handles cases where no existing artifact exists (no error thrown).

Usage examples:
  podman artifact add --replace quay.io/myimage/artifact:latest /path/to/file
  podman artifact add --replace localhost/test/artifact /tmp/newfile.txt

Fixes: Implements requested --replace functionality for artifact add command
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2025-10-06 12:22:40 -04:00

114 lines
3.1 KiB
Bash

#!/usr/bin/env bats -*- bats -*-
#
# Tests for podman artifact functionality
#
load helpers
function setup() {
basic_setup
}
function teardown() {
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"
}
# bats test_tags=ci:parallel
@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)
# Add initial artifact
run_podman artifact add "$artifact_name" "$file1"
local first_digest="$output"
# Verify initial artifact exists
run_podman artifact inspect "$artifact_name"
# Replace with different file
run_podman artifact add --replace "$artifact_name" "$file2"
local second_digest="$output"
# Verify artifact was replaced (different digest)
assert "$first_digest" != "$second_digest" "Replace should create different digest"
# Verify artifact still exists and is accessible
run_podman artifact inspect "$artifact_name"
# Cleanup
run_podman artifact rm "$artifact_name"
rm -f "$file1" "$file2"
}
# bats test_tags=ci:parallel
@test "podman artifact add --replace nonexistent artifact" {
local artifact_name="localhost/test/nonexistent-artifact"
local file1
file1=$(create_test_file 1024)
# Using --replace on nonexistent artifact should succeed
run_podman artifact add --replace "$artifact_name" "$file1"
# Verify artifact was created
run_podman artifact inspect "$artifact_name"
# Cleanup
run_podman artifact rm "$artifact_name"
rm -f "$file1"
}
# bats test_tags=ci:parallel
@test "podman artifact add --replace and --append conflict" {
local artifact_name="localhost/test/conflict-artifact"
local file1
file1=$(create_test_file 1024)
# Using --replace and --append together should fail
run_podman 125 artifact add --replace --append "$artifact_name" "$file1"
assert "$output" =~ "--append and --replace options cannot be used together"
rm -f "$file1"
}
# bats test_tags=ci:parallel
@test "podman artifact add --replace with existing artifact" {
local artifact_name="localhost/test/existing-artifact"
local file1 file2
file1=$(create_test_file 512)
file2=$(create_test_file 1024)
# Create initial artifact
run_podman artifact add "$artifact_name" "$file1"
# Verify initial artifact exists
run_podman artifact inspect "$artifact_name"
# Adding same name without --replace should fail
run_podman 125 artifact add "$artifact_name" "$file2"
assert "$output" =~ "artifact already exists"
# Replace should succeed
run_podman artifact add --replace "$artifact_name" "$file2"
# Verify artifact was replaced
run_podman artifact inspect "$artifact_name"
# Cleanup
run_podman artifact rm "$artifact_name"
rm -f "$file1" "$file2"
}