Skip to content

Commit

Permalink
test: try parameterizing the tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
  • Loading branch information
rchincha committed Nov 4, 2023
1 parent 7645c84 commit b3d3ec6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 119 deletions.
124 changes: 5 additions & 119 deletions test/gzip.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,123 +8,9 @@ function teardown() {
cleanup
}

@test "import tar < 1M" {
mkdir -p folder1
truncate -s 512k folder1/file1
tar cvf test.tar folder1
cat > stacker.yaml <<EOF
tar:
from:
type: tar
url: test.tar
EOF
stacker build
cat oci/index.json | jq .
m1=$(cat oci/index.json | jq .manifests[0].digest | sed 's/sha256://' | tr -d \")
cat oci/blobs/sha256/"$m1" | jq .
l1=$(cat oci/blobs/sha256/"$m1" | jq .layers[0].digest | sed 's/sha256://' | tr -d \")
$SKOPEO --version
[[ "$($SKOPEO --version)" =~ "skopeo version ${SKOPEO_VERSION}" ]] || {
echo "$SKOPEO --version should be ${SKOPEO_VERSION}"
exit 1
}
$SKOPEO copy --format=oci oci:oci:tar containers-storage:test:tar
$SKOPEO copy --format=oci containers-storage:test:tar oci:oci:test
cat oci/index.json | jq .
m2=$(cat oci/index.json | jq .manifests[1].digest | sed 's/sha256://' | tr -d \")
cat oci/blobs/sha256/"$m2" | jq .
l2=$(cat oci/blobs/sha256/"$m2" | jq .layers[0].digest | sed 's/sha256://' | tr -d \")
echo "$l1"
echo "$l2"
[ "$l1" = "$l2" ]
}

@test "import tar > 1M" {
mkdir -p folder1
truncate -s 2m folder1/file1
tar cvf test.tar folder1
cat > stacker.yaml <<EOF
tar:
from:
type: tar
url: test.tar
EOF
stacker build
cat oci/index.json | jq .
m1=$(cat oci/index.json | jq .manifests[0].digest | sed 's/sha256://' | tr -d \")
cat oci/blobs/sha256/"$m1" | jq .
l1=$(cat oci/blobs/sha256/"$m1" | jq .layers[0].digest | sed 's/sha256://' | tr -d \")
[[ "$($SKOPEO --version)" =~ "skopeo version ${SKOPEO_VERSION}" ]] || {
echo "$SKOPEO --version should be ${SKOPEO_VERSION}"
exit 1
}
$SKOPEO copy --format=oci oci:oci:tar containers-storage:test:tar
$SKOPEO copy --format=oci containers-storage:test:tar oci:oci:test
cat oci/index.json | jq .
m2=$(cat oci/index.json | jq .manifests[1].digest | sed 's/sha256://' | tr -d \")
cat oci/blobs/sha256/"$m2" | jq .
l2=$(cat oci/blobs/sha256/"$m2" | jq .layers[0].digest | sed 's/sha256://' | tr -d \")
echo "$l1"
echo "$l2"
[ "$l1" = "$l2" ]
}

@test "import tar.gz < 1M" {
mkdir -p folder1
truncate -s 512k folder1/file1
tar cvzf test.tar.gz folder1
cat > stacker.yaml <<EOF
tar:
from:
type: tar
url: test.tar.gz
EOF
stacker build
cat oci/index.json | jq .
m1=$(cat oci/index.json | jq .manifests[0].digest | sed 's/sha256://' | tr -d \")
cat oci/blobs/sha256/"$m1" | jq .
l1=$(cat oci/blobs/sha256/"$m1" | jq .layers[0].digest | sed 's/sha256://' | tr -d \")
[[ "$($SKOPEO --version)" =~ "skopeo version ${SKOPEO_VERSION}" ]] || {
echo "$SKOPEO --version should be ${SKOPEO_VERSION}"
exit 1
}
$SKOPEO copy --format=oci oci:oci:tar containers-storage:test:tar
$SKOPEO copy --format=oci containers-storage:test:tar oci:oci:test
cat oci/index.json | jq .
m2=$(cat oci/index.json | jq .manifests[1].digest | sed 's/sha256://' | tr -d \")
cat oci/blobs/sha256/"$m2" | jq .
l2=$(cat oci/blobs/sha256/"$m2" | jq .layers[0].digest | sed 's/sha256://' | tr -d \")
echo "$l1"
echo "$l2"
[ "$l1" = "$l2" ]
}

@test "import tar.gz > 1M" {
mkdir -p folder1
truncate -s 2m folder1/file1
tar cvzf test.tar.gz folder1
cat > stacker.yaml <<EOF
tar:
from:
type: tar
url: test.tar.gz
EOF
stacker build
cat oci/index.json | jq .
m1=$(cat oci/index.json | jq .manifests[0].digest | sed 's/sha256://' | tr -d \")
cat oci/blobs/sha256/"$m1" | jq .
l1=$(cat oci/blobs/sha256/"$m1" | jq .layers[0].digest | sed 's/sha256://' | tr -d \")
[[ "$($SKOPEO --version)" =~ "skopeo version ${SKOPEO_VERSION}" ]] || {
echo "$SKOPEO --version should be ${SKOPEO_VERSION}"
exit 1
}
$SKOPEO copy --format=oci oci:oci:tar containers-storage:test:tar
$SKOPEO copy --format=oci containers-storage:test:tar oci:oci:test
cat oci/index.json | jq .
m2=$(cat oci/index.json | jq .manifests[1].digest | sed 's/sha256://' | tr -d \")
cat oci/blobs/sha256/"$m2" | jq .
l2=$(cat oci/blobs/sha256/"$m2" | jq .layers[0].digest | sed 's/sha256://' | tr -d \")
echo "$l1"
echo "$l2"
[ "$l1" = "$l2" ]
@test "import various sizes" {
test_copy_buffer_size 512k tar
test_copy_buffer_size 2m tar
test_copy_buffer_size 512k tar.gz
test_copy_buffer_size 2m tar.gz
}
44 changes: 44 additions & 0 deletions test/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,47 @@ function zot_teardown {
killall zot
rm -f $TEST_TMPDIR/zot-config.json
}

function test_copy_buffer_size() {
local buffer_size=$1
local file_type=$2
mkdir folder1
truncate -s $buffer_size folder1/file1
if [ $file_type = "tar" ]
then
tar cvf test.$file_type folder1
elif [ $file_type = "tar.gz" ]
then
tar cvzf test.$file_type folder1
else
echo "unknown file type: $file_type"
exit 1
fi
cat > stacker.yaml <<EOF
tar:
from:
type: tar
url: test.$file_type
EOF
stacker build
cat oci/index.json | jq .
m1=$(cat oci/index.json | jq .manifests[0].digest | sed 's/sha256://' | tr -d \")
cat oci/blobs/sha256/"$m1" | jq .
l1=$(cat oci/blobs/sha256/"$m1" | jq .layers[0].digest | sed 's/sha256://' | tr -d \")
$SKOPEO --version
[[ "$($SKOPEO --version)" =~ "skopeo version ${SKOPEO_VERSION}" ]] || {
echo "$SKOPEO --version should be ${SKOPEO_VERSION}"
exit 1
}
$SKOPEO copy --format=oci oci:oci:tar containers-storage:test:tar
$SKOPEO copy --format=oci containers-storage:test:tar oci:oci:test
cat oci/index.json | jq .
m2=$(cat oci/index.json | jq .manifests[1].digest | sed 's/sha256://' | tr -d \")
cat oci/blobs/sha256/"$m2" | jq .
l2=$(cat oci/blobs/sha256/"$m2" | jq .layers[0].digest | sed 's/sha256://' | tr -d \")
echo "$l1"
echo "$l2"
[ "$l1" = "$l2" ]
stacker clean
rm -rf folder1
}

0 comments on commit b3d3ec6

Please sign in to comment.