github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/extensions/services/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/services"
     7  	"github.com/gophercloud/gophercloud/pagination"
     8  	"github.com/gophercloud/gophercloud/testhelper"
     9  	"github.com/gophercloud/gophercloud/testhelper/client"
    10  )
    11  
    12  func TestListServicesPre253(t *testing.T) {
    13  	testhelper.SetupHTTP()
    14  	defer testhelper.TeardownHTTP()
    15  	HandleListPre253Successfully(t)
    16  
    17  	pages := 0
    18  	err := services.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
    19  		pages++
    20  
    21  		actual, err := services.ExtractServices(page)
    22  		if err != nil {
    23  			return false, err
    24  		}
    25  
    26  		if len(actual) != 4 {
    27  			t.Fatalf("Expected 4 services, got %d", len(actual))
    28  		}
    29  		testhelper.CheckDeepEquals(t, FirstFakeServicePre253, actual[0])
    30  		testhelper.CheckDeepEquals(t, SecondFakeServicePre253, actual[1])
    31  		testhelper.CheckDeepEquals(t, ThirdFakeServicePre253, actual[2])
    32  		testhelper.CheckDeepEquals(t, FourthFakeServicePre253, actual[3])
    33  
    34  		return true, nil
    35  	})
    36  
    37  	testhelper.AssertNoErr(t, err)
    38  
    39  	if pages != 1 {
    40  		t.Errorf("Expected 1 page, saw %d", pages)
    41  	}
    42  }
    43  
    44  func TestListServices(t *testing.T) {
    45  	testhelper.SetupHTTP()
    46  	defer testhelper.TeardownHTTP()
    47  	HandleListSuccessfully(t)
    48  
    49  	pages := 0
    50  	opts := services.ListOpts{
    51  		Binary: "fake-binary",
    52  		Host:   "host123",
    53  	}
    54  	err := services.List(client.ServiceClient(), opts).EachPage(func(page pagination.Page) (bool, error) {
    55  		pages++
    56  
    57  		actual, err := services.ExtractServices(page)
    58  		if err != nil {
    59  			return false, err
    60  		}
    61  
    62  		if len(actual) != 4 {
    63  			t.Fatalf("Expected 4 services, got %d", len(actual))
    64  		}
    65  		testhelper.CheckDeepEquals(t, FirstFakeService, actual[0])
    66  		testhelper.CheckDeepEquals(t, SecondFakeService, actual[1])
    67  		testhelper.CheckDeepEquals(t, ThirdFakeService, actual[2])
    68  		testhelper.CheckDeepEquals(t, FourthFakeService, actual[3])
    69  
    70  		return true, nil
    71  	})
    72  
    73  	testhelper.AssertNoErr(t, err)
    74  
    75  	if pages != 1 {
    76  		t.Errorf("Expected 1 page, saw %d", pages)
    77  	}
    78  }
    79  
    80  func TestUpdateService(t *testing.T) {
    81  	testhelper.SetupHTTP()
    82  	defer testhelper.TeardownHTTP()
    83  	HandleUpdateSuccessfully(t)
    84  
    85  	client := client.ServiceClient()
    86  	actual, err := services.Update(client, "fake-service-id", services.UpdateOpts{Status: services.ServiceDisabled}).Extract()
    87  	if err != nil {
    88  		t.Fatalf("Unexpected Update error: %v", err)
    89  	}
    90  
    91  	testhelper.CheckDeepEquals(t, FakeServiceUpdateBody, *actual)
    92  }
    93  
    94  func TestDeleteService(t *testing.T) {
    95  	testhelper.SetupHTTP()
    96  	defer testhelper.TeardownHTTP()
    97  	HandleDeleteSuccessfully(t)
    98  
    99  	client := client.ServiceClient()
   100  	res := services.Delete(client, "fake-service-id")
   101  
   102  	testhelper.AssertNoErr(t, res.Err)
   103  }