-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregion_test.go
44 lines (33 loc) · 928 Bytes
/
region_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
package symbiosis
import (
"encoding/json"
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
)
const regionJSON = `
[
{
"id": "xxxxxxx-3557-48e6-a7f5-984251295303",
"name": "germany-1"
}
]
`
func TestListRegions(t *testing.T) {
c := getMocketClient()
defer httpmock.DeactivateAndReset()
fakeURL := "/rest/v1/region"
var fakeRegions []Region
json.Unmarshal([]byte(regionJSON), &fakeRegions)
responder := httpmock.NewStringResponder(200, regionJSON)
httpmock.RegisterResponder("GET", fakeURL, responder)
regions, err := c.Region.List()
assert.Nil(t, err)
assert.Equal(t, fakeRegions, regions)
assert.Equal(t, regions[0].Name, "germany-1")
assert.Equal(t, regions[0].ID, "xxxxxxx-3557-48e6-a7f5-984251295303")
responder = httpmock.NewErrorResponder(assert.AnError)
httpmock.RegisterResponder("GET", fakeURL, responder)
_, err = c.Region.List()
assert.Error(t, err)
}