-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage_test.go
99 lines (78 loc) · 2.42 KB
/
storage_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
package instellar
import (
"fmt"
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
)
const storageJSON = `
{
"data": {
"attributes": {
"id": 1,
"current_state": "%s",
"host": "%s",
"bucket": "instellar",
"region": "us-east-1",
"credential_access_key_id": "somekey",
"credential_secret_access_key": "somesecret"
},
"id": "1",
"links": {
"self": "http://localhost:4000/provision/storages/1"
},
"relationships": {},
"type": "storage"
},
"included": [],
"links": {
"self": "http://localhost:4000/provision/storages/1"
}
}
`
func TestGetStorage(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("GET", "/provision/storages/1",
httpmock.NewStringResponder(200, fmt.Sprintf(storageJSON, "healthy", "s3.amazonaws.com")))
storage, _ := client.GetStorage("1")
assert.Equal(t, storage.Data.Attributes.ID, 1)
assert.Equal(t, storage.Data.Attributes.Host, "s3.amazonaws.com")
}
func TestCreateStorage(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("POST", "/provision/storages",
httpmock.NewStringResponder(201, fmt.Sprintf(storageJSON, "syncing", "s3.amazonaws.com")))
var storageParams = StorageParams{
Host: "s3.amazonaws.com",
Bucket: "instellar",
Region: "us-east-1",
CredentialAccessKeyID: "something",
CredentialSecretAccessKey: "secret",
InsterraComponentID: 1,
}
storage, _ := client.CreateStorage(storageParams)
assert.Equal(t, storage.Data.Attributes.Host, "s3.amazonaws.com")
assert.Equal(t, storage.Data.Attributes.Bucket, "instellar")
assert.Equal(t, storage.Data.Attributes.Region, "us-east-1")
}
func TestUpdateStorage(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("PATCH", "/provision/storages/1",
httpmock.NewStringResponder(200, fmt.Sprintf(storageJSON, "syncing", "object.linode.com")))
var storageParams = StorageParams{
Host: "object.linode.com",
}
storage, _ := client.UpdateStorage("1", storageParams)
assert.Equal(t, storage.Data.Attributes.Host, "object.linode.com")
}
func TestDeleteStorage(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("DELETE", "/provision/storages/1",
httpmock.NewStringResponder(200, fmt.Sprintf(nodeJSON, "deleted", "object.linode.com")))
storage, _ := client.DeleteStorage("1")
assert.Equal(t, storage.Data.Attributes.CurrentState, "deleted")
}