-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathavailability_zones_test.go
More file actions
74 lines (61 loc) · 1.86 KB
/
availability_zones_test.go
File metadata and controls
74 lines (61 loc) · 1.86 KB
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
package edgecloud
import (
"encoding/json"
"fmt"
"net/http"
"path"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAvailabilityZonesServiceOp_List(t *testing.T) {
setup()
defer teardown()
client.Project = 0
URL := path.Join(AvailabilityZoneBasePath, strconv.Itoa(regionID))
expResp := AvailabilityZonesList{
RegionID: regionID,
AvailabilityZones: []string{"availability-zone-1", "availability-zone-2"},
}
mux.HandleFunc(URL, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
resp, err := json.Marshal(expResp)
if err != nil {
t.Errorf("failed to marshal response: %v", err)
}
_, err = w.Write(resp)
if err != nil {
t.Errorf("failed to write response: %v", err)
}
})
respActual, resp, err := client.AvailabilityZones.List(ctx)
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
require.Equal(t, expResp, *respActual)
}
func TestAvailabilityZonesServiceOp_List_NotFoundError(t *testing.T) {
setup()
defer teardown()
URL := path.Join(AvailabilityZoneBasePath, strconv.Itoa(regionID))
mux.HandleFunc(URL, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
w.WriteHeader(http.StatusNotFound)
_, _ = fmt.Fprint(w, "Region not found")
})
respActual, resp, err := client.AvailabilityZones.List(ctx)
assert.Nil(t, respActual)
assert.Error(t, err)
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
}
func TestAvailabilityZonesServiceOp_List_ClientWithoutRegion(t *testing.T) {
setup()
defer teardown()
client.Region = 0
expectedError := NewArgError("Client.Region", "is not set")
respActual, resp, err := client.AvailabilityZones.List(ctx)
assert.Nil(t, respActual)
assert.Error(t, err)
assert.Equal(t, err, expectedError)
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
}