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