-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathproject_policy_test.go
122 lines (99 loc) · 2.99 KB
/
project_policy_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
package client_test
import (
"errors"
. "github.com/env0/terraform-provider-env0/client"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
gomock "go.uber.org/mock/gomock"
)
const (
policyId = "policy0"
)
var _ = Describe("Policy", func() {
mockPolicy := Policy{
Id: policyId,
ProjectId: "project0",
DriftDetectionCron: "0 * * * *",
AutoDriftRemediation: "CODE_TO_CLOUD",
}
Describe("Policy", func() {
var policy Policy
var err error
path := "/policies?projectId=" + mockPolicy.ProjectId
Describe("Success", func() {
BeforeEach(func() {
policiesResult := mockPolicy
httpCall = mockHttpClient.EXPECT().
Get(path, nil, gomock.Any()).
Do(func(path string, request interface{}, response *Policy) {
*response = policiesResult
})
policy, err = apiClient.Policy(mockPolicy.ProjectId)
})
It("Should send GET request once", func() {
httpCall.Times(1)
})
It("Should return policy", func() {
Expect(policy).Should(Equal(mockPolicy))
})
It("Should not return an error", func() {
Expect(err).Should(BeNil())
})
It("Should return policy with auto drift remediation", func() {
Expect(policy.AutoDriftRemediation).Should(Equal("CODE_TO_CLOUD"))
})
})
Describe("Failure", func() {
It("On error from server return the error", func() {
expectedErr := errors.New("some error")
httpCall = mockHttpClient.EXPECT().
Get(path, nil, gomock.Any()).
Return(expectedErr)
_, err = apiClient.Policy(mockPolicy.ProjectId)
Expect(expectedErr).Should(Equal(err))
})
})
})
Describe("PolicyUpdate", func() {
updatePolicyPayload := PolicyUpdatePayload{
ProjectId: "project0",
DriftDetectionCron: "0 * * * *",
DriftDetectionEnabled: true,
AutoDriftRemediation: "CODE_TO_CLOUD",
}
Describe("Success", func() {
var updatedPolicy Policy
var err error
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().
Put("/policies", updatePolicyPayload, gomock.Any()).
Do(func(path string, request interface{}, response *Policy) {
*response = mockPolicy
})
updatedPolicy, err = apiClient.PolicyUpdate(updatePolicyPayload)
})
It("Should send Put request with expected payload", func() {
httpCall.Times(1)
})
It("Should not return an error", func() {
Expect(err).To(BeNil())
})
It("Should return team received from API", func() {
Expect(updatedPolicy).To(Equal(mockPolicy))
})
It("Should return policy with updated auto drift remediation", func() {
Expect(updatedPolicy.AutoDriftRemediation).To(Equal("CODE_TO_CLOUD"))
})
})
Describe("Failure", func() {
It("On error from server return the error", func() {
expectedErr := errors.New("some error")
httpCall = mockHttpClient.EXPECT().
Put("/policies", updatePolicyPayload, gomock.Any()).
Return(expectedErr)
_, err := apiClient.PolicyUpdate(updatePolicyPayload)
Expect(expectedErr).Should(Equal(err))
})
})
})
})