github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/testing/delegate_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  
     6  	common "github.com/huaweicloud/golangsdk/openstack/common/extensions"
     7  	"github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions"
     8  	"github.com/huaweicloud/golangsdk/pagination"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	"github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  func TestList(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  
    17  	HandleListExtensionsSuccessfully(t)
    18  
    19  	count := 0
    20  	extensions.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
    21  		count++
    22  		actual, err := extensions.ExtractExtensions(page)
    23  		th.AssertNoErr(t, err)
    24  
    25  		expected := []common.Extension{
    26  			{
    27  				Updated:     "2013-01-20T00:00:00-00:00",
    28  				Name:        "Neutron Service Type Management",
    29  				Links:       []interface{}{},
    30  				Namespace:   "http://docs.openstack.org/ext/neutron/service-type/api/v1.0",
    31  				Alias:       "service-type",
    32  				Description: "API for retrieving service providers for Neutron advanced services",
    33  			},
    34  		}
    35  		th.AssertDeepEquals(t, expected, actual)
    36  
    37  		return true, nil
    38  	})
    39  	th.CheckEquals(t, 1, count)
    40  }
    41  
    42  func TestGet(t *testing.T) {
    43  	th.SetupHTTP()
    44  	defer th.TeardownHTTP()
    45  
    46  	HandleGetExtensionsSuccessfully(t)
    47  
    48  	ext, err := extensions.Get(client.ServiceClient(), "agent").Extract()
    49  	th.AssertNoErr(t, err)
    50  
    51  	th.AssertEquals(t, ext.Updated, "2013-02-03T10:00:00-00:00")
    52  	th.AssertEquals(t, ext.Name, "agent")
    53  	th.AssertEquals(t, ext.Namespace, "http://docs.openstack.org/ext/agent/api/v2.0")
    54  	th.AssertEquals(t, ext.Alias, "agent")
    55  	th.AssertEquals(t, ext.Description, "The agent management extension.")
    56  }