-
Notifications
You must be signed in to change notification settings - Fork 3
/
osImageVersions_test.go
72 lines (59 loc) · 1.97 KB
/
osImageVersions_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
package solus
import (
"context"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestOsImageVersionsService_Get(t *testing.T) {
t.Run("positive", func(t *testing.T) {
versions := map[string]OsImageVersion{
"kvm": fakeKvmOsImageVersion,
"vz": fakeVzOsImageVersion,
}
for name, version := range versions {
t.Run(name, func(t *testing.T) {
s := startTestServer(t, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/os_image_versions/10", r.URL.Path)
assert.Equal(t, http.MethodGet, r.Method)
writeResponse(t, w, http.StatusOK, version)
})
defer s.Close()
actual, err := createTestClient(t, s.URL).OsImageVersions.Get(context.Background(), 10)
require.NoError(t, err)
require.Equal(t, version, actual)
})
}
})
}
func TestOsImageVersionsService_Update(t *testing.T) {
data := OsImageVersionRequest{
Position: 1.5,
Version: "version",
VirtualizationType: VirtualizationTypeKVM,
URL: "http://foo/bar",
CloudInitVersion: CloudInitVersionV0,
IsVisible: true,
}
s := startTestServer(t, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/os_image_versions/10", r.URL.Path)
assert.Equal(t, http.MethodPut, r.Method)
assertRequestBody(t, r, data)
writeResponse(t, w, http.StatusOK, fakeKvmOsImageVersion)
})
defer s.Close()
actual, err := createTestClient(t, s.URL).OsImageVersions.Update(context.Background(), 10, data)
require.NoError(t, err)
require.Equal(t, fakeKvmOsImageVersion, actual)
}
func TestOsImageVersionsService_Delete(t *testing.T) {
s := startTestServer(t, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/os_image_versions/10", r.URL.Path)
assert.Equal(t, http.MethodDelete, r.Method)
w.WriteHeader(http.StatusNoContent)
})
defer s.Close()
err := createTestClient(t, s.URL).OsImageVersions.Delete(context.Background(), 10)
require.NoError(t, err)
}