func TestUpdateAccount(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleUpdateAccountSuccessfully(t) options := &accounts.UpdateOpts{Metadata: map[string]string{"gophercloud-test": "accounts"}} res := accounts.Update(fake.ServiceClient(), options) th.AssertNoErr(t, res.Err) expected := &accounts.UpdateHeader{ Date: gophercloud.JSONRFC1123(time.Date(2014, time.January, 17, 16, 9, 56, 0, loc)), // Fri, 17 Jan 2014 16:09:56 GMT } actual, err := res.Extract() th.AssertNoErr(t, err) th.CheckDeepEquals(t, expected, actual) }
func TestCreateContainer(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleCreateContainerSuccessfully(t) options := containers.CreateOpts{ContentType: "application/json", Metadata: map[string]string{"foo": "bar"}} res := containers.Create(fake.ServiceClient(), "testContainer", options) th.CheckEquals(t, "bar", res.Header["X-Container-Meta-Foo"][0]) expected := &containers.CreateHeader{ ContentLength: 0, ContentType: "text/html; charset=UTF-8", Date: gophercloud.JSONRFC1123(time.Date(2016, time.August, 17, 19, 25, 43, 0, loc)), //Wed, 17 Aug 2016 19:25:43 GMT TransID: "tx554ed59667a64c61866f1-0058b4ba37", } actual, err := res.Extract() th.CheckNoErr(t, err) th.AssertDeepEquals(t, expected, actual) }
func TestDownloadExtraction(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleDownloadObjectSuccessfully(t) response := objects.Download(fake.ServiceClient(), "testContainer", "testObject", nil) // Check []byte extraction bytes, err := response.ExtractContent() th.AssertNoErr(t, err) th.CheckEquals(t, "Successful download with Gophercloud", string(bytes)) expected := &objects.DownloadHeader{ ContentLength: 36, ContentType: "text/plain; charset=utf-8", Date: gophercloud.JSONRFC1123(time.Date(2009, time.November, 10, 23, 0, 0, 0, loc)), } actual, err := response.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"} 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{ ContainerCount: 2, ObjectCount: 5, BytesUsed: 14, Date: gophercloud.JSONRFC1123(time.Date(2014, time.January, 17, 16, 9, 56, 0, loc)), // Fri, 17 Jan 2014 16:09:56 GMT } actual, err := res.Extract() th.AssertNoErr(t, err) th.CheckDeepEquals(t, expected, actual) }
func TestGetContainer(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleGetContainerSuccessfully(t) res := containers.Get(fake.ServiceClient(), "testContainer") _, err := res.ExtractMetadata() th.CheckNoErr(t, err) expected := &containers.GetHeader{ AcceptRanges: "bytes", BytesUsed: 100, ContentType: "application/json; charset=utf-8", Date: gophercloud.JSONRFC1123(time.Date(2016, time.August, 17, 19, 25, 43, 0, loc)), //Wed, 17 Aug 2016 19:25:43 GMT ObjectCount: 4, Read: []string{"test"}, TransID: "tx554ed59667a64c61866f1-0057b4ba37", Write: []string{"test2", "user4"}, } actual, err := res.Extract() th.CheckNoErr(t, err) th.AssertDeepEquals(t, expected, actual) }