From ee7d3c534ce542aec6ee830d4f28eb565959e7cd Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 7 Sep 2026 18:04:51 +0200 Subject: [PATCH] pkg/machine/e2e: combine build context test Instead of creating a fresh machine which is slow reuse an existing test for this test. Also fix the test to actually check the file content properly, it was using the wrong build output. And then just use one cat for both files to make it a tiny bit faster. Signed-off-by: Paul Holzinger --- pkg/machine/e2e/basic_test.go | 64 ++++++++++++++--------------------- 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/pkg/machine/e2e/basic_test.go b/pkg/machine/e2e/basic_test.go index c772b72ce4..c1fa5279f7 100644 --- a/pkg/machine/e2e/basic_test.go +++ b/pkg/machine/e2e/basic_test.go @@ -145,6 +145,32 @@ var _ = Describe("run basic podman commands", func() { Expect(findmnt).To(Exit(0)) Expect(findmnt.outputToString()).To(ContainSubstring("virtiofs")) } + + // Test build context support + mainContextDir := GinkgoT().TempDir() + cfile := filepath.Join(mainContextDir, "test1") + err = os.WriteFile(cfile, []byte("test1-"+name+"\n"), 0o644) + Expect(err).ToNot(HaveOccurred()) + + additionalContextDir := GinkgoT().TempDir() + cfile = filepath.Join(additionalContextDir, "test2") + err = os.WriteFile(cfile, []byte("test2-"+name+"\n"), 0o644) + Expect(err).ToNot(HaveOccurred()) + + cfile = filepath.Join(mainContextDir, "Containerfile") + err = os.WriteFile(cfile, []byte("FROM "+TESTIMAGE+"\nCOPY test1 /\nCOPY --from=test-context test2 /\n"), 0o644) + Expect(err).ToNot(HaveOccurred()) + + bm = basicMachine{} + build, err = mb.setCmd(bm.withPodmanCommand([]string{"build", "-t", name, "--build-context", "test-context=" + additionalContextDir, mainContextDir})).run() + Expect(err).ToNot(HaveOccurred()) + Expect(build).To(Exit(0)) + Expect(build.outputToString()).To(ContainSubstring("COMMIT")) + + run, err = mb.setCmd(bm.withPodmanCommand([]string{"run", name, "cat", "/test1", "/test2"})).run() + Expect(err).ToNot(HaveOccurred()) + Expect(run).To(Exit(0)) + Expect(run.outputToString()).To(And(ContainSubstring("test1-"+name), ContainSubstring("test2-"+name))) }) It("Volume should be disabled by command line", func() { @@ -260,44 +286,6 @@ var _ = Describe("run basic podman commands", func() { Expect(ls.outputToString()).To(ContainSubstring(testString)) }) - It("podman build contexts", func() { - name := randomString() - i := new(initMachine) - session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withNow()).run() - Expect(err).ToNot(HaveOccurred()) - Expect(session).To(Exit(0)) - - mainContextDir := GinkgoT().TempDir() - cfile := filepath.Join(mainContextDir, "test1") - err = os.WriteFile(cfile, []byte(name), 0o644) - Expect(err).ToNot(HaveOccurred()) - - additionalContextDir := GinkgoT().TempDir() - cfile = filepath.Join(additionalContextDir, "test2") - err = os.WriteFile(cfile, []byte(name), 0o644) - Expect(err).ToNot(HaveOccurred()) - - cfile = filepath.Join(mainContextDir, "Containerfile") - err = os.WriteFile(cfile, []byte("FROM "+TESTIMAGE+"\nCOPY test1 /\nCOPY --from=test-context test2 /\n"), 0o644) - Expect(err).ToNot(HaveOccurred()) - - bm := basicMachine{} - build, err := mb.setCmd(bm.withPodmanCommand([]string{"build", "-t", name, "--build-context", "test-context=" + additionalContextDir, mainContextDir})).run() - Expect(err).ToNot(HaveOccurred()) - Expect(build).To(Exit(0)) - Expect(build.outputToString()).To(ContainSubstring("COMMIT")) - - run, err := mb.setCmd(bm.withPodmanCommand([]string{"run", name, "cat", "/test1"})).run() - Expect(err).ToNot(HaveOccurred()) - Expect(run).To(Exit(0)) - Expect(build.outputToString()).To(ContainSubstring(name)) - - run, err = mb.setCmd(bm.withPodmanCommand([]string{"run", name, "cat", "/test2"})).run() - Expect(err).ToNot(HaveOccurred()) - Expect(run).To(Exit(0)) - Expect(build.outputToString()).To(ContainSubstring(name)) - }) - It("CVE-2025-6032 regression test - HTTP", func() { // ensure that trying to pull from a local HTTP server fails and the connection will be rejected // ensure that tlsVerify is true by default