-
Notifications
You must be signed in to change notification settings - Fork 24
/
application_test.go
114 lines (104 loc) · 2.38 KB
/
application_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
package civogo
import (
"reflect"
"testing"
)
func TestListApplications(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/applications": `{"page":1,"per_page":20,"pages":1,"items":[{
"id": "69a23478-a89e-41d2-97b1-6f4c341cee70",
"name": "your-app-name",
"status": "ACTIVE",
"account_id": "12345",
"network_id": "34567",
"description": "this is a test app",
"process_info": [
{
"processType": "web",
"processCount": 1
}],
"domains": [
"your-app-name.example.com"
],
"ssh_key_ids": [
"12345"
],
"config": [
{
"name": "PORT",
"value": "80"
}]
}]}`,
})
defer server.Close()
got, err := client.ListApplications()
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
expected := &PaginatedApplications{
Page: 1,
PerPage: 20,
Pages: 1,
Items: []Application{
{
ID: "69a23478-a89e-41d2-97b1-6f4c341cee70",
Name: "your-app-name",
Status: "ACTIVE",
NetworkID: "34567",
Description: "this is a test app",
ProcessInfo: []ProcessInfo{
{
ProcessType: "web",
ProcessCount: 1,
},
},
Domains: []string{"your-app-name.example.com"},
SSHKeyIDs: []string{"12345"},
Config: []EnvVar{
{
Name: "PORT",
Value: "80",
},
},
},
},
}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Expected %+v, got %+v", expected, got)
}
}
func TestCreateApplication(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/applications": `{"name":"test-app"}`,
})
defer server.Close()
cfg := &ApplicationConfig{
Name: "test-app",
Description: "test app",
SSHKeyIDs: []string{"12345"},
Size: "small",
}
got, err := client.CreateApplication(cfg)
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
if got.Name != "test-app" {
t.Errorf("Expected %s, got %s", "test-app", got.Name)
}
}
func TestDeleteApplication(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/applications/12345": `{"result":"success"}`,
})
defer server.Close()
got, err := client.DeleteApplication("12345")
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
if got.Result != "success" {
t.Errorf("Expected %s, got %s", "success", got.Result)
}
}