From 7ebf051043114cd33c7f90a1cad408d966cf919e Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Wed, 18 Sep 2019 11:35:34 -0400 Subject: [PATCH] testing: test building a source image from src.rpms Signed-off-by: Vincent Batts --- .gitignore | 4 ++++ Makefile | 20 ++++++++++++++++---- test/{simple.bats => 00-simple.bats} | 0 test/01-from_rpms.bats | 24 ++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 .gitignore rename test/{simple.bats => 00-simple.bats} (100%) create mode 100644 test/01-from_rpms.bats diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..50554ee --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ + +.build-container +.testprep +.validate diff --git a/Makefile b/Makefile index d355c66..cbc2c0e 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,12 @@ SRC := ./BuildSourceImage.sh CTR_IMAGE := localhost/containers/buildsourceimage CTR_ENGINE ?= podman cleanfiles = +# these are packages whose src.rpms are very small +srpm_urls = \ + https://archive.kernel.org/centos-vault/7.0.1406/os/Source/SPackages/basesystem-10.0-7.el7.centos.src.rpm \ + https://archive.kernel.org/centos-vault/7.0.1406/os/Source/SPackages/rootfiles-8.1-11.el7.src.rpm \ + https://archive.kernel.org/centos-vault/7.0.1406/os/Source/SPackages/centos-bookmarks-7-1.el7.src.rpm +srpms = $(addprefix ./.testprep/srpms/,$(notdir $(rpms))) all: validate @@ -16,14 +22,20 @@ build-container: .build-container cleanfiles += .build-container .build-container: .validate Dockerfile $(SRC) @echo - @echo "Building BuildSourceImage Container" + @echo "==> Building BuildSourceImage Container" $(CTR_ENGINE) build --quiet --file Dockerfile --tag $(CTR_IMAGE) . && touch $@ +cleanfiles += .testprep $(srpms) +.testprep: + @echo "==> Fetching SRPMs for testing against" + mkdir -p $@/{srpms,tmp} + wget -P $@/srpms/ $(srpm_urls) + .PHONY: test-integration -test-integration: .build-container +test-integration: .build-container .testprep @echo - @echo "Running integration tests" - CTR_IMAGE=$(CTR_IMAGE) CTR_ENGINE=$(CTR_ENGINE) bats test/ + @echo "==> Running integration tests" + CTR_IMAGE=$(CTR_IMAGE) CTR_ENGINE=$(CTR_ENGINE) TMPDIR=$(shell realpath .testprep/tmp) bats test/ clean: diff --git a/test/simple.bats b/test/00-simple.bats similarity index 100% rename from test/simple.bats rename to test/00-simple.bats diff --git a/test/01-from_rpms.bats b/test/01-from_rpms.bats new file mode 100644 index 0000000..2f44779 --- /dev/null +++ b/test/01-from_rpms.bats @@ -0,0 +1,24 @@ +#!/usr/bin/env bats -t + +@test "build from RPMS" { + d=$(mktemp -d) + run $CTR_ENGINE run --rm -v $(pwd)/.testprep/srpms/:/src:ro -v ${d}:/output/ $CTR_IMAGE -s /src + [ "$status" -eq 0 ] + #echo ${lines[@]} + [[ ${lines[0]} =~ "[SrcImg][INFO] calling source collection drivers" ]] + # get the number of the last line + n=$(expr ${#lines[@]} - 1) + [[ ${lines[${n}]} =~ "[SrcImg][INFO] copied to oci:/output:latest-source" ]] + + echo "${d}" + [ -f "${d}/index.json" ] + [ -f "${d}/oci-layout" ] + [ "$(du -b ${d}/index.json | awk '{ print $1 }')" -gt 0 ] + [ "$(du -b ${d}/oci-layout | awk '{ print $1 }')" -gt 0 ] + + # let's press that the files are predictable + [ "$(find ${d} -type f | wc -l)" -eq 7 ] + [ -f "${d}/blobs/sha256/3afb43699ea82a69b16efb215363604d9e4ffe16c9ace7e53df66663847309cf" ] + [ -f "${d}/blobs/sha256/7f4a50f05b7bd38017be8396b6320e1d2e6a05af097672e3ed23ef3df2ddeadb" ] + [ -f "${d}/blobs/sha256/8f4e610748f8b58a3297ecf78ecc8ff7b6420c3e559e3e20cad8ac178c6fe4e8" ] +}