github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/integration/v7/push/docker_test.go (about) 1 package push 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 . "github.com/onsi/ginkgo" 6 . "github.com/onsi/gomega" 7 . "github.com/onsi/gomega/gbytes" 8 . "github.com/onsi/gomega/gexec" 9 ) 10 11 var _ = Describe("pushing docker images", func() { 12 var ( 13 appName string 14 ) 15 16 BeforeEach(func() { 17 appName = helpers.PrefixedRandomName("app") 18 }) 19 20 When("the docker image is valid", func() { 21 It("uses the specified docker image", func() { 22 session := helpers.CF(PushCommandName, appName, "-o", PublicDockerImage) 23 24 Eventually(session).Should(Say(`name:\s+%s`, appName)) 25 Eventually(session).Should(Say(`requested state:\s+started`)) 26 Eventually(session).Should(Say("stack:")) 27 Consistently(session).ShouldNot(Say("buildpacks:")) 28 Eventually(session).Should(Say(`docker image:\s+%s`, PublicDockerImage)) 29 Eventually(session).Should(Exit(0)) 30 }) 31 }) 32 33 When("the docker image is invalid", func() { 34 It("displays an error and exits 1", func() { 35 session := helpers.CF(PushCommandName, appName, "-o", "some-invalid-docker-image") 36 Eventually(session.Err).Should(Say("StagingError - Staging error: staging failed")) 37 Eventually(session).Should(Say("FAILED")) 38 Eventually(session).Should(Exit(1)) 39 }) 40 }) 41 42 When("a docker username and password are provided with a private image", func() { 43 var ( 44 privateDockerImage string 45 privateDockerUsername string 46 privateDockerPassword string 47 ) 48 49 BeforeEach(func() { 50 privateDockerImage, privateDockerUsername, privateDockerPassword = helpers.SkipIfPrivateDockerInfoNotSet() 51 }) 52 53 When("the docker passwored is provided via environment variable", func() { 54 It("uses the specified private docker image", func() { 55 session := helpers.CustomCF( 56 helpers.CFEnv{ 57 EnvVars: map[string]string{"CF_DOCKER_PASSWORD": privateDockerPassword}, 58 }, 59 PushCommandName, appName, 60 "--docker-username", privateDockerUsername, 61 "--docker-image", privateDockerImage, 62 ) 63 64 Eventually(session).Should(Say("Using docker repository password from environment variable CF_DOCKER_PASSWORD.")) 65 Consistently(session).ShouldNot(Say("Docker password")) 66 Eventually(session).Should(Say(`name:\s+%s`, appName)) 67 Eventually(session).Should(Say(`requested state:\s+started`)) 68 Eventually(session).Should(Say("stack:")) 69 Consistently(session).ShouldNot(Say("buildpacks:")) 70 Eventually(session).Should(Say(`docker image:\s+%s`, privateDockerImage)) 71 Eventually(session).Should(Exit(0)) 72 }) 73 }) 74 75 When("the docker passwored is not provided", func() { 76 var buffer *Buffer 77 78 BeforeEach(func() { 79 buffer = NewBuffer() 80 _, err := buffer.Write([]byte(privateDockerPassword + "\n")) 81 Expect(err).NotTo(HaveOccurred()) 82 }) 83 84 It("prompts for the docker password", func() { 85 session := helpers.CFWithStdin(buffer, 86 PushCommandName, 87 appName, 88 "--docker-username", privateDockerUsername, 89 "--docker-image", privateDockerImage, 90 ) 91 92 Eventually(session).Should(Say("Environment variable CF_DOCKER_PASSWORD not set.")) 93 Eventually(session).Should(Say("Docker password")) 94 Eventually(session).Should(Say(`name:\s+%s`, appName)) 95 Eventually(session).Should(Say(`requested state:\s+started`)) 96 Eventually(session).Should(Say("stack:")) 97 Consistently(session).ShouldNot(Say("buildpacks:")) 98 Eventually(session).Should(Say(`docker image:\s+%s`, privateDockerImage)) 99 Eventually(session).Should(Exit(0)) 100 }) 101 }) 102 }) 103 })