-
Notifications
You must be signed in to change notification settings - Fork 2
/
datastore_type_test.go
110 lines (89 loc) · 2.61 KB
/
datastore_type_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
package dbaas
import (
"context"
"fmt"
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const datastoreTypeID = "20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4"
const testDatastoreTypeNotFoundResponse = `{
"error": {
"code": 404,
"title": "Not Found",
"message": "datastoretype %s not found."
}
}`
const testDatastoreTypesResponse = `{
"datastore-types": [
{
"id": "20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4",
"engine": "mysql",
"version": "8"
},
{
"id": "20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f5",
"engine": "postgresql",
"version": "12"
}
]
}`
const testDatastoreTypeResponse = `{
"datastore-type": {
"id": "20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4",
"engine": "mysql",
"version": "8"
}
}`
func TestDatastoreTypes(t *testing.T) {
httpmock.Activate()
testClient := SetupTestClient()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", testClient.Endpoint+DatastoreTypesURI,
httpmock.NewStringResponder(200, testDatastoreTypesResponse))
expected := []DatastoreType{
{
ID: "20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4",
Engine: "mysql",
Version: "8",
},
{
ID: "20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f5",
Engine: "postgresql",
Version: "12",
},
}
actual, err := testClient.DatastoreTypes(context.Background())
require.NoError(t, err)
assert.Equal(t, expected, actual)
}
func TestDatastoreType(t *testing.T) {
httpmock.Activate()
testClient := SetupTestClient()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", testClient.Endpoint+DatastoreTypesURI+"/"+datastoreTypeID,
httpmock.NewStringResponder(200, testDatastoreTypeResponse))
expected := DatastoreType{
ID: "20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4",
Engine: "mysql",
Version: "8",
}
actual, err := testClient.DatastoreType(context.Background(), datastoreTypeID)
require.NoError(t, err)
assert.Equal(t, expected, actual)
}
func TestDatastoreTypeNotFound(t *testing.T) {
httpmock.Activate()
testClient := SetupTestClient()
defer httpmock.DeactivateAndReset()
notFoundResponse := fmt.Sprintf(testDatastoreTypeNotFoundResponse, NotFoundEntityID)
httpmock.RegisterResponder("GET", testClient.Endpoint+DatastoreTypesURI+"/"+NotFoundEntityID,
httpmock.NewStringResponder(404, notFoundResponse))
expected := &DBaaSAPIError{}
expected.APIError.Code = 404
expected.APIError.Title = ErrorNotFoundTitle
expected.APIError.Message = fmt.Sprintf("datastoretype %s not found.", NotFoundEntityID)
_, err := testClient.DatastoreType(context.Background(), NotFoundEntityID)
require.ErrorAs(t, err, &expected)
}