-
Notifications
You must be signed in to change notification settings - Fork 191
/
rest-org_integration_test.go
120 lines (98 loc) · 3.09 KB
/
rest-org_integration_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
package sdk_test
import (
"context"
"reflect"
"testing"
"github.com/grafana-tools/sdk"
)
func TestCreateDelete(t *testing.T) {
shouldSkip(t)
client := getClient(t)
ctx := context.Background()
oName := "coolorg"
o := sdk.Org{Name: oName}
statusMessage, err := client.CreateOrg(ctx, o)
if err != nil {
t.Fatalf("failed to create an org: %v (%s)", statusMessage, err.Error())
}
t.Logf("got status message: %v\n", statusMessage)
oID := *statusMessage.OrgID
retrievedOrg, err := client.GetOrgById(ctx, oID)
if err != nil {
t.Fatalf("failed to retrieved org: %s", err.Error())
}
if retrievedOrg.Name != o.Name {
t.Fatalf("got wrong org: got %s, expected %s", retrievedOrg.Name, o.Name)
}
_, err = client.DeleteOrg(ctx, oID)
if err != nil {
t.Fatalf("failed to delete org: %s", err.Error())
}
_, err = client.GetOrgById(ctx, oID)
if err == nil {
t.Fatalf("org %s is still there even though it should be deleted", o.Name)
}
}
// TestUpdateOrgAddress checks if updating Org address works correctly
func TestUpdateOrgAddress(t *testing.T) {
shouldSkip(t)
client := getClient(t)
ctx := context.Background()
// Create a new organization
oName := "coolorg"
o := sdk.Org{Name: oName}
statusMessage, err := client.CreateOrg(ctx, o)
if err != nil {
t.Fatalf("failed to create an org: %v (%s)", statusMessage, err.Error())
}
oID := *statusMessage.OrgID
// Test if updating organization by ID works as expected
// Create a dummy address object
address := sdk.Address{
Address1: "CoolAddress1",
Address2: "CoolAddress2",
City: "CoolCity",
ZipCode: "CoolZipCode",
State: "CoolState",
Country: "CoolCountry",
}
// Try updating organization address by Org ID
statusMessage, err = client.UpdateOrgAddress(ctx, address, oID)
if err != nil {
t.Fatalf("failed to update the address: %v (%s)", statusMessage, err.Error())
}
retrievedOrg, err := client.GetOrgById(ctx, oID)
if err != nil {
t.Fatalf("failed to retrieved org: %s", err.Error())
}
// Check if retrieved address values are equal to expected ones
if !reflect.DeepEqual(retrievedOrg.Address, address) {
t.Fatalf("got wrong address: got %+v, expected %+v", retrievedOrg.Address, address)
}
// Test if updating current organization works as expected
address = sdk.Address{
Address1: "NiceAddress1",
Address2: "NiceAddress2",
City: "NiceCity",
ZipCode: "NiceZipCode",
State: "NiceState",
Country: "NiceCountry",
}
statusMessage, err = client.SwitchActualUserContext(ctx, oID)
if err != nil {
t.Fatalf("failed to switch user context: %s", err.Error())
}
// Try updating current organization address
statusMessage, err = client.UpdateActualOrgAddress(ctx, address)
if err != nil {
t.Fatalf("failed to update the address: %v (%s)", statusMessage, err.Error())
}
retrievedOrg, err = client.GetActualOrg(ctx)
if err != nil {
t.Fatalf("failed to retrieved org: %s", err.Error())
}
// Check if retrieved address values are equal to expected ones
if !reflect.DeepEqual(retrievedOrg.Address, address) {
t.Fatalf("got wrong address: got %v, expected %v", retrievedOrg.Address, address)
}
}