github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/command/v7/docker_password_getter_test.go (about) 1 package v7_test 2 3 import ( 4 "code.cloudfoundry.org/cli/command/commandfakes" 5 . "code.cloudfoundry.org/cli/command/v7" 6 "code.cloudfoundry.org/cli/util/ui" 7 . "github.com/onsi/ginkgo" 8 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gbytes" 11 ) 12 13 var _ = Describe("GetDockerPassword", func() { 14 var ( 15 cmd PushCommand 16 fakeConfig *commandfakes.FakeConfig 17 testUI *ui.UI 18 19 dockerUsername string 20 containsPrivateDocker bool 21 22 executeErr error 23 dockerPassword string 24 25 input *Buffer 26 ) 27 28 BeforeEach(func() { 29 input = NewBuffer() 30 testUI = ui.NewTestUI(input, NewBuffer(), NewBuffer()) 31 fakeConfig = new(commandfakes.FakeConfig) 32 33 cmd = PushCommand{ 34 Config: fakeConfig, 35 UI: testUI, 36 } 37 }) 38 39 Describe("Get", func() { 40 JustBeforeEach(func() { 41 dockerPassword, executeErr = cmd.GetDockerPassword(dockerUsername, containsPrivateDocker) 42 }) 43 44 When("docker image is private", func() { 45 When("there is a manifest", func() { 46 BeforeEach(func() { 47 dockerUsername = "" 48 containsPrivateDocker = true 49 }) 50 51 When("a password is provided via environment variable", func() { 52 BeforeEach(func() { 53 fakeConfig.DockerPasswordReturns("some-docker-password") 54 }) 55 56 It("takes the password from the environment", func() { 57 Expect(executeErr).ToNot(HaveOccurred()) 58 59 Expect(testUI.Out).ToNot(Say("Environment variable CF_DOCKER_PASSWORD not set.")) 60 Expect(testUI.Out).ToNot(Say("Docker password")) 61 62 Expect(testUI.Out).To(Say("Using docker repository password from environment variable CF_DOCKER_PASSWORD.")) 63 64 Expect(dockerPassword).To(Equal("some-docker-password")) 65 }) 66 }) 67 68 When("no password is provided", func() { 69 BeforeEach(func() { 70 _, err := input.Write([]byte("some-docker-password\n")) 71 Expect(err).ToNot(HaveOccurred()) 72 }) 73 74 It("prompts for a password", func() { 75 Expect(executeErr).ToNot(HaveOccurred()) 76 77 Expect(testUI.Out).To(Say("Environment variable CF_DOCKER_PASSWORD not set.")) 78 Expect(testUI.Out).To(Say("Docker password")) 79 80 Expect(dockerPassword).To(Equal("some-docker-password")) 81 }) 82 }) 83 }) 84 85 When("there is no manifest", func() { 86 BeforeEach(func() { 87 dockerUsername = "some-docker-username" 88 containsPrivateDocker = false 89 }) 90 91 When("a password is provided via environment variable", func() { 92 BeforeEach(func() { 93 fakeConfig.DockerPasswordReturns("some-docker-password") 94 }) 95 96 It("takes the password from the environment", func() { 97 Expect(executeErr).ToNot(HaveOccurred()) 98 99 Expect(testUI.Out).ToNot(Say("Environment variable CF_DOCKER_PASSWORD not set.")) 100 Expect(testUI.Out).ToNot(Say("Docker password")) 101 102 Expect(testUI.Out).To(Say("Using docker repository password from environment variable CF_DOCKER_PASSWORD.")) 103 104 Expect(dockerPassword).To(Equal("some-docker-password")) 105 }) 106 }) 107 108 When("no password is provided", func() { 109 BeforeEach(func() { 110 _, err := input.Write([]byte("some-docker-password\n")) 111 Expect(err).ToNot(HaveOccurred()) 112 }) 113 114 It("prompts for a password", func() { 115 Expect(executeErr).ToNot(HaveOccurred()) 116 117 Expect(testUI.Out).To(Say("Environment variable CF_DOCKER_PASSWORD not set.")) 118 Expect(testUI.Out).To(Say("Docker password")) 119 120 Expect(dockerPassword).To(Equal("some-docker-password")) 121 }) 122 }) 123 }) 124 }) 125 When("docker image is public", func() { 126 BeforeEach(func() { 127 dockerUsername = "" 128 containsPrivateDocker = false 129 }) 130 131 It("does not prompt for a password", func() { 132 Expect(testUI.Out).ToNot(Say("Environment variable CF_DOCKER_PASSWORD not set.")) 133 Expect(testUI.Out).ToNot(Say("Docker password")) 134 Expect(testUI.Out).ToNot(Say("Using docker repository password from environment variable CF_DOCKER_PASSWORD.")) 135 }) 136 137 It("returns an empty password", func() { 138 Expect(executeErr).ToNot(HaveOccurred()) 139 Expect(dockerPassword).To(Equal("")) 140 }) 141 }) 142 }) 143 })