github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/baremetal/v1/drivers/testing/requests_test.go (about)

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