diff options
author | Brent Baude <bbaude@redhat.com> | 2020-02-14 12:11:23 -0600 |
---|---|---|
committer | Brent Baude <bbaude@redhat.com> | 2020-02-14 12:11:23 -0600 |
commit | 08bb9317cbd1a00b4dd52bc3409699271351403d (patch) | |
tree | 3cc0115bd6fda66dca2baf3df854b1e2bd54aa20 /pkg/bindings/test/common_test.go | |
parent | 0c060dace19710716ff8f3a65865a295312d9d94 (diff) | |
download | podman-08bb9317cbd1a00b4dd52bc3409699271351403d.tar.gz podman-08bb9317cbd1a00b4dd52bc3409699271351403d.tar.bz2 podman-08bb9317cbd1a00b4dd52bc3409699271351403d.zip |
add caching for binding tests
add the ability to cache images instead of pull them. makes tests faster and less network use when we flip on CI.
Also added list images with filter test
Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/bindings/test/common_test.go')
-rw-r--r-- | pkg/bindings/test/common_test.go | 76 |
1 files changed, 72 insertions, 4 deletions
diff --git a/pkg/bindings/test/common_test.go b/pkg/bindings/test/common_test.go index 22cd0b7e0..dba94cb35 100644 --- a/pkg/bindings/test/common_test.go +++ b/pkg/bindings/test/common_test.go @@ -13,10 +13,30 @@ import ( "github.com/pkg/errors" ) +type testImage struct { + name string + shortName string + tarballName string +} + const ( defaultPodmanBinaryLocation string = "/usr/bin/podman" - alpine string = "docker.io/library/alpine:latest" - busybox string = "docker.io/library/busybox:latest" +) + +var ( + ImageCacheDir = "/tmp/podman/imagecachedir" + LockTmpDir string + alpine = testImage{ + name: "docker.io/library/alpine:latest", + shortName: "alpine", + tarballName: "alpine.tar", + } + busybox = testImage{ + name: "docker.io/library/busybox:latest", + shortName: "busybox", + tarballName: "busybox.tar", + } + CACHE_IMAGES = []testImage{alpine, busybox} ) type bindingTest struct { @@ -109,7 +129,7 @@ func (b *bindingTest) startAPIService() *gexec.Session { var ( cmd []string ) - cmd = append(cmd, "--log-level=debug", "service", "--timeout=999999", b.sock) + cmd = append(cmd, "--log-level=debug", "system", "service", "--timeout=999999", b.sock) return b.runPodman(cmd) } @@ -127,6 +147,21 @@ func (b *bindingTest) Pull(name string) { p.Wait(45) } +func (b *bindingTest) Save(i testImage) { + p := b.runPodman([]string{"save", "-o", filepath.Join(ImageCacheDir, i.tarballName), i.name}) + p.Wait(45) +} + +func (b *bindingTest) RestoreImagesFromCache() { + for _, i := range CACHE_IMAGES { + b.restoreImageFromCache(i) + } +} +func (b *bindingTest) restoreImageFromCache(i testImage) { + p := b.runPodman([]string{"load", "-i", filepath.Join(ImageCacheDir, i.tarballName), i.name}) + p.Wait(45) +} + // Run a container and add append the alpine image to it func (b *bindingTest) RunTopContainer(name *string) { cmd := []string{"run", "-dt"} @@ -134,7 +169,7 @@ func (b *bindingTest) RunTopContainer(name *string) { containerName := *name cmd = append(cmd, "--name", containerName) } - cmd = append(cmd, alpine, "top") + cmd = append(cmd, alpine.name, "top") p := b.runPodman(cmd) p.Wait(45) } @@ -149,3 +184,36 @@ func StringInSlice(s string, sl []string) bool { } return false } + +var _ = ginkgo.SynchronizedBeforeSuite(func() []byte { + // make cache dir + if err := os.MkdirAll(ImageCacheDir, 0777); err != nil { + fmt.Printf("%q\n", err) + os.Exit(1) + } + + // If running localized tests, the cache dir is created and populated. if the + // tests are remote, this is a no-op + createCache() + path, err := ioutil.TempDir("", "libpodlock") + if err != nil { + fmt.Println(err) + os.Exit(1) + } + return []byte(path) +}, func(data []byte) { + LockTmpDir = string(data) +}) + +func createCache() { + b := newBindingTest() + for _, i := range CACHE_IMAGES { + _, err := os.Stat(filepath.Join(ImageCacheDir, i.tarballName)) + if os.IsNotExist(err) { + // pull the image + b.Pull(i.name) + b.Save(i) + } + } + b.cleanup() +} |