More specific types for ObjectStorage response object fields (#74)
* more accurate types for objectstorage response object fields (e.g. ContentLength: string -> in64)
* containers unit tests for new field types
* more specific types for accounts headers fields
* update accounts unit tests
* download header unmarshal method and unit test
* object results unmarshal methods
diff --git a/openstack/objectstorage/v1/containers/testing/fixtures.go b/openstack/objectstorage/v1/containers/testing/fixtures.go
index fe579d8..b68230a 100644
--- a/openstack/objectstorage/v1/containers/testing/fixtures.go
+++ b/openstack/objectstorage/v1/containers/testing/fixtures.go
@@ -103,7 +103,10 @@
th.TestHeader(t, r, "Accept", "application/json")
w.Header().Add("X-Container-Meta-Foo", "bar")
- w.Header().Add("X-Trans-Id", "1234567")
+ w.Header().Set("Content-Length", "0")
+ w.Header().Set("Content-Type", "text/html; charset=UTF-8")
+ w.Header().Set("Date", "Wed, 17 Aug 2016 19:25:43 GMT")
+ w.Header().Set("X-Trans-Id", "tx554ed59667a64c61866f1-0058b4ba37")
w.WriteHeader(http.StatusNoContent)
})
}
@@ -137,6 +140,15 @@
th.TestMethod(t, r, "HEAD")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
+ w.Header().Set("Accept-Ranges", "bytes")
+ w.Header().Set("Content-Type", "application/json; charset=utf-8")
+ w.Header().Set("Date", "Wed, 17 Aug 2016 19:25:43 GMT")
+ w.Header().Set("X-Container-Bytes-Used", "100")
+ w.Header().Set("X-Container-Object-Count", "4")
+ w.Header().Set("X-Container-Read", "test")
+ w.Header().Set("X-Container-Write", "test2,user4")
+ w.Header().Set("X-Timestamp", "1471298837.95721")
+ w.Header().Set("X-Trans-Id", "tx554ed59667a64c61866f1-0057b4ba37")
w.WriteHeader(http.StatusNoContent)
})
}
diff --git a/openstack/objectstorage/v1/containers/testing/requests_test.go b/openstack/objectstorage/v1/containers/testing/requests_test.go
index 0d32882..abac922 100644
--- a/openstack/objectstorage/v1/containers/testing/requests_test.go
+++ b/openstack/objectstorage/v1/containers/testing/requests_test.go
@@ -2,14 +2,19 @@
import (
"testing"
+ "time"
+ "github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers"
"github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
fake "github.com/gophercloud/gophercloud/testhelper/client"
)
-var metadata = map[string]string{"gophercloud-test": "containers"}
+var (
+ metadata = map[string]string{"gophercloud-test": "containers"}
+ loc, _ = time.LoadLocation("GMT")
+)
func TestListContainerInfo(t *testing.T) {
th.SetupHTTP()
@@ -83,10 +88,17 @@
options := containers.CreateOpts{ContentType: "application/json", Metadata: map[string]string{"foo": "bar"}}
res := containers.Create(fake.ServiceClient(), "testContainer", options)
- c, err := res.Extract()
- th.CheckNoErr(t, err)
th.CheckEquals(t, "bar", res.Header["X-Container-Meta-Foo"][0])
- th.CheckEquals(t, "1234567", c.TransID)
+
+ 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 TestDeleteContainer(t *testing.T) {
@@ -113,6 +125,21 @@
defer th.TeardownHTTP()
HandleGetContainerSuccessfully(t)
- _, err := containers.Get(fake.ServiceClient(), "testContainer").ExtractMetadata()
+ 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)
}