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