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 <rchincha@cisco.com>
  • Loading branch information
rchincha committed Nov 3, 2023
1 parent 63b4c95 commit 7645c84
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 8 deletions.
17 changes: 16 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
export SKOPEO = $(TOOLS_D)/bin/skopeo
export SKOPEO_VERSION = 1.9.3
# OCI registry
ZOT := $(TOOLS_D)/bin/zot
ZOT_VERSION := v2.0.0-rc6
Expand Down Expand Up @@ -99,6 +101,19 @@ $(REGCLIENT):
$(ZOT):
$(call dlbin,$@,https://github.com/project-zot/zot/releases/download/$(ZOT_VERSION)/zot-linux-amd64-minimal)

$(SKOPEO):
@mkdir -p "$(TOOLS_D)/bin"; \
tmpdir=$$(mktemp -d); \
cd $$tmpdir; \
git clone https://github.com/containers/skopeo.git; \
cd skopeo; \
git fetch --all --tags --prune; \
git checkout tags/v$(SKOPEO_VERSION) -b tag-$(SKOPEO_VERSION); \
make bin/skopeo; \
cp bin/skopeo $(SKOPEO); \
cd $(TOP_LEVEL); \
rm -rf $$tmpdir;

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

Expand All @@ -108,7 +123,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
26 changes: 19 additions & 7 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 All @@ -35,9 +41,15 @@ installdeps_ubuntu() {
lxc-utils \
parallel \
pkg-config \
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
130 changes: 130 additions & 0 deletions test/gzip.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
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 --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" ]
}

0 comments on commit 7645c84

Please sign in to comment.