github.com/gophercloud/gophercloud@v1.11.0/openstack/baremetal/v1/drivers/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/gophercloud/gophercloud/openstack/baremetal/v1/drivers" 7 "github.com/gophercloud/gophercloud/pagination" 8 th "github.com/gophercloud/gophercloud/testhelper" 9 "github.com/gophercloud/gophercloud/testhelper/client" 10 ) 11 12 func TestListDrivers(t *testing.T) { 13 th.SetupHTTP() 14 defer th.TeardownHTTP() 15 HandleListDriversSuccessfully(t) 16 17 pages := 0 18 err := drivers.ListDrivers(client.ServiceClient(), drivers.ListDriversOpts{}).EachPage(func(page pagination.Page) (bool, error) { 19 pages++ 20 21 actual, err := drivers.ExtractDrivers(page) 22 if err != nil { 23 return false, err 24 } 25 26 if len(actual) != 3 { 27 t.Fatalf("Expected 3 drivers, got %d", len(actual)) 28 } 29 30 th.CheckDeepEquals(t, DriverAgentIpmitool, actual[0]) 31 th.CheckDeepEquals(t, DriverFake, actual[1]) 32 th.AssertEquals(t, "ipmi", actual[2].Name) 33 34 return true, nil 35 }) 36 37 th.AssertNoErr(t, err) 38 39 if pages != 1 { 40 t.Errorf("Expected 1 page, saw %d", pages) 41 } 42 } 43 44 func TestGetDriverDetails(t *testing.T) { 45 th.SetupHTTP() 46 defer th.TeardownHTTP() 47 HandleGetDriverDetailsSuccessfully(t) 48 49 c := client.ServiceClient() 50 actual, err := drivers.GetDriverDetails(c, "ipmi").Extract() 51 if err != nil { 52 t.Fatalf("Unexpected Get error: %v", err) 53 } 54 55 th.CheckDeepEquals(t, DriverIpmi, *actual) 56 } 57 58 func TestGetDriverProperties(t *testing.T) { 59 th.SetupHTTP() 60 defer th.TeardownHTTP() 61 HandleGetDriverPropertiesSuccessfully(t) 62 63 c := client.ServiceClient() 64 actual, err := drivers.GetDriverProperties(c, "agent_ipmitool").Extract() 65 if err != nil { 66 t.Fatalf("Unexpected Get error: %v", err) 67 } 68 69 th.CheckDeepEquals(t, DriverIpmiToolProperties, *actual) 70 } 71 72 func TestGetDriverDiskProperties(t *testing.T) { 73 th.SetupHTTP() 74 defer th.TeardownHTTP() 75 HandleGetDriverDiskPropertiesSuccessfully(t) 76 77 c := client.ServiceClient() 78 actual, err := drivers.GetDriverDiskProperties(c, "agent_ipmitool").Extract() 79 if err != nil { 80 t.Fatalf("Unexpected Get error: %v", err) 81 } 82 83 th.CheckDeepEquals(t, DriverIpmiToolDisk, *actual) 84 }