github.com/gophercloud/gophercloud@v1.11.0/openstack/baremetalintrospection/v1/introspection/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/gophercloud/gophercloud/openstack/baremetalintrospection/v1/introspection"
     7  	"github.com/gophercloud/gophercloud/pagination"
     8  	th "github.com/gophercloud/gophercloud/testhelper"
     9  	"github.com/gophercloud/gophercloud/testhelper/client"
    10  )
    11  
    12  func TestListIntrospections(t *testing.T) {
    13  	th.SetupHTTP()
    14  	defer th.TeardownHTTP()
    15  	HandleListIntrospectionsSuccessfully(t)
    16  
    17  	pages := 0
    18  	err := introspection.ListIntrospections(client.ServiceClient(), introspection.ListIntrospectionsOpts{}).EachPage(func(page pagination.Page) (bool, error) {
    19  		pages++
    20  
    21  		actual, err := introspection.ExtractIntrospections(page)
    22  		if err != nil {
    23  			return false, err
    24  		}
    25  
    26  		if len(actual) != 2 {
    27  			t.Fatalf("Expected 2 introspections, got %d", len(actual))
    28  		}
    29  		th.CheckDeepEquals(t, IntrospectionFoo, actual[0])
    30  		th.CheckDeepEquals(t, IntrospectionBar, actual[1])
    31  
    32  		return true, nil
    33  	})
    34  
    35  	th.AssertNoErr(t, err)
    36  
    37  	if pages != 1 {
    38  		t.Errorf("Expected 1 page, saw %d", pages)
    39  	}
    40  }
    41  
    42  func TestGetIntrospectionStatus(t *testing.T) {
    43  	th.SetupHTTP()
    44  	defer th.TeardownHTTP()
    45  	HandleGetIntrospectionStatusSuccessfully(t)
    46  
    47  	c := client.ServiceClient()
    48  	actual, err := introspection.GetIntrospectionStatus(c, "c244557e-899f-46fa-a1ff-5b2c6718616b").Extract()
    49  	if err != nil {
    50  		t.Fatalf("Unexpected Get error: %v", err)
    51  	}
    52  
    53  	th.CheckDeepEquals(t, IntrospectionBar, *actual)
    54  }
    55  
    56  func TestStartIntrospection(t *testing.T) {
    57  	th.SetupHTTP()
    58  	defer th.TeardownHTTP()
    59  	HandleStartIntrospectionSuccessfully(t)
    60  
    61  	c := client.ServiceClient()
    62  	err := introspection.StartIntrospection(c, "c244557e-899f-46fa-a1ff-5b2c6718616b", introspection.StartOpts{}).ExtractErr()
    63  	th.AssertNoErr(t, err)
    64  }
    65  
    66  func TestAbortIntrospection(t *testing.T) {
    67  	th.SetupHTTP()
    68  	defer th.TeardownHTTP()
    69  	HandleAbortIntrospectionSuccessfully(t)
    70  
    71  	c := client.ServiceClient()
    72  	err := introspection.AbortIntrospection(c, "c244557e-899f-46fa-a1ff-5b2c6718616b").ExtractErr()
    73  	th.AssertNoErr(t, err)
    74  }
    75  
    76  func TestGetIntrospectionData(t *testing.T) {
    77  	th.SetupHTTP()
    78  	defer th.TeardownHTTP()
    79  	HandleGetIntrospectionDataSuccessfully(t)
    80  
    81  	c := client.ServiceClient()
    82  	actual, err := introspection.GetIntrospectionData(c, "c244557e-899f-46fa-a1ff-5b2c6718616b").Extract()
    83  	if err != nil {
    84  		t.Fatalf("Unexpected Get error: %v", err)
    85  	}
    86  
    87  	th.CheckDeepEquals(t, IntrospectionDataRes, *actual)
    88  }
    89  
    90  func TestReApplyIntrospection(t *testing.T) {
    91  	th.SetupHTTP()
    92  	defer th.TeardownHTTP()
    93  	HandleReApplyIntrospectionSuccessfully(t)
    94  
    95  	c := client.ServiceClient()
    96  	err := introspection.ReApplyIntrospection(c, "c244557e-899f-46fa-a1ff-5b2c6718616b").ExtractErr()
    97  	th.AssertNoErr(t, err)
    98  }