-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathinstances_test.go
111 lines (97 loc) · 3.16 KB
/
instances_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
package linodego_test
import (
"context"
"testing"
"github.com/chiefy/linodego"
)
func TestListInstances(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
client, teardown := createTestClient(t, "fixtures/TestListInstances")
defer teardown()
linodes, err := client.ListInstances(context.Background(), nil)
if err != nil {
t.Errorf("Error listing instances, expected struct, got error %v", err)
}
if len(linodes) == 0 {
t.Errorf("Expected a list of instances, but got %v", linodes)
}
}
func TestGetInstance(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
client, teardown := createTestClient(t, "fixtures/TestGetInstance")
defer teardown()
instance, err := client.GetInstance(context.Background(), TestInstanceID)
if err != nil {
t.Errorf("Error getting instance TestInstanceID, expected *LinodeInstance, got error %v", err)
}
if instance.Specs.Disk <= 0 {
t.Errorf("Error in instance TestInstanceID spec for disk size, %v", instance.Specs)
}
}
func TestListInstanceDisks(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
client, teardown := createTestClient(t, "fixtures/TestListInstanceDisks")
defer teardown()
disks, err := client.ListInstanceDisks(context.Background(), TestInstanceID, nil)
if err != nil {
t.Errorf("Error listing instance disks, expected struct, got error %v", err)
}
if len(disks) == 0 {
t.Errorf("Expected a list of instance disks, but got %v", disks)
}
}
func TestListInstanceConfigs(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
client, teardown := createTestClient(t, "fixtures/TestListInstanceConfigs")
defer teardown()
configs, err := client.ListInstanceConfigs(context.Background(), TestInstanceID, nil)
if err != nil {
t.Errorf("Error listing instance configs, expected struct, got error %v", err)
}
if len(configs) == 0 {
t.Errorf("Expected a list of instance configs, but got %v", configs)
}
}
func TestListInstanceVolumes(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
client, teardown := createTestClient(t, "fixtures/TestListInstanceVolumes")
defer teardown()
volumes, err := client.ListInstanceVolumes(context.Background(), TestInstanceID, nil)
if err != nil {
t.Errorf("Error listing instance volumes, expected struct, got error %v", err)
}
if len(volumes) == 0 {
t.Errorf("Expected an list of instance volumes, but got %v", volumes)
}
}
func setupInstance(t *testing.T, fixturesYaml string) (*linodego.Client, *linodego.Instance, func(), error) {
t.Helper()
client, fixtureTeardown := createTestClient(t, fixturesYaml)
createOpts := linodego.InstanceCreateOptions{
Label: "linodego-test-instance",
RootPass: "R34lBAdP455",
Region: "us-west",
Type: "g6-nanode-1",
}
instance, err := client.CreateInstance(context.Background(), &createOpts)
if err != nil {
t.Errorf("Error creating test Instance: %s", err)
}
teardown := func() {
if err := client.DeleteInstance(context.Background(), instance.ID); err != nil {
t.Errorf("Error deleting test Instance: %s", err)
}
fixtureTeardown()
}
return client, instance, teardown, err
}