forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall_plugin_command_test.go
144 lines (120 loc) · 3.63 KB
/
uninstall_plugin_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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package plugin_test
import (
"errors"
"os"
"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/command/translatableerror"
"code.cloudfoundry.org/cli/util/configv3"
"code.cloudfoundry.org/cli/util/ui"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
)
var _ = Describe("uninstall-plugin command", func() {
var (
cmd UninstallPluginCommand
testUI *ui.UI
fakeConfig *commandfakes.FakeConfig
fakeActor *pluginfakes.FakeUninstallPluginActor
executeErr error
)
BeforeEach(func() {
testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer())
fakeConfig = new(commandfakes.FakeConfig)
somePlugin := configv3.Plugin{
Name: "some-plugin",
Version: configv3.PluginVersion{
Major: 1,
Minor: 2,
Build: 3,
},
}
fakeConfig.GetPluginCaseInsensitiveReturns(somePlugin, true)
fakeActor = new(pluginfakes.FakeUninstallPluginActor)
cmd = UninstallPluginCommand{
UI: testUI,
Config: fakeConfig,
Actor: fakeActor,
}
cmd.RequiredArgs.PluginName = "some-plugin"
})
JustBeforeEach(func() {
executeErr = cmd.Execute(nil)
})
When("the plugin is installed", func() {
BeforeEach(func() {
fakeActor.UninstallPluginReturns(nil)
})
When("no errors are encountered", func() {
It("uninstalls the plugin and outputs the success message", func() {
Expect(executeErr).ToNot(HaveOccurred())
Expect(testUI.Out).To(Say("Uninstalling plugin some-plugin..."))
Expect(testUI.Out).To(Say("OK"))
Expect(testUI.Out).To(Say("Plugin some-plugin 1.2.3 successfully uninstalled."))
Expect(fakeActor.UninstallPluginCallCount()).To(Equal(1))
_, pluginName := fakeActor.UninstallPluginArgsForCall(0)
Expect(pluginName).To(Equal("some-plugin"))
})
})
When("uninstalling the plugin returns a plugin binary remove failed error", func() {
var pathError error
BeforeEach(func() {
pathError = &os.PathError{
Op: "some-op",
Err: errors.New("some error"),
}
fakeActor.UninstallPluginReturns(actionerror.PluginBinaryRemoveFailedError{
Err: pathError,
})
})
It("returns a PluginBinaryRemoveFailedError", func() {
Expect(executeErr).To(MatchError(translatableerror.PluginBinaryRemoveFailedError{
Err: pathError,
}))
})
})
When("uninstalling the plugin returns a plugin execute error", func() {
var pathError error
BeforeEach(func() {
pathError = &os.PathError{
Op: "some-op",
Err: errors.New("some error"),
}
fakeActor.UninstallPluginReturns(actionerror.PluginExecuteError{Err: pathError})
})
It("returns a PluginBinaryUninstallError", func() {
Expect(executeErr).To(MatchError(translatableerror.PluginBinaryUninstallError{
Err: pathError,
}))
})
})
When("uninstalling the plugin encounters any other error", func() {
var expectedErr error
BeforeEach(func() {
expectedErr = errors.New("some error")
fakeActor.UninstallPluginReturns(expectedErr)
})
It("returns the error", func() {
Expect(executeErr).To(MatchError(expectedErr))
})
})
})
When("the plugin is not installed", func() {
BeforeEach(func() {
fakeActor.UninstallPluginReturns(
actionerror.PluginNotFoundError{
PluginName: "some-plugin",
},
)
})
It("returns a PluginNotFoundError", func() {
Expect(testUI.Out).To(Say("Uninstalling plugin some-plugin..."))
Expect(executeErr).To(MatchError(actionerror.PluginNotFoundError{
PluginName: "some-plugin",
}))
})
})
})