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