Skip to content

Commit

Permalink
test(gzip): add unit tests for gzip
Browse files Browse the repository at this point in the history
Signed-off-by: Ramkumar Chinchani <[email protected]>
  • Loading branch information
rchincha committed Nov 2, 2023
1 parent e93dc0d commit 3fd3dce
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 7 deletions.
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ HACK_D := $(TOP_LEVEL)/hack
TOOLS_D := $(HACK_D)/tools
REGCLIENT := $(TOOLS_D)/bin/regctl
REGCLIENT_VERSION := v0.5.1
SKOPEO := $(TOOLS_D)/bin/skopeo
SKOPEO_VERSION := v1.9.3
# OCI registry
ZOT := $(TOOLS_D)/bin/zot
ZOT_VERSION := v2.0.0-rc6
Expand Down Expand Up @@ -99,6 +101,15 @@ $(REGCLIENT):
$(ZOT):
$(call dlbin,$@,https://github.com/project-zot/zot/releases/download/$(ZOT_VERSION)/zot-linux-amd64-minimal)

$(SKOPEO):
tmpdir=$$(mktemp -d); \
cd $$tmpdir; \
git clone -b $(SKOPEO_VERSION) https://github.com/containers/skopeo.git; \
cd skopeo; \
make bin/skopeo; \
cp bin/skopeo $(SKOPEO); \
cd $(TOP_LEVEL)

TEST?=$(patsubst test/%.bats,%,$(wildcard test/*.bats))
PRIVILEGE_LEVEL?=

Expand All @@ -108,7 +119,7 @@ PRIVILEGE_LEVEL?=
check: lint test go-test

.PHONY: test
test: stacker $(REGCLIENT) $(ZOT)
test: stacker $(REGCLIENT) $(SKOPEO) $(ZOT)
sudo -E PATH="$$PATH" \
LXC_BRANCH=$(LXC_BRANCH) \
LXC_CLONE_URL=$(LXC_CLONE_URL) \
Expand Down
25 changes: 19 additions & 6 deletions install-build-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ set -o pipefail
set -o errexit

installdeps_fedora() {
sudo dnf install \
bats \
jq \
lxc-devel \
libcap-devel \
libacl-devel
sudo dnf install \
bats \
jq \
lxc-devel \
libcap-devel \
libacl-devel
# skopeo deps
sudo dnf install \
gpgme-devel \
libassuan-devel \
btrfs-progs-devel \
device-mapper-devel
if ! command -v go 2>/dev/null; then
sudo dnf install golang
go version
Expand Down Expand Up @@ -38,6 +44,13 @@ installdeps_ubuntu() {
skopeo \
squashfs-tools \
squashfuse
# skopeo deps
sudo apt -yy install \
libgpgme-dev \
libassuan-dev \
libbtrfs-dev \
libdevmapper-dev \
pkg-config
if ! command -v go 2>/dev/null; then
sudo apt -yy install golang-go
go version
Expand Down
117 changes: 117 additions & 0 deletions test/gzip.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
load helpers

function setup() {
stacker_setup
}

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 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 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 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 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" ]
}
3 changes: 3 additions & 0 deletions test/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ if [ "$(id -u)" != "0" ]; then
exit 1
fi

# use tools we build first
export PATH="$ROOT_DIR"/hack/tools/bin:"$PATH"

function skip_if_no_unpriv_overlay {
run sudo -u $SUDO_USER "${ROOT_DIR}/stacker" --debug internal-go testsuite-check-overlay
echo $output
Expand Down

0 comments on commit 3fd3dce

Please sign in to comment.