opentofu/vendor/github.com/digitalocean/godo/regions_test.go
Paul Hinze 6fe2703665 Vendor all dependencies w/ Godep
* Remove `make updatedeps` from Travis build. We'll follow up with more
   specific plans around dependency updating in subsequent PRs.
 * Update all `make` targets to set `GO15VENDOREXPERIMENT=1` and to
   filter out `/vendor/` from `./...` where appropriate.
 * Temporarily remove `vet` from the `make test` target until we can
   figure out how to get it to not vet `vendor/`. (Initial
   experimentation failed to yield the proper incantation.)

Everything is pinned to current master, with the exception of:

 * Azure/azure-sdk-for-go which is pinned before the breaking change today
 * aws/aws-sdk-go which is pinned to the most recent tag

The documentation still needs to be updated, which we can do in a follow
up PR. The goal here is to unblock release.
2016-01-29 15:08:48 -06:00

92 lines
2.0 KiB
Go

package godo
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestRegions_List(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/regions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"regions":[{"slug":"1"},{"slug":"2"}]}`)
})
regions, _, err := client.Regions.List(nil)
if err != nil {
t.Errorf("Regions.List returned error: %v", err)
}
expected := []Region{{Slug: "1"}, {Slug: "2"}}
if !reflect.DeepEqual(regions, expected) {
t.Errorf("Regions.List returned %+v, expected %+v", regions, expected)
}
}
func TestRegions_ListRegionsMultiplePages(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/regions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"regions": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/regions/?page=2"}}}`)
})
_, resp, err := client.Regions.List(nil)
if err != nil {
t.Fatal(err)
}
checkCurrentPage(t, resp, 1)
}
func TestRegions_RetrievePageByNumber(t *testing.T) {
setup()
defer teardown()
jBlob := `
{
"regions": [{"id":1},{"id":2}],
"links":{
"pages":{
"next":"http://example.com/v2/regions/?page=3",
"prev":"http://example.com/v2/regions/?page=1",
"last":"http://example.com/v2/regions/?page=3",
"first":"http://example.com/v2/regions/?page=1"
}
}
}`
mux.HandleFunc("/v2/regions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, jBlob)
})
opt := &ListOptions{Page: 2}
_, resp, err := client.Regions.List(opt)
if err != nil {
t.Fatal(err)
}
checkCurrentPage(t, resp, 2)
}
func TestRegion_String(t *testing.T) {
region := &Region{
Slug: "region",
Name: "Region",
Sizes: []string{"1", "2"},
Available: true,
}
stringified := region.String()
expected := `godo.Region{Slug:"region", Name:"Region", Sizes:["1" "2"], Available:true}`
if expected != stringified {
t.Errorf("Region.String returned %+v, expected %+v", stringified, expected)
}
}