github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/sharedfilesystems/v2/snapshots/testing/request_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/sharedfilesystems/v2/snapshots"
     9  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    10  	"github.com/vnpaycloud-console/gophercloud/v2/testhelper/client"
    11  )
    12  
    13  func TestCreate(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  
    17  	MockCreateResponse(t)
    18  
    19  	options := &snapshots.CreateOpts{ShareID: shareID, Name: "test snapshot", Description: "test description"}
    20  	n, err := snapshots.Create(context.TODO(), client.ServiceClient(), options).Extract()
    21  
    22  	th.AssertNoErr(t, err)
    23  	th.AssertEquals(t, n.Name, "test snapshot")
    24  	th.AssertEquals(t, n.Description, "test description")
    25  	th.AssertEquals(t, n.ShareProto, "NFS")
    26  	th.AssertEquals(t, n.ShareSize, 1)
    27  	th.AssertEquals(t, n.Size, 1)
    28  }
    29  
    30  func TestUpdate(t *testing.T) {
    31  	th.SetupHTTP()
    32  	defer th.TeardownHTTP()
    33  
    34  	MockUpdateResponse(t)
    35  
    36  	name := "my_new_test_snapshot"
    37  	description := ""
    38  	options := &snapshots.UpdateOpts{
    39  		DisplayName:        &name,
    40  		DisplayDescription: &description,
    41  	}
    42  	n, err := snapshots.Update(context.TODO(), client.ServiceClient(), snapshotID, options).Extract()
    43  
    44  	th.AssertNoErr(t, err)
    45  	th.AssertEquals(t, n.Name, "my_new_test_snapshot")
    46  	th.AssertEquals(t, n.Description, "")
    47  }
    48  
    49  func TestDelete(t *testing.T) {
    50  	th.SetupHTTP()
    51  	defer th.TeardownHTTP()
    52  
    53  	MockDeleteResponse(t)
    54  
    55  	result := snapshots.Delete(context.TODO(), client.ServiceClient(), snapshotID)
    56  	th.AssertNoErr(t, result.Err)
    57  }
    58  
    59  func TestGet(t *testing.T) {
    60  	th.SetupHTTP()
    61  	defer th.TeardownHTTP()
    62  
    63  	MockGetResponse(t)
    64  
    65  	s, err := snapshots.Get(context.TODO(), client.ServiceClient(), snapshotID).Extract()
    66  	th.AssertNoErr(t, err)
    67  	th.AssertDeepEquals(t, s, &snapshots.Snapshot{
    68  		ID:          snapshotID,
    69  		Name:        "new_app_snapshot",
    70  		Description: "",
    71  		ShareID:     "19865c43-3b91-48c9-85a0-7ac4d6bb0efe",
    72  		ShareProto:  "NFS",
    73  		ShareSize:   1,
    74  		Size:        1,
    75  		Status:      "available",
    76  		ProjectID:   "16e1ab15c35a457e9c2b2aa189f544e1",
    77  		CreatedAt:   time.Date(2019, time.January, 06, 11, 11, 02, 0, time.UTC),
    78  		Links: []map[string]string{
    79  			{
    80  				"href": "http://172.18.198.54:8786/v2/16e1ab15c35a457e9c2b2aa189f544e1/snapshots/bc082e99-3bdb-4400-b95e-b85c7a41622c",
    81  				"rel":  "self",
    82  			},
    83  			{
    84  				"href": "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/snapshots/bc082e99-3bdb-4400-b95e-b85c7a41622c",
    85  				"rel":  "bookmark",
    86  			},
    87  		},
    88  	})
    89  }
    90  
    91  func TestListDetail(t *testing.T) {
    92  	th.SetupHTTP()
    93  	defer th.TeardownHTTP()
    94  
    95  	MockListDetailResponse(t)
    96  
    97  	allPages, err := snapshots.ListDetail(client.ServiceClient(), &snapshots.ListOpts{}).AllPages(context.TODO())
    98  
    99  	th.AssertNoErr(t, err)
   100  
   101  	actual, err := snapshots.ExtractSnapshots(allPages)
   102  	th.AssertNoErr(t, err)
   103  
   104  	th.AssertDeepEquals(t, actual, []snapshots.Snapshot{
   105  		{
   106  			ID:          snapshotID,
   107  			Name:        "new_app_snapshot",
   108  			Description: "",
   109  			ShareID:     "19865c43-3b91-48c9-85a0-7ac4d6bb0efe",
   110  			ShareProto:  "NFS",
   111  			ShareSize:   1,
   112  			Size:        1,
   113  			Status:      "available",
   114  			ProjectID:   "16e1ab15c35a457e9c2b2aa189f544e1",
   115  			CreatedAt:   time.Date(2019, time.January, 06, 11, 11, 02, 0, time.UTC),
   116  			Links: []map[string]string{
   117  				{
   118  					"href": "http://172.18.198.54:8786/v2/16e1ab15c35a457e9c2b2aa189f544e1/snapshots/bc082e99-3bdb-4400-b95e-b85c7a41622c",
   119  					"rel":  "self",
   120  				},
   121  				{
   122  					"href": "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/snapshots/bc082e99-3bdb-4400-b95e-b85c7a41622c",
   123  					"rel":  "bookmark",
   124  				},
   125  			},
   126  		},
   127  	})
   128  }
   129  
   130  func TestResetStatusSuccess(t *testing.T) {
   131  	th.SetupHTTP()
   132  	defer th.TeardownHTTP()
   133  
   134  	MockResetStatusResponse(t)
   135  
   136  	c := client.ServiceClient()
   137  
   138  	err := snapshots.ResetStatus(context.TODO(), c, snapshotID, &snapshots.ResetStatusOpts{Status: "error"}).ExtractErr()
   139  	th.AssertNoErr(t, err)
   140  }
   141  
   142  func TestForceDeleteSuccess(t *testing.T) {
   143  	th.SetupHTTP()
   144  	defer th.TeardownHTTP()
   145  
   146  	MockForceDeleteResponse(t)
   147  
   148  	c := client.ServiceClient()
   149  
   150  	err := snapshots.ForceDelete(context.TODO(), c, snapshotID).ExtractErr()
   151  	th.AssertNoErr(t, err)
   152  }