github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/models/application_test.go (about) 1 package models_test 2 3 import ( 4 "os" 5 6 . "code.cloudfoundry.org/cli/cf/models" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 ) 10 11 var _ = Describe("Merge", func() { 12 var ( 13 appParams AppParams 14 flagContext AppParams 15 ) 16 17 BeforeEach(func() { 18 appParams = AppParams{} 19 flagContext = AppParams{} 20 }) 21 22 JustBeforeEach(func() { 23 appParams.Merge(&flagContext) 24 }) 25 26 Context("when the Docker username is set in neither flag context nor manifest", func() { 27 It("leaves the merged Docker password as nil", func() { 28 Expect(appParams.DockerPassword).To(BeNil()) 29 }) 30 }) 31 32 Context("when the Docker username is set in the flag context", func() { 33 BeforeEach(func() { 34 user := "my-user" 35 flagContext.DockerUsername = &user 36 37 password := "my-pass" 38 flagContext.DockerPassword = &password 39 }) 40 41 It("copies the Docker password from the flag context", func() { 42 Expect(appParams.DockerPassword).NotTo(BeNil()) 43 Expect(*appParams.DockerPassword).To(Equal("my-pass")) 44 }) 45 }) 46 47 Context("when the Docker username is not set in the flag context but is set in the manifest", func() { 48 var oldDockerPassword string 49 50 BeforeEach(func() { 51 oldDockerPassword = os.Getenv("CF_DOCKER_PASSWORD") 52 Expect(os.Setenv("CF_DOCKER_PASSWORD", "some-docker-pass")).ToNot(HaveOccurred()) 53 54 password := "should-not-be-me" 55 flagContext.DockerPassword = &password 56 57 user := "my-manifest-user" 58 appParams.DockerUsername = &user 59 }) 60 61 AfterEach(func() { 62 Expect(os.Setenv("CF_DOCKER_PASSWORD", oldDockerPassword)).ToNot(HaveOccurred()) 63 }) 64 65 It("grabs the Docker password from the env var CF_DOCKER_PASSWORD", func() { 66 Expect(appParams.DockerPassword).NotTo(BeNil()) 67 Expect(*appParams.DockerPassword).To(Equal("some-docker-pass")) 68 }) 69 }) 70 })