-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathworkspace_service_test.go
130 lines (106 loc) · 3.17 KB
/
workspace_service_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
// +build enterprise
package kong
import (
"testing"
uuid "github.com/satori/go.uuid"
"github.com/stretchr/testify/assert"
)
func TestWorkspaceService(T *testing.T) {
assert := assert.New(T)
client, err := NewTestClient(nil, nil)
assert.Nil(err)
assert.NotNil(client)
workspace := &Workspace{
Name: String("teamA"),
Meta: map[string]interface{}{
"color": "#814CA6",
"thumbnail": nil,
},
}
createdWorkspace, err := client.Workspaces.Create(defaultCtx, workspace)
assert.Nil(err)
assert.NotNil(createdWorkspace)
workspace, err = client.Workspaces.Get(defaultCtx, createdWorkspace.ID)
assert.Nil(err)
assert.NotNil(workspace)
workspace.Comment = String("new comment")
workspace, err = client.Workspaces.Update(defaultCtx, workspace)
assert.Nil(err)
assert.NotNil(workspace)
assert.NotNil(workspace.Config)
assert.Equal("teamA", *workspace.Name)
assert.Equal("new comment", *workspace.Comment)
assert.Equal("#814CA6", workspace.Meta["color"])
err = client.Workspaces.Delete(defaultCtx, createdWorkspace.ID)
assert.Nil(err)
// ID can be specified
id := uuid.NewV4().String()
workspace = &Workspace{
Name: String("teamB"),
ID: String(id),
}
createdWorkspace, err = client.Workspaces.Create(defaultCtx, workspace)
assert.Nil(err)
assert.NotNil(createdWorkspace)
assert.Equal(id, *createdWorkspace.ID)
err = client.Workspaces.Delete(defaultCtx, createdWorkspace.ID)
assert.Nil(err)
}
func TestWorkspaceServiceList(T *testing.T) {
assert := assert.New(T)
client, err := NewTestClient(nil, nil)
assert.Nil(err)
assert.NotNil(client)
workspaceA := &Workspace{
Name: String("teamA"),
}
workspaceB := &Workspace{
Name: String("teamB"),
}
createdWorkspaceA, err := client.Workspaces.Create(defaultCtx, workspaceA)
assert.Nil(err)
createdWorkspaceB, err := client.Workspaces.Create(defaultCtx, workspaceB)
assert.Nil(err)
// paged List
page1, next, err := client.Workspaces.List(defaultCtx, &ListOpt{Size: 1})
assert.Nil(err)
assert.NotNil(next)
assert.NotNil(page1)
assert.Equal(1, len(page1))
// nil ListOpt List
workspaces, next, err := client.Workspaces.List(defaultCtx, nil)
assert.Nil(err)
assert.Nil(next)
assert.NotNil(workspaces)
// Counts default workspace
assert.Equal(3, len(workspaces))
err = client.Workspaces.Delete(defaultCtx, createdWorkspaceA.ID)
assert.Nil(err)
err = client.Workspaces.Delete(defaultCtx, createdWorkspaceB.ID)
assert.Nil(err)
}
func TestWorkspaceServiceListAll(T *testing.T) {
assert := assert.New(T)
client, err := NewTestClient(nil, nil)
assert.Nil(err)
assert.NotNil(client)
workspaceA := &Workspace{
Name: String("teamA"),
}
workspaceB := &Workspace{
Name: String("teamB"),
}
createdWorkspaceA, err := client.Workspaces.Create(defaultCtx, workspaceA)
assert.Nil(err)
createdWorkspaceB, err := client.Workspaces.Create(defaultCtx, workspaceB)
assert.Nil(err)
workspaces, err := client.Workspaces.ListAll(defaultCtx)
assert.Nil(err)
assert.NotNil(workspaces)
// Counts default workspace
assert.Equal(3, len(workspaces))
err = client.Workspaces.Delete(defaultCtx, createdWorkspaceA.ID)
assert.Nil(err)
err = client.Workspaces.Delete(defaultCtx, createdWorkspaceB.ID)
assert.Nil(err)
}