Skip to content

Commit

Permalink
package e2e tests in rpm, part 2 of 3
Browse files Browse the repository at this point in the history
Part 2: specfile work:
 - add tests/e2e to existing podman-tests package
   - build a static ginkgo test binary
   - copy files needed by tests (registries, certs, build dirs)
   - create a run-tests script, because otherwise it'd be
     impossible for humans to figure out
 - fix tests that were assuming github source tree layout

This commit allows e2e tests to pass as root.

Signed-off-by: Ed Santiago <[email protected]>
  • Loading branch information
edsantiago committed May 9, 2024
1 parent d313ba8 commit b1627ff
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
54 changes: 54 additions & 0 deletions rpm/podman.spec
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Requires: openssl
Requires: socat
Requires: buildah
Requires: gnupg
Requires: zstd

%description tests
%{summary}
Expand Down Expand Up @@ -240,6 +241,10 @@ export BUILDTAGS="$BASEBUILDTAGS exclude_graphdriver_btrfs btrfs_noversion remot
export BUILDTAGS="$BASEBUILDTAGS $(hack/btrfs_installed_tag.sh) $(hack/btrfs_tag.sh)"
%gobuild -o bin/quadlet ./cmd/quadlet

# builds test/e2e/e2e.test
(cd test/tools && %gobuild -o build/ginkgo ./vendor/github.com/onsi/ginkgo/v2/ginkgo)
./test/tools/build/ginkgo build -tags="${BUILDTAGS:-}" test/e2e

# reset LDFLAGS for plugins binaries
LDFLAGS=''

Expand Down Expand Up @@ -271,6 +276,55 @@ rm -f %{buildroot}%{_mandir}/man5/docker*.5
install -d -p %{buildroot}/%{_datadir}/%{name}/test/system
cp -pav test/system %{buildroot}/%{_datadir}/%{name}/test/

# The compiled set of ginkgo tests, and a helper script
install -d -p %{buildroot}/%{_datadir}/%{name}/test/e2e
cp test/e2e/e2e.test hack/podman-registry %{buildroot}/%{_datadir}/%{name}/test/e2e

# Files and subdirectories used by those tests
for testfiles in certs deny.json policy.json redhat_sigstore.yaml registries.conf; do
cp -pav test/$testfiles %{buildroot}/%{_datadir}/%{name}/test/e2e/
done
for subdir in build cdi config quadlet sign testdata; do
cp -pav test/e2e/$subdir %{buildroot}/%{_datadir}/%{name}/test/e2e/
done

# Invoking ginkgo is complicated. Make it easier for end users.
cat >%{buildroot}/%{_datadir}/%{name}/test/e2e/run-tests <<EOF
#!/bin/bash
#
# Possible options:
#
# --ginkgo.focus "blah blah"
# --ginkgo.flake-attempts 3
# --ginkgo.parallel.total 3
# --ginkgo.randomize-all
#

# /tmp is probably too small for all we do
export TMPDIR=/var/tmp

# Fetch images only once. Important when rerunning e2e tests.
export PODMAN_TEST_IMAGE_CACHE_DIR=/var/tmp/ginkgo
mkdir -p \$PODMAN_TEST_IMAGE_CACHE_DIR

# The executables we're testing are the ones delivered in RPM
export PODMAN_BINARY=%{_bindir}/%{name}
export PODMAN_REMOTE_BINARY=%{_bindir}/%{name}-remote
export QUADLET_BINARY=%{_libexecdir}/%{name}/quadlet

# Where subtests will find files they need
export PODMAN_INTEGRATION_ROOT=%{_datadir}/%{name}/test/e2e

# Many tests rely on files relative to cwd
cd \$PODMAN_INTEGRATION_ROOT/

# Needed for podman-registry script
export PATH=\$PATH:\$PODMAN_INTEGRATION_ROOT

exec ./e2e.test --ginkgo.trace --ginkgo.v "\$@"
EOF
chmod 555 %{buildroot}/%{_datadir}/%{name}/test/e2e/run-tests

#define license tag if not already defined
%{!?_licensedir:%global license %doc}

Expand Down
8 changes: 3 additions & 5 deletions test/e2e/login_logout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ var _ = Describe("Podman login and logout", func() {

testImg = strings.Join([]string{server, "test-alpine"}, "/")

certDirPath = filepath.Join(os.Getenv("HOME"), ".config/containers/certs.d", server)
certDirPath = filepath.Join(podmanTest.TempDir, "certs")
err = os.MkdirAll(certDirPath, os.ModePerm)
Expect(err).ToNot(HaveOccurred())
cwd, _ := os.Getwd()
certPath = filepath.Join(cwd, "../", "certs")
certPath = filepath.Join(INTEGRATION_ROOT, "certs")

setup := SystemExec("cp", []string{filepath.Join(certPath, "domain.crt"), filepath.Join(certDirPath, "ca.crt")})
setup.WaitWithDefaultTimeout()
Expand Down Expand Up @@ -296,8 +295,7 @@ var _ = Describe("Podman login and logout", func() {
err = os.MkdirAll(certDir, os.ModePerm)
Expect(err).ToNot(HaveOccurred())

cwd, _ := os.Getwd()
certPath = filepath.Join(cwd, "../", "certs")
certPath = filepath.Join(INTEGRATION_ROOT, "certs")

setup := SystemExec("cp", []string{filepath.Join(certPath, "domain.crt"), filepath.Join(certDir, "ca.crt")})
setup.WaitWithDefaultTimeout()
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ var _ = Describe("Podman push", func() {
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll("/etc/containers/certs.d/localhost:5004")

cwd, _ := os.Getwd()
certPath := filepath.Join(cwd, "../", "certs")
certPath := filepath.Join(INTEGRATION_ROOT, "certs")

lock := GetPortLock("5004")
defer lock.Unlock()
Expand Down

0 comments on commit b1627ff

Please sign in to comment.