-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathpurge_config_command_test.go
More file actions
83 lines (70 loc) · 3.04 KB
/
purge_config_command_test.go
File metadata and controls
83 lines (70 loc) · 3.04 KB
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
package commands_test
import (
plugin_fakes "code.cloudfoundry.org/cli/v8/plugin/pluginfakes"
cli_fakes "github.com/cloudfoundry-incubator/multiapps-cli-plugin/cli/fakes"
"github.com/cloudfoundry-incubator/multiapps-cli-plugin/commands"
"github.com/cloudfoundry-incubator/multiapps-cli-plugin/testutil"
"github.com/cloudfoundry-incubator/multiapps-cli-plugin/ui"
util_fakes "github.com/cloudfoundry-incubator/multiapps-cli-plugin/util/fakes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("PurgeConfigCommand", func() {
Describe("Execute", func() {
const (
org = "test-org"
space = "test-space"
user = "test-user"
)
var name string
var cliConnection *plugin_fakes.FakeCliConnection
var clientFactory *commands.TestClientFactory
var command *commands.PurgeConfigCommand
var testTokenFactory *commands.TestTokenFactory
var oc testutil.OutputCapturer
var ex testutil.Expector
BeforeEach(func() {
ui.DisableTerminalOutput(true)
name = "purge-mta-config"
cliConnection = cli_fakes.NewFakeCliConnectionBuilder().
CurrentOrg("test-org-guid", org, nil).
CurrentSpace("test-space-guid", space, nil).
Username(user, nil).
AccessToken("bearer test-token", nil).Build()
testTokenFactory = commands.NewTestTokenFactory(cliConnection)
clientFactory = commands.NewTestClientFactory(nil, nil, nil)
deployServiceURLCalculator := util_fakes.NewDeployServiceURLFakeCalculator("deploy-service.test.ondemand.com")
command = commands.NewPurgeConfigCommand()
command.InitializeAll(name, cliConnection, testutil.NewCustomTransport(200), clientFactory, testTokenFactory, deployServiceURLCalculator)
oc = testutil.NewUIOutputCapturer()
ex = testutil.NewUIExpector()
})
Context("with an unknown flag", func() {
It("should print incorrect usage, call cf help, and exit with a non-zero status", func() {
output, status := oc.CaptureOutputAndStatus(func() int {
return command.Execute([]string{"-a"}).ToInt()
})
ex.ExpectFailure(status, output, "Incorrect usage. Unknown or wrong flags: -a")
Expect(cliConnection.CliCommandArgsForCall(0)).To(Equal([]string{"help", name}))
})
})
Context("with an unknown flag and one valid flag", func() {
It("should print incorrect usage, call cf help, and exit with a non-zero status", func() {
output, status := oc.CaptureOutputAndStatus(func() int {
return command.Execute([]string{"-a", "-u"}).ToInt()
})
ex.ExpectFailure(status, output, "Incorrect usage. Unknown or wrong flags: -a")
Expect(cliConnection.CliCommandArgsForCall(0)).To(Equal([]string{"help", name}))
})
})
Context("with wrong arguments", func() {
It("should print incorrect usage, call cf help, and exit with a non-zero status", func() {
output, status := oc.CaptureOutputAndStatus(func() int {
return command.Execute([]string{"x", "y", "z"}).ToInt()
})
ex.ExpectFailure(status, output, "Incorrect usage. Wrong arguments")
Expect(cliConnection.CliCommandArgsForCall(0)).To(Equal([]string{"help", name}))
})
})
})
})