-
Notifications
You must be signed in to change notification settings - Fork 2
/
floating_ips_test.go
76 lines (56 loc) · 1.8 KB
/
floating_ips_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
package dbaas
import (
"context"
"fmt"
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/require"
)
const testInstanceNotFoundResponse = `{
"error": {
"code": 404,
"title": "Not Found",
"message": "instance %s not found."
}
}`
const instanceID = "7d959e48-4d42-41cd-8515-aae0a8482d8d"
func TestCreateFloatingIP(t *testing.T) {
httpmock.Activate()
testClient := SetupTestClient()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("POST", testClient.Endpoint+FloatingIPsURI,
httpmock.NewStringResponder(200, ""))
createFloatingIPOpts := FloatingIPsOpts{
InstanceID: instanceID,
}
err := testClient.CreateFloatingIP(context.Background(), createFloatingIPOpts)
require.NoError(t, err)
}
func TestDeleteFloatingIP(t *testing.T) {
httpmock.Activate()
testClient := SetupTestClient()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("DELETE", testClient.Endpoint+FloatingIPsURI,
httpmock.NewStringResponder(200, ""))
deleteFloatingIPOpts := FloatingIPsOpts{
InstanceID: instanceID,
}
err := testClient.DeleteFloatingIP(context.Background(), deleteFloatingIPOpts)
require.NoError(t, err)
}
func TestCreateFloatingIPInstanceNotFound(t *testing.T) {
httpmock.Activate()
testClient := SetupTestClient()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("DELETE", testClient.Endpoint+FloatingIPsURI,
httpmock.NewStringResponder(404, testInstanceNotFoundResponse))
createFloatingIPOpts := FloatingIPsOpts{
InstanceID: instanceID,
}
expected := &DBaaSAPIError{}
expected.APIError.Code = 404
expected.APIError.Title = ErrorNotFoundTitle
expected.APIError.Message = fmt.Sprintf("instance %s not found.", instanceID)
err := testClient.DeleteFloatingIP(context.Background(), createFloatingIPOpts)
require.ErrorAs(t, err, &expected)
}