github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/command/plugin/add_plugin_repo_command_test.go (about) 1 package plugin_test 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/pluginaction" 5 "code.cloudfoundry.org/cli/command/commandfakes" 6 . "code.cloudfoundry.org/cli/command/plugin" 7 "code.cloudfoundry.org/cli/command/plugin/pluginfakes" 8 "code.cloudfoundry.org/cli/command/translatableerror" 9 "code.cloudfoundry.org/cli/util/ui" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 . "github.com/onsi/gomega/gbytes" 13 ) 14 15 var _ = Describe("add-plugin-repo command", func() { 16 var ( 17 cmd AddPluginRepoCommand 18 testUI *ui.UI 19 fakeConfig *commandfakes.FakeConfig 20 fakeActor *pluginfakes.FakeAddPluginRepoActor 21 executeErr error 22 ) 23 24 BeforeEach(func() { 25 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 26 fakeConfig = new(commandfakes.FakeConfig) 27 fakeActor = new(pluginfakes.FakeAddPluginRepoActor) 28 cmd = AddPluginRepoCommand{UI: testUI, Config: fakeConfig, Actor: fakeActor} 29 }) 30 31 JustBeforeEach(func() { 32 executeErr = cmd.Execute(nil) 33 }) 34 35 Context("when the provided repo name already exists", func() { 36 BeforeEach(func() { 37 cmd.RequiredArgs.PluginRepoName = "some-repo" 38 cmd.RequiredArgs.PluginRepoURL = "some-repo-URL" 39 fakeActor.AddPluginRepositoryReturns(pluginaction.RepositoryNameTakenError{Name: "some-repo"}) 40 }) 41 42 It("returns RepositoryNameTakenError", func() { 43 Expect(executeErr).To(MatchError(translatableerror.RepositoryNameTakenError{Name: "some-repo"})) 44 }) 45 }) 46 47 Context("when the provided repo name and URL already exist in the same repo", func() { 48 BeforeEach(func() { 49 cmd.RequiredArgs.PluginRepoName = "some-repo" 50 cmd.RequiredArgs.PluginRepoURL = "some-repo-URL" 51 fakeActor.AddPluginRepositoryReturns(pluginaction.RepositoryAlreadyExistsError{Name: "some-repo", URL: "https://some-repo-URL"}) 52 }) 53 54 It("displays a message that the repo is already registered and does not return an error", func() { 55 Expect(executeErr).ToNot(HaveOccurred()) 56 57 Expect(testUI.Out).To(Say("https://some-repo-URL already registered as some-repo")) 58 59 Expect(fakeActor.AddPluginRepositoryCallCount()).To(Equal(1)) 60 repoName, repoURL := fakeActor.AddPluginRepositoryArgsForCall(0) 61 Expect(repoName).To(Equal("some-repo")) 62 Expect(repoURL).To(Equal("some-repo-URL")) 63 }) 64 }) 65 66 Context("when an AddPluginRepositoryError is encountered", func() { 67 BeforeEach(func() { 68 cmd.RequiredArgs.PluginRepoName = "some-repo" 69 cmd.RequiredArgs.PluginRepoURL = "some-URL" 70 fakeActor.AddPluginRepositoryReturns(pluginaction.AddPluginRepositoryError{Name: "some-repo", URL: "some-URL", Message: "404"}) 71 }) 72 73 It("handles the error", func() { 74 Expect(executeErr).To(MatchError(translatableerror.AddPluginRepositoryError{Name: "some-repo", URL: "some-URL", Message: "404"})) 75 }) 76 }) 77 78 Context("when no errors are encountered", func() { 79 BeforeEach(func() { 80 cmd.RequiredArgs.PluginRepoName = "some-repo" 81 cmd.RequiredArgs.PluginRepoURL = "https://some-repo-URL" 82 fakeActor.AddPluginRepositoryReturns(nil) 83 }) 84 85 It("adds the plugin repo", func() { 86 Expect(executeErr).ToNot(HaveOccurred()) 87 88 Expect(testUI.Out).To(Say("https://some-repo-URL added as some-repo")) 89 90 Expect(fakeActor.AddPluginRepositoryCallCount()).To(Equal(1)) 91 repoName, repoURL := fakeActor.AddPluginRepositoryArgsForCall(0) 92 Expect(repoName).To(Equal("some-repo")) 93 Expect(repoURL).To(Equal("https://some-repo-URL")) 94 }) 95 }) 96 })