github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/blockstorage/extensions/volumeactions/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/huaweicloud/golangsdk"
     8  	"github.com/huaweicloud/golangsdk/openstack/blockstorage/extensions/volumeactions"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	"github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  func TestAttach(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  
    17  	MockAttachResponse(t)
    18  
    19  	options := &volumeactions.AttachOpts{
    20  		MountPoint:   "/mnt",
    21  		Mode:         "rw",
    22  		InstanceUUID: "50902f4f-a974-46a0-85e9-7efc5e22dfdd",
    23  	}
    24  	err := volumeactions.Attach(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).ExtractErr()
    25  	th.AssertNoErr(t, err)
    26  }
    27  
    28  func TestBeginDetaching(t *testing.T) {
    29  	th.SetupHTTP()
    30  	defer th.TeardownHTTP()
    31  
    32  	MockBeginDetachingResponse(t)
    33  
    34  	err := volumeactions.BeginDetaching(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c").ExtractErr()
    35  	th.AssertNoErr(t, err)
    36  }
    37  
    38  func TestDetach(t *testing.T) {
    39  	th.SetupHTTP()
    40  	defer th.TeardownHTTP()
    41  
    42  	MockDetachResponse(t)
    43  
    44  	err := volumeactions.Detach(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", &volumeactions.DetachOpts{}).ExtractErr()
    45  	th.AssertNoErr(t, err)
    46  }
    47  
    48  func TestUploadImage(t *testing.T) {
    49  	th.SetupHTTP()
    50  	defer th.TeardownHTTP()
    51  	MockUploadImageResponse(t)
    52  	options := &volumeactions.UploadImageOpts{
    53  		ContainerFormat: "bare",
    54  		DiskFormat:      "raw",
    55  		ImageName:       "test",
    56  		Force:           true,
    57  	}
    58  
    59  	actual, err := volumeactions.UploadImage(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).Extract()
    60  	th.AssertNoErr(t, err)
    61  
    62  	expected := volumeactions.VolumeImage{
    63  		VolumeID:        "cd281d77-8217-4830-be95-9528227c105c",
    64  		ContainerFormat: "bare",
    65  		DiskFormat:      "raw",
    66  		Description:     "",
    67  		ImageID:         "ecb92d98-de08-45db-8235-bbafe317269c",
    68  		ImageName:       "test",
    69  		Size:            5,
    70  		Status:          "uploading",
    71  		UpdatedAt:       time.Date(2017, 7, 17, 9, 29, 22, 0, time.UTC),
    72  		VolumeType: volumeactions.ImageVolumeType{
    73  			ID:          "b7133444-62f6-4433-8da3-70ac332229b7",
    74  			Name:        "basic.ru-2a",
    75  			Description: "",
    76  			IsPublic:    true,
    77  			ExtraSpecs:  map[string]interface{}{"volume_backend_name": "basic.ru-2a"},
    78  			QosSpecsID:  "",
    79  			Deleted:     false,
    80  			DeletedAt:   time.Time{},
    81  			CreatedAt:   time.Date(2016, 5, 4, 8, 54, 14, 0, time.UTC),
    82  			UpdatedAt:   time.Date(2016, 5, 4, 9, 15, 33, 0, time.UTC),
    83  		},
    84  	}
    85  	th.AssertDeepEquals(t, expected, actual)
    86  }
    87  
    88  func TestReserve(t *testing.T) {
    89  	th.SetupHTTP()
    90  	defer th.TeardownHTTP()
    91  
    92  	MockReserveResponse(t)
    93  
    94  	err := volumeactions.Reserve(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c").ExtractErr()
    95  	th.AssertNoErr(t, err)
    96  }
    97  
    98  func TestUnreserve(t *testing.T) {
    99  	th.SetupHTTP()
   100  	defer th.TeardownHTTP()
   101  
   102  	MockUnreserveResponse(t)
   103  
   104  	err := volumeactions.Unreserve(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c").ExtractErr()
   105  	th.AssertNoErr(t, err)
   106  }
   107  
   108  func TestInitializeConnection(t *testing.T) {
   109  	th.SetupHTTP()
   110  	defer th.TeardownHTTP()
   111  
   112  	MockInitializeConnectionResponse(t)
   113  
   114  	options := &volumeactions.InitializeConnectionOpts{
   115  		IP:        "127.0.0.1",
   116  		Host:      "stack",
   117  		Initiator: "iqn.1994-05.com.redhat:17cf566367d2",
   118  		Multipath: golangsdk.Disabled,
   119  		Platform:  "x86_64",
   120  		OSType:    "linux2",
   121  	}
   122  	_, err := volumeactions.InitializeConnection(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).Extract()
   123  	th.AssertNoErr(t, err)
   124  }
   125  
   126  func TestTerminateConnection(t *testing.T) {
   127  	th.SetupHTTP()
   128  	defer th.TeardownHTTP()
   129  
   130  	MockTerminateConnectionResponse(t)
   131  
   132  	options := &volumeactions.TerminateConnectionOpts{
   133  		IP:        "127.0.0.1",
   134  		Host:      "stack",
   135  		Initiator: "iqn.1994-05.com.redhat:17cf566367d2",
   136  		Multipath: golangsdk.Enabled,
   137  		Platform:  "x86_64",
   138  		OSType:    "linux2",
   139  	}
   140  	err := volumeactions.TerminateConnection(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).ExtractErr()
   141  	th.AssertNoErr(t, err)
   142  }
   143  
   144  func TestExtendSize(t *testing.T) {
   145  	th.SetupHTTP()
   146  	defer th.TeardownHTTP()
   147  
   148  	MockExtendSizeResponse(t)
   149  
   150  	options := &volumeactions.ExtendSizeOpts{
   151  		NewSize: 3,
   152  	}
   153  
   154  	err := volumeactions.ExtendSize(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).ExtractErr()
   155  	th.AssertNoErr(t, err)
   156  }
   157  
   158  func TestForceDelete(t *testing.T) {
   159  	th.SetupHTTP()
   160  	defer th.TeardownHTTP()
   161  
   162  	MockForceDeleteResponse(t)
   163  
   164  	res := volumeactions.ForceDelete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
   165  	th.AssertNoErr(t, res.Err)
   166  }