From f6e2d9440942865c835a624f521af4d8322c9bde Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Tue, 25 Feb 2025 18:49:51 +0100 Subject: [PATCH] test/e2e: improve createArtifactFile() There is no need whatsoever to run container to populate a random file, this is just much slower than just writing some random bytes directly without having to run a container and run dd in it. Also the function accepted the number of bytes, however because dd uses a minimum block size of 512 bytes it was actually numBytes * 1024 which where written. That makes no sense so fix the two tests that depended on the wrong number. Signed-off-by: Paul Holzinger --- test/e2e/artifact_test.go | 4 ++-- test/e2e/common_test.go | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/test/e2e/artifact_test.go b/test/e2e/artifact_test.go index 001b142392..e5b34d64b3 100644 --- a/test/e2e/artifact_test.go +++ b/test/e2e/artifact_test.go @@ -475,7 +475,7 @@ var _ = Describe("Podman artifact", func() { a := podmanTest.InspectArtifact(artifact1Name) Expect(a.Manifest.Layers).To(HaveLen(1)) - Expect(a.TotalSizeBytes()).To(Equal(int64(524288))) + Expect(a.TotalSizeBytes()).To(Equal(int64(1024))) }) It("podman artifact add file already exists in artifact", func() { @@ -506,7 +506,7 @@ var _ = Describe("Podman artifact", func() { a := podmanTest.InspectArtifact(artifact1Name) Expect(a.Manifest.Layers).To(HaveLen(1)) - Expect(a.TotalSizeBytes()).To(Equal(int64(1048576))) + Expect(a.TotalSizeBytes()).To(Equal(int64(2048))) }) It("podman artifact add with --append and --type", func() { diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index 3773c1739b..518a8f028d 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -5,6 +5,7 @@ package integration import ( "bufio" "bytes" + crand "crypto/rand" "encoding/json" "errors" "fmt" @@ -1390,6 +1391,7 @@ func writeYaml(content string, fileName string) error { func GetPort() int { portMin := 5000 portMax := 5999 + rng := rand.New(rand.NewSource(time.Now().UnixNano())) // Avoid dup-allocation races between parallel ginkgo processes @@ -1617,16 +1619,22 @@ func setupRegistry(portOverride *int) (*lockfile.LockFile, string, error) { } func createArtifactFile(numBytes int64) (string, error) { + GinkgoHelper() artifactDir := filepath.Join(podmanTest.TempDir, "artifacts") if err := os.MkdirAll(artifactDir, 0755); err != nil { return "", err } filename := RandomString(8) outFile := filepath.Join(artifactDir, filename) - session := podmanTest.Podman([]string{"run", "-v", fmt.Sprintf("%s:/artifacts:z", artifactDir), ALPINE, "dd", "if=/dev/urandom", fmt.Sprintf("of=%s", filepath.Join("/artifacts", filename)), "bs=1b", fmt.Sprintf("count=%d", numBytes)}) - session.WaitWithDefaultTimeout() - if session.ExitCode() != 0 { - return "", errors.New("unable to generate artifact file") + + f, err := os.Create(filepath.Join(artifactDir, filename)) + if err != nil { + return "", err + } + defer f.Close() + _, err = io.CopyN(f, crand.Reader, numBytes) + if err != nil { + return "", err } return outFile, nil }