-
Notifications
You must be signed in to change notification settings - Fork 2
/
available_extension_test.go
134 lines (113 loc) · 3.45 KB
/
available_extension_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
126
127
128
129
130
131
132
133
134
package dbaas
import (
"context"
"fmt"
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const availableExtensionID = "20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4"
const testAvailableExtensionNotFoundResponse = `{
"error": {
"code": 404,
"title": "Not Found",
"message": "availableextension %s not found."
}
}`
const testAvailableExtensionsResponse = `{
"available-extensions": [
{
"id": "20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4",
"name": "xml2",
"datastore_type_ids": [
"20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4",
"20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f5"
],
"dependency_ids": []
},
{
"id": "20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f5",
"name": "prefix",
"datastore_type_ids": [
"20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4",
"20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f5"
],
"dependency_ids": []
}
]
}`
const testAvailableExtensionResponse = `{
"available-extension": {
"id": "20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4",
"name": "xml2",
"datastore_type_ids": [
"20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4",
"20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f5"
],
"dependency_ids": []
}
}`
func TestAvailableExtensions(t *testing.T) {
httpmock.Activate()
testClient := SetupTestClient()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", testClient.Endpoint+AvailableExtensionsURI,
httpmock.NewStringResponder(200, testAvailableExtensionsResponse))
expected := []AvailableExtension{
{
ID: "20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4",
Name: "xml2",
DatastoreTypeIDs: []string{
"20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4",
"20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f5",
},
DependencyIDs: []string{},
},
{
ID: "20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f5",
Name: "prefix",
DatastoreTypeIDs: []string{
"20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4",
"20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f5",
},
DependencyIDs: []string{},
},
}
actual, err := testClient.AvailableExtensions(context.Background())
require.NoError(t, err)
assert.Equal(t, expected, actual)
}
func TestAvailableExtension(t *testing.T) {
httpmock.Activate()
testClient := SetupTestClient()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", testClient.Endpoint+AvailableExtensionsURI+"/"+datastoreTypeID,
httpmock.NewStringResponder(200, testAvailableExtensionResponse))
expected := AvailableExtension{
ID: "20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4",
Name: "xml2",
DatastoreTypeIDs: []string{
"20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4",
"20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f5",
},
DependencyIDs: []string{},
}
actual, err := testClient.AvailableExtension(context.Background(), availableExtensionID)
require.NoError(t, err)
assert.Equal(t, expected, actual)
}
func TestAvailableExtensionNotFound(t *testing.T) {
httpmock.Activate()
testClient := SetupTestClient()
defer httpmock.DeactivateAndReset()
notFoundResponse := fmt.Sprintf(testAvailableExtensionNotFoundResponse, NotFoundEntityID)
httpmock.RegisterResponder("GET", testClient.Endpoint+AvailableExtensionsURI+"/"+NotFoundEntityID,
httpmock.NewStringResponder(404, notFoundResponse))
expected := &DBaaSAPIError{}
expected.APIError.Code = 404
expected.APIError.Title = ErrorNotFoundTitle
expected.APIError.Message = fmt.Sprintf("availableextension %s not found.", NotFoundEntityID)
_, err := testClient.AvailableExtension(context.Background(), NotFoundEntityID)
require.ErrorAs(t, err, &expected)
}