-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_image_test.go
125 lines (101 loc) · 3.72 KB
/
api_image_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
// +build !integration
package linode
import (
"testing"
"github.com/alexsacr/linode/_third_party/testify/assert"
"github.com/alexsacr/linode/_third_party/testify/require"
)
func mockImageListOK() []mockAPIResponse {
var output string
var params map[string]string
var responses []mockAPIResponse
output = `{"ERRORARRAY":[],"DATA":[{"LAST_USED_DT":"baz","MINSIZE":600,"DESCRIPTION":"foo","LABEL":"bar","CREATOR":"quux","STATUS":"available","ISPUBLIC":1,"CREATE_DT":"2015-07-07 23:55:59.0","TYPE":"manual","FS_TYPE":"ext4","IMAGEID":402716}],"ACTION":"image.list"}`
params = map[string]string{
"ImageID": `402716`,
"api_action": `image.list`,
"api_key": `foo`,
"pendingOnly": `0`,
}
responses = append(responses, newMockAPIResponse("image.list", params, output))
return responses
}
func TestImageListOK(t *testing.T) {
c, ts := clientFor(newMockAPIServer(t, mockImageListOK()))
defer ts.Close()
imgs, err := c.ImageList(Int(402716), Bool(false))
require.NoError(t, err)
require.Len(t, imgs, 1)
i := imgs[0]
assert.Equal(t, "baz", i.LastUsedDT)
assert.Equal(t, 600, i.MinSize)
assert.Equal(t, "foo", i.Description)
assert.Equal(t, "bar", i.Label)
assert.Equal(t, "quux", i.Creator)
assert.Equal(t, "available", i.Status)
assert.True(t, i.IsPublic)
assert.Equal(t, "2015-07-07 23:55:59.0", i.CreateDT)
assert.Equal(t, "manual", i.Type)
assert.Equal(t, "ext4", i.FSType)
assert.Equal(t, 402716, i.ID)
}
func mockImageListPendingOnlyOK() []mockAPIResponse {
var output string
var params map[string]string
var responses []mockAPIResponse
output = `{"ERRORARRAY":[],"DATA":[],"ACTION":"image.list"}`
params = map[string]string{
"ImageID": `402716`,
"api_action": `image.list`,
"api_key": `foo`,
"pendingOnly": `1`,
}
responses = append(responses, newMockAPIResponse("image.list", params, output))
return responses
}
func TestImageListPendingOnlyOK(t *testing.T) {
c, ts := clientFor(newMockAPIServer(t, mockImageListPendingOnlyOK()))
defer ts.Close()
imgs, err := c.ImageList(Int(402716), Bool(true))
require.NoError(t, err)
require.Len(t, imgs, 0)
}
func mockImageUpdateOK() []mockAPIResponse {
var output string
var params map[string]string
var responses []mockAPIResponse
output = `{"ERRORARRAY":[],"DATA":{"last_used_dt":"","minSize":600,"description":"quux","label":"baz","creator":"foo","status":"available","isPublic":0,"create_dt":"2015-07-07 23:55:59.0","type":"manual","fs_type":"ext4","imageID":402716},"ACTION":"image.update"}`
params = map[string]string{
"ImageID": `402716`,
"api_action": `image.update`,
"api_key": `foo`,
"description": `quux`,
"label": `baz`,
}
responses = append(responses, newMockAPIResponse("image.update", params, output))
return responses
}
func TestLinodeImageUpdateOK(t *testing.T) {
c, ts := clientFor(newMockAPIServer(t, mockImageUpdateOK()))
defer ts.Close()
err := c.ImageUpdate(402716, String("baz"), String("quux"))
require.NoError(t, err)
}
func mockImageDeleteOK() []mockAPIResponse {
var output string
var params map[string]string
var responses []mockAPIResponse
output = `{"ERRORARRAY":[],"DATA":{"last_used_dt":"","minSize":600,"description":"quux","label":"baz","creator":"foo","status":"deleted","isPublic":0,"create_dt":"2015-07-07 23:55:59.0","type":"manual","fs_type":"ext4","imageID":402716},"ACTION":"image.delete"}`
params = map[string]string{
"ImageID": `402716`,
"api_action": `image.delete`,
"api_key": `foo`,
}
responses = append(responses, newMockAPIResponse("image.delete", params, output))
return responses
}
func TestLinodeImageDeleteOK(t *testing.T) {
c, ts := clientFor(newMockAPIServer(t, mockImageDeleteOK()))
defer ts.Close()
err := c.ImageDelete(402716)
require.NoError(t, err)
}