github.com/gophercloud/gophercloud@v1.11.0/openstack/dns/v2/zones/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/gophercloud/gophercloud/openstack/dns/v2/zones"
     7  	"github.com/gophercloud/gophercloud/pagination"
     8  	th "github.com/gophercloud/gophercloud/testhelper"
     9  	"github.com/gophercloud/gophercloud/testhelper/client"
    10  )
    11  
    12  func TestList(t *testing.T) {
    13  	th.SetupHTTP()
    14  	defer th.TeardownHTTP()
    15  	HandleListSuccessfully(t)
    16  
    17  	count := 0
    18  	err := zones.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
    19  		count++
    20  		actual, err := zones.ExtractZones(page)
    21  		th.AssertNoErr(t, err)
    22  		th.CheckDeepEquals(t, ExpectedZonesSlice, actual)
    23  
    24  		return true, nil
    25  	})
    26  	th.AssertNoErr(t, err)
    27  	th.CheckEquals(t, 1, count)
    28  }
    29  
    30  func TestListAllPages(t *testing.T) {
    31  	th.SetupHTTP()
    32  	defer th.TeardownHTTP()
    33  	HandleListSuccessfully(t)
    34  
    35  	allPages, err := zones.List(client.ServiceClient(), nil).AllPages()
    36  	th.AssertNoErr(t, err)
    37  	allZones, err := zones.ExtractZones(allPages)
    38  	th.AssertNoErr(t, err)
    39  	th.CheckEquals(t, 2, len(allZones))
    40  }
    41  
    42  func TestGet(t *testing.T) {
    43  	th.SetupHTTP()
    44  	defer th.TeardownHTTP()
    45  	HandleGetSuccessfully(t)
    46  
    47  	actual, err := zones.Get(client.ServiceClient(), "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3").Extract()
    48  	th.AssertNoErr(t, err)
    49  	th.CheckDeepEquals(t, &FirstZone, actual)
    50  }
    51  
    52  func TestCreate(t *testing.T) {
    53  	th.SetupHTTP()
    54  	defer th.TeardownHTTP()
    55  	HandleCreateSuccessfully(t)
    56  
    57  	createOpts := zones.CreateOpts{
    58  		Name:        "example.org.",
    59  		Email:       "joe@example.org",
    60  		Type:        "PRIMARY",
    61  		TTL:         7200,
    62  		Description: "This is an example zone.",
    63  	}
    64  
    65  	actual, err := zones.Create(client.ServiceClient(), createOpts).Extract()
    66  	th.AssertNoErr(t, err)
    67  	th.CheckDeepEquals(t, &CreatedZone, actual)
    68  }
    69  
    70  func TestUpdate(t *testing.T) {
    71  	th.SetupHTTP()
    72  	defer th.TeardownHTTP()
    73  	HandleUpdateSuccessfully(t)
    74  
    75  	var description = "Updated Description"
    76  	updateOpts := zones.UpdateOpts{
    77  		TTL:         600,
    78  		Description: &description,
    79  	}
    80  
    81  	UpdatedZone := CreatedZone
    82  	UpdatedZone.Status = "PENDING"
    83  	UpdatedZone.Action = "UPDATE"
    84  	UpdatedZone.TTL = 600
    85  	UpdatedZone.Description = "Updated Description"
    86  
    87  	actual, err := zones.Update(client.ServiceClient(), UpdatedZone.ID, updateOpts).Extract()
    88  	th.AssertNoErr(t, err)
    89  	th.CheckDeepEquals(t, &UpdatedZone, actual)
    90  }
    91  
    92  func TestDelete(t *testing.T) {
    93  	th.SetupHTTP()
    94  	defer th.TeardownHTTP()
    95  	HandleDeleteSuccessfully(t)
    96  
    97  	DeletedZone := CreatedZone
    98  	DeletedZone.Status = "PENDING"
    99  	DeletedZone.Action = "DELETE"
   100  	DeletedZone.TTL = 600
   101  	DeletedZone.Description = "Updated Description"
   102  
   103  	actual, err := zones.Delete(client.ServiceClient(), DeletedZone.ID).Extract()
   104  	th.AssertNoErr(t, err)
   105  	th.CheckDeepEquals(t, &DeletedZone, actual)
   106  }