github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/blockstorage/apiversions/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/blockstorage/apiversions"
     9  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    10  	"github.com/vnpaycloud-console/gophercloud/v2/testhelper/client"
    11  )
    12  
    13  func TestListVersions(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  
    17  	MockListResponse(t)
    18  
    19  	allVersions, err := apiversions.List(client.ServiceClient()).AllPages(context.TODO())
    20  	th.AssertNoErr(t, err)
    21  	actual, err := apiversions.ExtractAPIVersions(allVersions)
    22  	th.AssertNoErr(t, err)
    23  
    24  	expected := []apiversions.APIVersion{
    25  		{
    26  			ID:      "v1.0",
    27  			Status:  "DEPRECATED",
    28  			Updated: time.Date(2016, 5, 2, 20, 25, 19, 0, time.UTC),
    29  		},
    30  		{
    31  			ID:      "v2.0",
    32  			Status:  "SUPPORTED",
    33  			Updated: time.Date(2014, 6, 28, 12, 20, 21, 0, time.UTC),
    34  		},
    35  		{
    36  			ID:         "v3.0",
    37  			MinVersion: "3.0",
    38  			Status:     "CURRENT",
    39  			Updated:    time.Date(2016, 2, 8, 12, 20, 21, 0, time.UTC),
    40  			Version:    "3.27",
    41  		},
    42  	}
    43  
    44  	th.AssertDeepEquals(t, expected, actual)
    45  }
    46  
    47  func TestListOldVersions(t *testing.T) {
    48  	th.SetupHTTP()
    49  	defer th.TeardownHTTP()
    50  
    51  	MockListOldResponse(t)
    52  
    53  	allVersions, err := apiversions.List(client.ServiceClient()).AllPages(context.TODO())
    54  	th.AssertNoErr(t, err)
    55  	actual, err := apiversions.ExtractAPIVersions(allVersions)
    56  	th.AssertNoErr(t, err)
    57  
    58  	expected := []apiversions.APIVersion{
    59  		{
    60  			ID:      "v1.0",
    61  			Status:  "CURRENT",
    62  			Updated: time.Date(2012, 1, 4, 11, 33, 21, 0, time.UTC),
    63  		},
    64  		{
    65  			ID:      "v2.0",
    66  			Status:  "CURRENT",
    67  			Updated: time.Date(2012, 11, 21, 11, 33, 21, 0, time.UTC),
    68  		},
    69  	}
    70  
    71  	th.AssertDeepEquals(t, expected, actual)
    72  }
    73  
    74  func TestGetVersion(t *testing.T) {
    75  	th.SetupHTTP()
    76  	defer th.TeardownHTTP()
    77  
    78  	MockListResponse(t)
    79  
    80  	allVersions, err := apiversions.List(client.ServiceClient()).AllPages(context.TODO())
    81  	th.AssertNoErr(t, err)
    82  	actual, err := apiversions.ExtractAPIVersion(allVersions, "v3.0")
    83  	th.AssertNoErr(t, err)
    84  
    85  	expected := apiversions.APIVersion{
    86  		ID:         "v3.0",
    87  		MinVersion: "3.0",
    88  		Status:     "CURRENT",
    89  		Updated:    time.Date(2016, 2, 8, 12, 20, 21, 0, time.UTC),
    90  		Version:    "3.27",
    91  	}
    92  
    93  	th.AssertEquals(t, actual.ID, expected.ID)
    94  	th.AssertEquals(t, actual.Status, expected.Status)
    95  	th.AssertEquals(t, actual.Updated, expected.Updated)
    96  }
    97  
    98  func TestGetOldVersion(t *testing.T) {
    99  	th.SetupHTTP()
   100  	defer th.TeardownHTTP()
   101  
   102  	MockListOldResponse(t)
   103  
   104  	allVersions, err := apiversions.List(client.ServiceClient()).AllPages(context.TODO())
   105  	th.AssertNoErr(t, err)
   106  	actual, err := apiversions.ExtractAPIVersion(allVersions, "v2.0")
   107  	th.AssertNoErr(t, err)
   108  
   109  	expected := apiversions.APIVersion{
   110  		ID:         "v2.0",
   111  		MinVersion: "",
   112  		Status:     "CURRENT",
   113  		Updated:    time.Date(2012, 11, 21, 11, 33, 21, 0, time.UTC),
   114  		Version:    "",
   115  	}
   116  
   117  	th.AssertEquals(t, actual.ID, expected.ID)
   118  	th.AssertEquals(t, actual.Status, expected.Status)
   119  	th.AssertEquals(t, actual.Updated, expected.Updated)
   120  }