forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprerequisites_test.go
More file actions
100 lines (84 loc) · 2.71 KB
/
prerequisites_test.go
File metadata and controls
100 lines (84 loc) · 2.71 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package command_test
import (
. "code.cloudfoundry.org/cli/command"
"code.cloudfoundry.org/cli/command/commandfakes"
"code.cloudfoundry.org/cli/util/configv3"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)
var _ = Describe("CheckTarget", func() {
var (
binaryName string
fakeConfig *commandfakes.FakeConfig
)
BeforeEach(func() {
binaryName = "faceman"
fakeConfig = new(commandfakes.FakeConfig)
fakeConfig.BinaryNameReturns(binaryName)
})
Context("when the api endpoint is set", func() {
BeforeEach(func() {
fakeConfig.TargetReturns("some-url")
})
Context("when the user is not logged in", func() {
It("returns an error", func() {
err := CheckTarget(fakeConfig, false, false)
Expect(err).To(MatchError(NotLoggedInError{
BinaryName: binaryName,
}))
})
})
Context("when the user is logged in", func() {
BeforeEach(func() {
fakeConfig.AccessTokenReturns("some-access-token")
fakeConfig.RefreshTokenReturns("some-refresh-token")
})
DescribeTable("targeting organization check",
func(isOrgTargeted bool, checkForTargeted bool, expectedError error) {
if isOrgTargeted {
fakeConfig.TargetedOrganizationReturns(configv3.Organization{
GUID: "some-org-guid",
})
}
err := CheckTarget(fakeConfig, checkForTargeted, false)
if expectedError != nil {
Expect(err).To(MatchError(expectedError))
} else {
Expect(err).ToNot(HaveOccurred())
}
},
Entry("it returns an error", false, true, NoTargetedOrgError{BinaryName: "faceman"}),
Entry("it does not return an error", false, false, nil),
Entry("it does not return an error", true, false, nil),
Entry("it does not return an error", true, true, nil),
)
Context("when the organization is targeted", func() {
BeforeEach(func() {
fakeConfig.TargetedOrganizationReturns(configv3.Organization{
GUID: "some-org-guid",
})
})
DescribeTable("targeting space check",
func(isSpaceTargeted bool, checkForTargeted bool, expectedError error) {
if isSpaceTargeted {
fakeConfig.TargetedSpaceReturns(configv3.Space{
GUID: "some-space-guid",
})
}
err := CheckTarget(fakeConfig, true, checkForTargeted)
if expectedError != nil {
Expect(err).To(MatchError(expectedError))
} else {
Expect(err).ToNot(HaveOccurred())
}
},
Entry("it returns an error", false, true, NoTargetedSpaceError{BinaryName: "faceman"}),
Entry("it does not return an error", false, false, nil),
Entry("it does not return an error", true, false, nil),
Entry("it does not return an error", true, true, nil),
)
})
})
})
})