-
Notifications
You must be signed in to change notification settings - Fork 28
/
patch.go
148 lines (126 loc) · 4.62 KB
/
patch.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
145
146
147
148
package test
import (
"fmt"
"net/http"
"strconv"
"github.com/Peripli/service-manager/pkg/types"
"github.com/gavv/httpexpect"
. "github.com/onsi/gomega"
"github.com/Peripli/service-manager/test/common"
. "github.com/onsi/ginkgo"
)
func DescribePatchTestsFor(ctx *common.TestContext, t TestCase, responseMode ResponseMode) bool {
return Describe("Patch", func() {
var testResource common.Object
var testResourceID string
var asyncParam = strconv.FormatBool(bool(responseMode))
createTestResourceWithAuth := func(auth *common.SMExpect) {
testResource = t.ResourceBlueprint(ctx, auth, bool(responseMode))
By(fmt.Sprintf("[SETUP]: Verifying that test resource %v is not empty", testResource))
Expect(testResource).ToNot(BeEmpty())
By(fmt.Sprintf("[SETUP]: Verifying that test resource %v has an id of type string", testResource))
testResourceID = testResource["id"].(string)
Expect(testResourceID).ToNot(BeEmpty())
}
verifyPatchedResource := func(resp *httpexpect.Response) {
switch responseMode {
case Async:
resp.Status(http.StatusAccepted)
case Sync:
resp.Status(http.StatusOK)
}
common.VerifyOperationExists(ctx, resp.Header("Location").Raw(), common.OperationExpectations{
Category: types.UPDATE,
State: types.SUCCEEDED,
ResourceType: types.ObjectType(t.API),
Reschedulable: false,
DeletionScheduled: false,
})
}
Context(fmt.Sprintf("Existing resource of type %s", t.API), func() {
Context("with bearer auth", func() {
if !t.StrictlyTenantScoped {
Context("when the resource is global", func() {
BeforeEach(func() {
createTestResourceWithAuth(ctx.SMWithOAuth)
})
Context("when authenticating with basic auth", func() {
It("returns 401", func() {
ctx.SMWithBasic.PATCH(t.API+"/"+testResourceID).WithQuery("async", asyncParam).WithJSON(common.Object{}).
Expect().
Status(http.StatusUnauthorized)
})
})
Context("when authenticating with global token", func() {
It("returns 200", func() {
resp := ctx.SMWithOAuth.PATCH(t.API+"/"+testResourceID).WithQuery("async", asyncParam).WithJSON(common.Object{}).Expect()
verifyPatchedResource(resp)
})
})
if !t.DisableTenantResources {
Context("when authenticating with tenant scoped token", func() {
It("returns 404", func() {
ctx.SMWithOAuthForTenant.PATCH(t.API+"/"+testResourceID).WithQuery("async", asyncParam).WithJSON(common.Object{}).
Expect().Status(http.StatusNotFound)
})
})
}
})
}
if !t.DisableTenantResources {
Context("when the resource is tenant scoped", func() {
BeforeEach(func() {
createTestResourceWithAuth(ctx.SMWithOAuthForTenant)
})
Context("when authenticating with basic auth", func() {
It("returns 401", func() {
ctx.SMWithBasic.PATCH(t.API+"/"+testResourceID).WithQuery("async", asyncParam).WithJSON(common.Object{}).
Expect().
Status(http.StatusUnauthorized)
})
})
if !t.StrictlyTenantScoped {
Context("when authenticating with global token", func() {
It("returns 200", func() {
resp := ctx.SMWithOAuth.PATCH(t.API+"/"+testResourceID).WithQuery("async", asyncParam).WithJSON(common.Object{}).Expect()
verifyPatchedResource(resp)
})
})
}
Context("when authenticating with tenant scoped token", func() {
It("returns 200", func() {
resp := ctx.SMWithOAuthForTenant.PATCH(t.API+"/"+testResourceID).WithQuery("async", asyncParam).WithJSON(common.Object{}).Expect()
verifyPatchedResource(resp)
})
})
})
}
})
})
Context(fmt.Sprintf("Not existing resource of type %s", t.API), func() {
BeforeEach(func() {
testResourceID = "non-existing-id"
})
Context("when authenticating with basic auth", func() {
It("returns 401", func() {
ctx.SMWithBasic.PATCH(t.API+"/"+testResourceID).WithQuery("async", asyncParam).WithJSON(common.Object{}).
Expect().
Status(http.StatusUnauthorized)
})
})
Context("when authenticating with global token", func() {
if t.StrictlyTenantScoped {
It("returns 400", func() {
ctx.SMWithOAuth.PATCH(t.API+"/"+testResourceID).WithQuery("async", asyncParam).WithJSON(common.Object{}).
Expect().Status(http.StatusBadRequest)
})
} else {
It("returns 404", func() {
ctx.SMWithOAuth.PATCH(t.API+"/"+testResourceID).WithQuery("async", asyncParam).WithJSON(common.Object{}).
Expect().Status(http.StatusNotFound)
})
}
})
})
})
}