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