github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/vbs/v2/shares/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	fake "github.com/huaweicloud/golangsdk/openstack/vbs/v2/common"
     9  	"github.com/huaweicloud/golangsdk/openstack/vbs/v2/shares"
    10  	th "github.com/huaweicloud/golangsdk/testhelper"
    11  )
    12  
    13  func TestListShared(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  	th.Mux.HandleFunc("/os-vendor-backup-sharing/detail", func(w http.ResponseWriter, r *http.Request) {
    17  		th.TestMethod(t, r, "GET")
    18  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    19  		w.Header().Add("Content-Type", "application/json")
    20  		w.WriteHeader(http.StatusOK)
    21  		fmt.Fprintf(w, listResponse)
    22  	})
    23  
    24  	actual, err := shares.List(fake.ServiceClient(), shares.ListOpts{})
    25  	if err != nil {
    26  		t.Errorf("Failed to extract shares: %v", err)
    27  	}
    28  
    29  	expected := []shares.Share{
    30  		{
    31  			BackupID:      "87566ed6-72cb-4053-aa6e-6f6216b3d507",
    32  			ToProjectID:   "91d687759aed45d28b5f6084bc2fa8ad",
    33  			FromProjectID: "17fbda95add24720a4038ba4b1c705ed",
    34  			ID:            "ac0fb374-a288-4399-ac63-cc080a13a2ee",
    35  			Backup: shares.Backup{Status: "available",
    36  				ObjectCount:      0,
    37  				Container:        "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3",
    38  				Name:             "c2c-test-buckup",
    39  				AvailabilityZone: "eu-de-01",
    40  				SnapshotID:       "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3",
    41  				VolumeID:         "5024a06e-6990-4f12-9dcc-8fe26b01a710",
    42  				ID:               "87566ed6-72cb-4053-aa6e-6f6216b3d507",
    43  				Size:             10},
    44  		},
    45  	}
    46  
    47  	th.AssertDeepEquals(t, expected, actual)
    48  }
    49  
    50  func TestGetShared(t *testing.T) {
    51  	th.SetupHTTP()
    52  	defer th.TeardownHTTP()
    53  
    54  	HandleGetSuccessfully(t)
    55  
    56  	s, err := shares.Get(fake.ServiceClient(), "ac0fb374-a288-4399-ac63-cc080a13a2ee").ExtractShare()
    57  	th.AssertNoErr(t, err)
    58  	th.AssertDeepEquals(t, s, &shares.Share{
    59  		BackupID:      "87566ed6-72cb-4053-aa6e-6f6216b3d507",
    60  		ToProjectID:   "91d687759aed45d28b5f6084bc2fa8ad",
    61  		FromProjectID: "17fbda95add24720a4038ba4b1c705ed",
    62  		ID:            "ac0fb374-a288-4399-ac63-cc080a13a2ee",
    63  		Backup: shares.Backup{Status: "available",
    64  			ObjectCount:      0,
    65  			Container:        "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3",
    66  			Name:             "c2c-test-buckup",
    67  			AvailabilityZone: "eu-de-01",
    68  			SnapshotID:       "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3",
    69  			VolumeID:         "5024a06e-6990-4f12-9dcc-8fe26b01a710",
    70  			ID:               "87566ed6-72cb-4053-aa6e-6f6216b3d507",
    71  			Size:             10},
    72  	})
    73  }
    74  
    75  func TestCreateShared(t *testing.T) {
    76  	th.SetupHTTP()
    77  	defer th.TeardownHTTP()
    78  	HandleCreateSuccessfully(t, CreateOutput)
    79  	createOpts := shares.CreateOpts{
    80  		BackupID:     "87566ed6-72cb-4053-aa6e-6f6216b3d507",
    81  		ToProjectIDs: []string{"91d687759aed45d28b5f6084bc2fa8ad"}}
    82  	actual, err := shares.Create(fake.ServiceClient(), createOpts).Extract()
    83  
    84  	th.AssertNoErr(t, err)
    85  
    86  	expected := CreateExpected
    87  	th.AssertDeepEquals(t, expected, actual)
    88  }
    89  
    90  func TestDeleteShared(t *testing.T) {
    91  	th.SetupHTTP()
    92  	defer th.TeardownHTTP()
    93  
    94  	HandleDeleteSuccessfully(t)
    95  
    96  	deleteOpts := shares.DeleteOpts{
    97  		IsBackupID: true,
    98  	}
    99  	result := shares.Delete(fake.ServiceClient(), "87566ed6-72cb-4053-aa6e-6f6216b3d507", deleteOpts)
   100  	th.AssertNoErr(t, result.Err)
   101  }