github.com/1and1/oneandone-cloudserver-sdk-go@v1.4.1/datacenters_test.go (about) 1 package oneandone 2 3 import ( 4 "fmt" 5 "testing" 6 "time" 7 ) 8 9 // /datacenters tests 10 11 func TestListDatacenters(t *testing.T) { 12 fmt.Println("Listing datacenters...") 13 14 res, err := api.ListDatacenters() 15 if err != nil { 16 t.Errorf("ListDatacenters failed. Error: " + err.Error()) 17 } 18 if len(res) == 0 { 19 t.Errorf("No datacenter found.") 20 } 21 22 res, err = api.ListDatacenters(1, 2, "location", "", "id,location") 23 24 if err != nil { 25 t.Errorf("ListDatacenters with parameter options failed. Error: " + err.Error()) 26 } 27 if len(res) == 0 { 28 t.Errorf("No datacenter found.") 29 } 30 31 // Test for error response 32 res, err = api.ListDatacenters(0, 0, "location", "Spain", "id", "country_code") 33 if res != nil || err == nil { 34 t.Errorf("ListDatacenters failed to handle incorrect number of passed arguments.") 35 } 36 37 res, err = api.ListDatacenters(0, 0, "", "Germany", "") 38 39 if err != nil { 40 t.Errorf("ListDatacenters with parameter options failed. Error: " + err.Error()) 41 } 42 } 43 44 func TestGetDatacenter(t *testing.T) { 45 dcs, err := api.ListDatacenters() 46 47 if len(dcs) == 0 { 48 t.Errorf("No datacenter found. " + err.Error()) 49 return 50 } 51 52 for i, _ := range dcs { 53 time.Sleep(time.Second) 54 fmt.Printf("Getting datacenter '%s'...\n", dcs[i].CountryCode) 55 dc, err := api.GetDatacenter(dcs[i].Id) 56 57 if err != nil { 58 t.Errorf("GetDatacenter failed. Error: " + err.Error()) 59 return 60 } 61 if dc.Id != dcs[i].Id { 62 t.Errorf("Wrong datacenter ID.") 63 } 64 if dc.CountryCode != dcs[i].CountryCode { 65 t.Errorf("Wrong country code of the datacenter.") 66 } 67 if dc.Location != dcs[i].Location { 68 t.Errorf("Wrong datacenter location.") 69 } 70 } 71 }