github.com/1and1/oneandone-cloudserver-sdk-go@v1.4.1/serverappliances_test.go (about) 1 package oneandone 2 3 import ( 4 "fmt" 5 "strings" 6 "testing" 7 ) 8 9 // /server_appliances tests 10 11 func TestListServerAppliances(t *testing.T) { 12 fmt.Println("Listing all server appliances...") 13 14 res, err := api.ListServerAppliances() 15 if err != nil { 16 t.Errorf("ListServerAppliances failed. Error: " + err.Error()) 17 } 18 if len(res) == 0 { 19 t.Errorf("No server appliance found.") 20 } 21 22 res, err = api.ListServerAppliances(1, 7, "name", "", "id,name,os_family") 23 24 if err != nil { 25 t.Errorf("ListServerAppliances with parameter options failed. Error: " + err.Error()) 26 } 27 if len(res) == 0 { 28 t.Errorf("No server appliance found.") 29 } 30 if len(res) != 7 { 31 t.Errorf("Wrong number of objects per page.") 32 } 33 for index := 0; index < len(res); index += 1 { 34 if res[index].Id == "" { 35 t.Errorf("Filtering a list of server appliances failed.") 36 } 37 if res[index].Name == "" { 38 t.Errorf("Filtering a list of server appliances failed.") 39 } 40 if res[index].Type != "" { 41 t.Errorf("Filtering parameters failed.") 42 } 43 if index < len(res)-1 { 44 if res[index].Name > res[index+1].Name { 45 t.Errorf("Sorting a list of server appliances failed.") 46 } 47 } 48 } 49 // Test for error response 50 res, err = api.ListServerAppliances(nil, nil, nil, nil, nil) 51 if res != nil || err == nil { 52 t.Errorf("ListServerAppliances failed to handle incorrect argument type.") 53 } 54 55 res, err = api.ListServerAppliances(0, 0, "", "linux", "") 56 57 if err != nil { 58 t.Errorf("ListServerAppliances with parameter options failed. Error: " + err.Error()) 59 } 60 61 for _, sa := range res { 62 if !strings.Contains(strings.ToLower(sa.OsFamily), "linux") { 63 t.Errorf("Search parameter failed.") 64 } 65 } 66 } 67 68 func TestGetServerAppliance(t *testing.T) { 69 saps, _ := api.ListServerAppliances(1, 1, "", "", "") 70 fmt.Printf("Getting server appliance '%s'...\n", saps[0].Name) 71 sa, err := api.GetServerAppliance(saps[0].Id) 72 73 if sa == nil || err != nil { 74 t.Errorf("GetServerAppliance failed. Error: " + err.Error()) 75 } 76 if sa.Id != saps[0].Id { 77 t.Errorf("Wrong ID of the server appliance.") 78 } 79 }