-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbusiness_mappings_test.go
178 lines (163 loc) · 4.74 KB
/
business_mappings_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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package cloudability
import (
"net/url"
"os"
"testing"
)
func TestNewBusinessMappingsEndpoint(t *testing.T) {
testClient := NewClient("testapikey")
e := testClient.BusinessMappings()
if e.BaseURL.String() != apiV3URL {
t.Errorf("BusinessMappingsEndpoint BaseURL mismatch. Got %s. Expected %s", e.BaseURL.String(), apiV3URL)
}
if e.EndpointPath != businessMappingsEndpoint {
t.Errorf("BusinessMappingsEndpoint EndpointPath mismatch. Got %s. Expected %s", e.EndpointPath, businessMappingsEndpoint)
}
}
func TestGetBusinessDimensions(t *testing.T) {
testServer := testAPI(t, "GET", "/business-mappings/dimensions", nil)
defer testServer.Close()
testClient := NewClient("testapikey")
e := testClient.BusinessMappings()
e.BaseURL, _ = url.Parse(testServer.URL)
_, err := e.GetBusinessDimensions()
if err != nil {
t.Fail()
}
}
func TestGetBusinessDimension(t *testing.T) {
testServer := testAPI(t, "GET", "/business-mappings/1", nil)
defer testServer.Close()
testClient := NewClient("testapikey")
e := testClient.BusinessMappings()
e.BaseURL, _ = url.Parse(testServer.URL)
_, err := e.GetBusinessDimension(1)
if err != nil {
t.Fail()
}
}
func TestNewBusinessDimension(t *testing.T) {
dimension := &BusinessMapping{
Kind: "test-kind",
Name: "test-name",
DefaultValue: "test-default-value",
// Statements: [],
}
testServer := testAPI(t, "POST", "/business-mappings", dimension)
defer testServer.Close()
testClient := NewClient("testapikey")
e := testClient.BusinessMappings()
e.BaseURL, _ = url.Parse(testServer.URL)
_, err := e.NewBusinessDimension(dimension)
if err != nil {
t.Fail()
}
}
func TestUpdateBusinessDimension(t *testing.T) {
dimension := &BusinessMapping{
Index: 1,
Kind: "test-kind",
Name: "test-name",
DefaultValue: "test-default-value",
// Statements: [],
}
testServer := testAPI(t, "PUT", "/business-mappings/1", dimension)
defer testServer.Close()
testClient := NewClient("testapikey")
e := testClient.BusinessMappings()
e.BaseURL, _ = url.Parse(testServer.URL)
err := e.UpdateBusinessDimension(dimension)
if err != nil {
t.Fail()
}
}
func TestDeleteBusinessDimension(t *testing.T) {
testServer := testAPI(t, "DELETE", "/business-mappings/1", nil)
defer testServer.Close()
testClient := NewClient("testapikey")
e := testClient.BusinessMappings()
e.BaseURL, _ = url.Parse(testServer.URL)
err := e.DeleteBusinessDimension(1)
if err != nil {
t.Fail()
}
}
func TestMultipleBusinessMapping(t *testing.T) {
bm1 := BusinessMapping{
Name: "bm1",
DefaultValue: "unallocated",
Statements: []*BusinessMappingStatement{
{
MatchExpression: "EXISTS TAG['Business_Unit']",
ValueExpression: "TAG['bm1']",
},
{
MatchExpression: "DIMENSION['vendor_account_identifier'] == '999999999999'",
ValueExpression: "'Mergers and Acquisitions'",
},
},
}
bm2 := BusinessMapping{
Name: "bm2",
DefaultValue: "unallocated",
Statements: []*BusinessMappingStatement{
{
MatchExpression: "EXISTS TAG['Business_Unit']",
ValueExpression: "TAG['bm2']",
},
{
MatchExpression: "DIMENSION['vendor_account_identifier'] == '999999999999'",
ValueExpression: "'Mergers and Acquisitions'",
},
},
}
bm3 := BusinessMapping{
Name: "bm3",
DefaultValue: "unallocated",
Statements: []*BusinessMappingStatement{
{
MatchExpression: "EXISTS TAG['Business_Unit']",
ValueExpression: "TAG['bm3']",
},
{
MatchExpression: "DIMENSION['vendor_account_identifier'] == '999999999999'",
ValueExpression: "'Mergers and Acquisitions'",
},
},
}
apikey := os.Getenv("CLOUDABILITY_APIKEY")
client := NewClient(apikey)
newbm1, err := client.BusinessMappings().NewBusinessDimension(&bm1)
if err != nil {
t.Fatalf("Error creating bm1: %s", err)
}
newbm2, err := client.BusinessMappings().NewBusinessDimension(&bm2)
if err != nil {
t.Fatalf("Error creating bm2: %s", err)
}
newbm3, err := client.BusinessMappings().NewBusinessDimension(&bm3)
if err != nil {
t.Fatalf("Error creating bm3: %s", err)
}
if newbm1.Name != "bm1" {
t.Fatalf(`New Business Dimension. Got: %q, Want: %q`, newbm1.Name, "bm1")
}
if newbm2.Name != "bm2" {
t.Fatalf(`New Business Dimension. Got: %q, Want: %q`, newbm2.Name, "bm2")
}
if newbm3.Name != "bm3" {
t.Fatalf(`New Business Dimension. Got: %q, Want: %q`, newbm3.Name, "bm3")
}
err = client.BusinessMappings().DeleteBusinessDimension(newbm1.Index)
if err != nil {
t.Fatalf("Error deleting bm1: %s", err)
}
err = client.BusinessMappings().DeleteBusinessDimension(newbm2.Index)
if err != nil {
t.Fatalf("Error deleting bm1: %s", err)
}
err = client.BusinessMappings().DeleteBusinessDimension(newbm3.Index)
if err != nil {
t.Fatalf("Error deleting bm1: %s", err)
}
}