github.com/gophercloud/gophercloud@v1.11.0/openstack/blockstorage/apiversions/testing/requests_test.go (about)

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