forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrevisions_test.go
136 lines (117 loc) · 4.06 KB
/
revisions_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
package ccv3_test
import (
"net/http"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/ccv3fakes"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
"code.cloudfoundry.org/cli/resources"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Revisions", func() {
var (
client *Client
requester *ccv3fakes.FakeRequester
)
BeforeEach(func() {
requester = new(ccv3fakes.FakeRequester)
client, _ = NewFakeRequesterTestClient(requester)
})
Describe("GetApplicationRevisions", func() {
var (
query Query
revisions []resources.Revision
warnings Warnings
executeErr error
)
JustBeforeEach(func() {
revisions, warnings, executeErr = client.GetApplicationRevisions("some-app-guid", query)
})
When("the cloud controller returns errors and warnings", func() {
BeforeEach(func() {
errors := []ccerror.V3Error{
{
Code: 10008,
Detail: "The request is semantically invalid: command presence",
Title: "CF-UnprocessableEntity",
},
{
Code: 10010,
Detail: "App not found",
Title: "CF-ResourceNotFound",
},
}
requester.MakeListRequestReturns(
IncludedResources{},
Warnings{"this is a warning"},
ccerror.MultiError{ResponseCode: http.StatusTeapot, Errors: errors},
)
})
It("returns the error and all warnings", func() {
Expect(executeErr).To(MatchError(ccerror.MultiError{
ResponseCode: http.StatusTeapot,
Errors: []ccerror.V3Error{
{
Code: 10008,
Detail: "The request is semantically invalid: command presence",
Title: "CF-UnprocessableEntity",
},
{
Code: 10010,
Detail: "App not found",
Title: "CF-ResourceNotFound",
},
},
}))
Expect(warnings).To(ConsistOf("this is a warning"))
})
})
When("applications exist", func() {
BeforeEach(func() {
requester.MakeListRequestCalls(func(requestParams RequestParams) (IncludedResources, Warnings, error) {
err := requestParams.AppendToList(resources.Revision{GUID: "app-guid-1"})
Expect(err).NotTo(HaveOccurred())
return IncludedResources{}, Warnings{"this is a warning", "this is another warning"}, nil
})
query = Query{Key: OrderBy, Values: []string{"-created_at"}}
})
It("returns the revisions and all warnings", func() {
Expect(requester.MakeListRequestCallCount()).To(Equal(1))
actualParams := requester.MakeListRequestArgsForCall(0)
Expect(actualParams.RequestName).To(Equal(internal.GetApplicationRevisionsRequest))
Expect(actualParams.Query).To(Equal([]Query{query}))
Expect(executeErr).NotTo(HaveOccurred())
Expect(warnings).To(ConsistOf("this is a warning", "this is another warning"))
Expect(revisions).To(ConsistOf([]resources.Revision{{GUID: "app-guid-1"}}))
})
})
})
Describe("GetApplicationRevisionsDeployed", func() {
var (
revisions []resources.Revision
warnings Warnings
executeErr error
)
JustBeforeEach(func() {
revisions, warnings, executeErr = client.GetApplicationRevisionsDeployed("some-app-guid")
})
When("applications exist", func() {
BeforeEach(func() {
requester.MakeListRequestCalls(func(requestParams RequestParams) (IncludedResources, Warnings, error) {
err := requestParams.AppendToList(resources.Revision{GUID: "app-guid-1"})
Expect(err).NotTo(HaveOccurred())
return IncludedResources{}, Warnings{"this is a warning", "this is another warning"}, nil
})
})
It("returns the revisions and all warnings", func() {
Expect(requester.MakeListRequestCallCount()).To(Equal(1))
actualParams := requester.MakeListRequestArgsForCall(0)
Expect(actualParams.RequestName).To(Equal(internal.GetApplicationRevisionsDeployedRequest))
Expect(executeErr).NotTo(HaveOccurred())
Expect(warnings).To(ConsistOf("this is a warning", "this is another warning"))
Expect(revisions).To(ConsistOf([]resources.Revision{{GUID: "app-guid-1"}}))
})
})
})
})