github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/push/docker_test.go (about) 1 package push 2 3 import ( 4 "io/ioutil" 5 "path/filepath" 6 7 "code.cloudfoundry.org/cli/integration/helpers" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gbytes" 11 . "github.com/onsi/gomega/gexec" 12 ) 13 14 var _ = Describe("pushing docker images", func() { 15 var ( 16 appName string 17 tempDir string 18 ) 19 20 BeforeEach(func() { 21 appName = helpers.PrefixedRandomName("app") 22 var err error 23 tempDir, err = ioutil.TempDir("", "simple-manifest-test") 24 Expect(err).ToNot(HaveOccurred()) 25 }) 26 27 var AssertThatItPrintsSuccessfulDockerPushOutput = func(session *Session, dockerImage string) { 28 Eventually(session).Should(Say(`name:\s+%s`, appName)) 29 Eventually(session).Should(Say(`requested state:\s+started`)) 30 Eventually(session).Should(Say("stack:")) 31 Consistently(session).ShouldNot(Say("buildpacks:")) 32 Eventually(session).Should(Say(`docker image:\s+%s`, dockerImage)) 33 Eventually(session).Should(Exit(0)) 34 } 35 36 When("a public docker image is specified in command line", func() { 37 When("the docker image is valid", func() { 38 It("uses the specified docker image", func() { 39 session := helpers.CF(PushCommandName, appName, "-o", PublicDockerImage) 40 41 AssertThatItPrintsSuccessfulDockerPushOutput(session, PublicDockerImage) 42 }) 43 }) 44 45 When("the docker image is invalid", func() { 46 It("displays an error and exits 1", func() { 47 session := helpers.CF(PushCommandName, appName, "-o", "some-invalid-docker-image") 48 Eventually(session.Err).Should(Say("StagingError - Staging error: staging failed")) 49 Eventually(session).Should(Say("FAILED")) 50 Eventually(session).Should(Exit(1)) 51 }) 52 }) 53 }) 54 55 When("a public docker image is only provided in the manifest", func() { 56 When("the docker image is valid", func() { 57 It("uses the specified docker image", func() { 58 manifestPath := filepath.Join(tempDir, "manifest.yml") 59 60 helpers.WriteManifest(manifestPath, map[string]interface{}{ 61 "applications": []map[string]interface{}{ 62 { 63 "name": appName, 64 "docker": map[string]interface{}{ 65 "image": PublicDockerImage, 66 }, 67 }, 68 }, 69 }) 70 session := helpers.CF( 71 PushCommandName, appName, 72 "-f", manifestPath, 73 ) 74 75 AssertThatItPrintsSuccessfulDockerPushOutput(session, PublicDockerImage) 76 }) 77 }) 78 79 When("the docker image is invalid", func() { 80 It("displays an error and exits 1", func() { 81 manifestPath := filepath.Join(tempDir, "manifest.yml") 82 83 helpers.WriteManifest(manifestPath, map[string]interface{}{ 84 "applications": []map[string]interface{}{ 85 { 86 "name": appName, 87 "docker": map[string]interface{}{ 88 "image": "some-invalid-docker-image", 89 }, 90 }, 91 }, 92 }) 93 session := helpers.CF( 94 PushCommandName, appName, 95 "-f", manifestPath, 96 ) 97 98 Eventually(session.Err).Should(Say("StagingError - Staging error: staging failed")) 99 Eventually(session).Should(Say("FAILED")) 100 Eventually(session).Should(Exit(1)) 101 }) 102 }) 103 }) 104 When("a docker username and password are provided with a private image", func() { 105 var ( 106 privateDockerImage string 107 privateDockerUsername string 108 privateDockerPassword string 109 ) 110 111 BeforeEach(func() { 112 privateDockerImage, privateDockerUsername, privateDockerPassword = helpers.SkipIfPrivateDockerInfoNotSet() 113 }) 114 115 When("the docker password is provided via environment variable", func() { 116 It("uses the specified private docker image", func() { 117 session := helpers.CustomCF( 118 helpers.CFEnv{ 119 EnvVars: map[string]string{"CF_DOCKER_PASSWORD": privateDockerPassword}, 120 }, 121 PushCommandName, appName, 122 "--docker-username", privateDockerUsername, 123 "--docker-image", privateDockerImage, 124 ) 125 126 Eventually(session).Should(Say("Using docker repository password from environment variable CF_DOCKER_PASSWORD.")) 127 Consistently(session).ShouldNot(Say("Docker password")) 128 129 AssertThatItPrintsSuccessfulDockerPushOutput(session, privateDockerImage) 130 }) 131 }) 132 133 When("the docker password is not provided", func() { 134 var buffer *Buffer 135 136 BeforeEach(func() { 137 buffer = NewBuffer() 138 _, err := buffer.Write([]byte(privateDockerPassword + "\n")) 139 Expect(err).NotTo(HaveOccurred()) 140 }) 141 142 It("prompts for the docker password", func() { 143 session := helpers.CFWithStdin(buffer, 144 PushCommandName, 145 appName, 146 "--docker-username", privateDockerUsername, 147 "--docker-image", privateDockerImage, 148 ) 149 150 Eventually(session).Should(Say("Environment variable CF_DOCKER_PASSWORD not set.")) 151 Eventually(session).Should(Say("Docker password")) 152 153 AssertThatItPrintsSuccessfulDockerPushOutput(session, privateDockerImage) 154 }) 155 }) 156 }) 157 158 When("a docker username and private image are only provided in the manifest", func() { 159 var ( 160 privateDockerImage string 161 privateDockerUsername string 162 privateDockerPassword string 163 ) 164 165 BeforeEach(func() { 166 privateDockerImage, privateDockerUsername, privateDockerPassword = helpers.SkipIfPrivateDockerInfoNotSet() 167 }) 168 169 When("the docker password is provided via environment variable", func() { 170 It("uses the specified private docker image", func() { 171 manifestPath := filepath.Join(tempDir, "manifest.yml") 172 173 helpers.WriteManifest(manifestPath, map[string]interface{}{ 174 "applications": []map[string]interface{}{ 175 { 176 "name": appName, 177 "docker": map[string]interface{}{ 178 "image": privateDockerImage, 179 "username": privateDockerUsername, 180 }, 181 }, 182 }, 183 }) 184 session := helpers.CustomCF( 185 helpers.CFEnv{ 186 EnvVars: map[string]string{"CF_DOCKER_PASSWORD": privateDockerPassword}, 187 }, 188 PushCommandName, appName, 189 "-f", manifestPath, 190 ) 191 192 Eventually(session).Should(Say("Using docker repository password from environment variable CF_DOCKER_PASSWORD.")) 193 Consistently(session).ShouldNot(Say("Docker password")) 194 195 AssertThatItPrintsSuccessfulDockerPushOutput(session, privateDockerImage) 196 }) 197 }) 198 199 When("the docker password is not provided", func() { 200 var buffer *Buffer 201 202 BeforeEach(func() { 203 buffer = NewBuffer() 204 _, err := buffer.Write([]byte(privateDockerPassword + "\n")) 205 Expect(err).NotTo(HaveOccurred()) 206 }) 207 208 It("prompts for the docker password", func() { 209 manifestPath := filepath.Join(tempDir, "manifest.yml") 210 helpers.WriteManifest(manifestPath, map[string]interface{}{ 211 "applications": []map[string]interface{}{ 212 { 213 "name": appName, 214 "docker": map[string]interface{}{ 215 "image": privateDockerImage, 216 "username": privateDockerUsername, 217 }, 218 }, 219 }, 220 }) 221 session := helpers.CFWithStdin(buffer, 222 PushCommandName, 223 appName, 224 "-f", manifestPath, 225 ) 226 227 Eventually(session).Should(Say("Environment variable CF_DOCKER_PASSWORD not set.")) 228 Eventually(session).Should(Say("Docker password")) 229 230 AssertThatItPrintsSuccessfulDockerPushOutput(session, privateDockerImage) 231 }) 232 }) 233 }) 234 235 })