mirror of
https://github.com/containers/podman.git
synced 2025-10-18 03:33:32 +08:00
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 <pholzing@redhat.com>
This commit is contained in:
@ -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() {
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user