github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/evs/extensions/volumeactions/testing/requests_test.go (about)

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