github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/integration/docker/main_test.go (about) 1 // Copyright (c) 2018 Intel Corporation 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 5 package docker 6 7 import ( 8 "os" 9 "path/filepath" 10 "runtime" 11 "strings" 12 "testing" 13 14 "github.com/kata-containers/tests" 15 . "github.com/onsi/ginkgo" 16 . "github.com/onsi/gomega" 17 ) 18 19 const ( 20 shouldFail = true 21 shouldNotFail = false 22 ) 23 24 var _ = SynchronizedBeforeSuite(func() []byte { 25 // before start we have to download the docker images 26 for _, i := range images { 27 // vish/stress is single-arch image only for amd64 28 if i == StressImage && runtime.GOARCH != "amd64" { 29 //check if vish/stress has already been built 30 argsImage := []string{"--format", "'{{.Repository}}:{{.Tag}}'", StressImage} 31 imagesStdout, _, imagesExitcode := dockerImages(argsImage...) 32 Expect(imagesExitcode).To(BeZero()) 33 if imagesStdout == "" { 34 gopath := os.Getenv("GOPATH") 35 entirePath := filepath.Join(gopath, StressDockerFile) 36 argsBuild := []string{"-t", StressImage, entirePath} 37 _, _, buildExitCode := dockerBuild(argsBuild...) 38 Expect(buildExitCode).To(BeZero()) 39 } 40 } else { 41 _, _, exitCode := dockerPull(i) 42 Expect(exitCode).To(BeZero()) 43 } 44 } 45 46 return nil 47 }, func(data []byte) { 48 // check whether all images were downloaded 49 stdout, _, exitCode := dockerImages("--format", "{{.Repository}}") 50 Expect(exitCode).To(BeZero()) 51 52 dockerImages := strings.Split(stdout, "\n") 53 for _, i := range images { 54 found := false 55 // remove tag 56 i = strings.Split(i, ":")[0] 57 for _, dockerImage := range dockerImages { 58 if i == dockerImage { 59 found = true 60 break 61 } 62 } 63 Expect(found).To(BeTrue()) 64 } 65 }) 66 67 func TestIntegration(t *testing.T) { 68 RegisterFailHandler(Fail) 69 RunSpecs(t, "Integration Suite") 70 } 71 72 func TestMain(m *testing.M) { 73 tests.KataInit() 74 os.Exit(m.Run()) 75 }