github.com/gophercloud/gophercloud@v1.11.0/openstack/objectstorage/v1/accounts/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts"
     8  	th "github.com/gophercloud/gophercloud/testhelper"
     9  	fake "github.com/gophercloud/gophercloud/testhelper/client"
    10  )
    11  
    12  func TestUpdateAccount(t *testing.T) {
    13  	th.SetupHTTP()
    14  	defer th.TeardownHTTP()
    15  	HandleUpdateAccountSuccessfully(t)
    16  
    17  	options := &accounts.UpdateOpts{
    18  		Metadata:          map[string]string{"gophercloud-test": "accounts"},
    19  		RemoveMetadata:    []string{"gophercloud-test-remove"},
    20  		ContentType:       new(string),
    21  		DetectContentType: new(bool),
    22  	}
    23  	res := accounts.Update(fake.ServiceClient(), options)
    24  	th.AssertNoErr(t, res.Err)
    25  
    26  	expected := &accounts.UpdateHeader{
    27  		Date: time.Date(2014, time.January, 17, 16, 9, 56, 0, time.UTC),
    28  	}
    29  	actual, err := res.Extract()
    30  	th.AssertNoErr(t, err)
    31  	th.CheckDeepEquals(t, expected, actual)
    32  }
    33  
    34  func TestGetAccount(t *testing.T) {
    35  	th.SetupHTTP()
    36  	defer th.TeardownHTTP()
    37  	HandleGetAccountSuccessfully(t)
    38  
    39  	expectedMetadata := map[string]string{"Subject": "books", "Quota-Bytes": "42", "Temp-Url-Key": "testsecret"}
    40  	res := accounts.Get(fake.ServiceClient(), &accounts.GetOpts{})
    41  	th.AssertNoErr(t, res.Err)
    42  	actualMetadata, _ := res.ExtractMetadata()
    43  	th.CheckDeepEquals(t, expectedMetadata, actualMetadata)
    44  	_, err := res.Extract()
    45  	th.AssertNoErr(t, err)
    46  
    47  	var quotaBytes int64 = 42
    48  	expected := &accounts.GetHeader{
    49  		QuotaBytes:     &quotaBytes,
    50  		ContainerCount: 2,
    51  		ObjectCount:    5,
    52  		BytesUsed:      14,
    53  		Date:           time.Date(2014, time.January, 17, 16, 9, 56, 0, time.UTC),
    54  		TempURLKey:     "testsecret",
    55  	}
    56  	actual, err := res.Extract()
    57  	th.AssertNoErr(t, err)
    58  	th.CheckDeepEquals(t, expected, actual)
    59  }
    60  
    61  func TestGetAccountNoQuota(t *testing.T) {
    62  	th.SetupHTTP()
    63  	defer th.TeardownHTTP()
    64  	HandleGetAccountNoQuotaSuccessfully(t)
    65  
    66  	expectedMetadata := map[string]string{"Subject": "books"}
    67  	res := accounts.Get(fake.ServiceClient(), &accounts.GetOpts{})
    68  	th.AssertNoErr(t, res.Err)
    69  	actualMetadata, _ := res.ExtractMetadata()
    70  	th.CheckDeepEquals(t, expectedMetadata, actualMetadata)
    71  	_, err := res.Extract()
    72  	th.AssertNoErr(t, err)
    73  
    74  	expected := &accounts.GetHeader{
    75  		QuotaBytes:     nil,
    76  		ContainerCount: 2,
    77  		ObjectCount:    5,
    78  		BytesUsed:      14,
    79  		Date:           time.Date(2014, time.January, 17, 16, 9, 56, 0, time.UTC),
    80  	}
    81  	actual, err := res.Extract()
    82  	th.AssertNoErr(t, err)
    83  	th.CheckDeepEquals(t, expected, actual)
    84  }