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