diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2018-03-11 19:38:27 +0100 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2018-03-11 19:41:33 +0100 |
| commit | d23b4052c0866698b14ac13ac98581d9f5440a9b (patch) | |
| tree | 51c93559594f8fd5136fd51b7397a30415ea93aa /tests/field_test.go | |
| parent | aaf61ac55e18a04fd68b9b6ee4fd4fce49659eeb (diff) | |
| download | go-schwift-d23b4052c0866698b14ac13ac98581d9f5440a9b.tar.gz | |
revamp the Headers API
1. Move common methods of AccountHeaders, ContainerHeaders,
ObjectHeaders into a base type Headers.
2. Fold Headers into RequestOptions to remove one of the two optional
arguments on request methods. The new Headers.ToOpts() method
offers a nice experience for users passing Headers to request
methods.
The Update() methods keep the explicit Headers argument since the
Headers argument is not optional there.
The only downside is that we lose a bit of type-safety because
RequestOptions takes any Headers instance, so e.g. ContainerHeaders
could be passed to Object.Upload(). I believe the benefits outweigh
this problem.
Diffstat (limited to 'tests/field_test.go')
| -rw-r--r-- | tests/field_test.go | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/tests/field_test.go b/tests/field_test.go index f3c03ca..8166f2d 100644 --- a/tests/field_test.go +++ b/tests/field_test.go @@ -27,33 +27,33 @@ import ( ) func TestFieldString(t *testing.T) { - hdr := make(schwift.AccountHeaders) + hdr := schwift.NewAccountHeaders() expectBool(t, hdr.TempURLKey().Exists(), false) expectString(t, hdr.TempURLKey().Get(), "") expectSuccess(t, hdr.Validate()) - hdr["X-Account-Meta-Temp-Url-Key"] = "" + hdr.Headers["X-Account-Meta-Temp-Url-Key"] = "" expectBool(t, hdr.TempURLKey().Exists(), false) expectString(t, hdr.TempURLKey().Get(), "") expectSuccess(t, hdr.Validate()) - hdr["X-Account-Meta-Temp-Url-Key"] = "foo" + hdr.Headers["X-Account-Meta-Temp-Url-Key"] = "foo" expectBool(t, hdr.TempURLKey().Exists(), true) expectString(t, hdr.TempURLKey().Get(), "foo") expectSuccess(t, hdr.Validate()) hdr.TempURLKey().Set("bar") - expectHeaders(t, hdr, map[string]string{ + expectHeaders(t, hdr.Headers, map[string]string{ "X-Account-Meta-Temp-Url-Key": "bar", }) hdr.TempURLKey().Clear() - expectHeaders(t, hdr, map[string]string{ + expectHeaders(t, hdr.Headers, map[string]string{ "X-Account-Meta-Temp-Url-Key": "", }) hdr.TempURLKey().Del() - expectHeaders(t, hdr, nil) + expectHeaders(t, hdr.Headers, nil) hdr.TempURLKey().Clear() - expectHeaders(t, hdr, map[string]string{ + expectHeaders(t, hdr.Headers, map[string]string{ "X-Account-Meta-Temp-Url-Key": "", }) } @@ -70,16 +70,16 @@ func TestFieldTimestamp(t *testing.T) { expectBool(t, hdr.CreatedAt().Exists(), true) actual := float64(hdr.CreatedAt().Get().UnixNano()) / 1e9 - expected, _ := strconv.ParseFloat(hdr["X-Timestamp"], 64) + expected, _ := strconv.ParseFloat(hdr.Headers["X-Timestamp"], 64) expectFloat64(t, actual, expected) }) - hdr := make(schwift.AccountHeaders) + hdr := schwift.NewAccountHeaders() expectBool(t, hdr.CreatedAt().Exists(), false) expectBool(t, hdr.CreatedAt().Get().IsZero(), true) expectSuccess(t, hdr.Validate()) - hdr["X-Timestamp"] = "wtf" + hdr.Headers["X-Timestamp"] = "wtf" expectBool(t, hdr.CreatedAt().Exists(), true) expectBool(t, hdr.CreatedAt().Get().IsZero(), true) expectError(t, hdr.Validate(), `Bad header X-Timestamp: strconv.ParseFloat: parsing "wtf": invalid syntax`) @@ -88,7 +88,7 @@ func TestFieldTimestamp(t *testing.T) { func TestFieldHTTPTimestamp(t *testing.T) { testWithContainer(t, func(c *schwift.Container) { obj := c.Object("test") - err := obj.Upload(nil, nil, nil) + err := obj.Upload(nil, nil) if !expectSuccess(t, err) { return } @@ -104,12 +104,12 @@ func TestFieldHTTPTimestamp(t *testing.T) { expectInt64(t, actual.Unix(), expected.Unix()) }) - hdr := make(schwift.ObjectHeaders) + hdr := schwift.NewObjectHeaders() expectBool(t, hdr.UpdatedAt().Exists(), false) expectBool(t, hdr.UpdatedAt().Get().IsZero(), true) expectSuccess(t, hdr.Validate()) - hdr["Last-Modified"] = "wtf" + hdr.Headers["Last-Modified"] = "wtf" expectBool(t, hdr.UpdatedAt().Exists(), true) expectBool(t, hdr.UpdatedAt().Get().IsZero(), true) expectError(t, hdr.Validate(), `Bad header Last-Modified: parsing time "wtf" as "Mon Jan _2 15:04:05 2006": cannot parse "wtf" as "Mon"`) @@ -118,49 +118,49 @@ func TestFieldHTTPTimestamp(t *testing.T) { //////////////////////////////////////////////////////////////////////////////// func TestFieldUint64(t *testing.T) { - hdr := make(schwift.AccountHeaders) + hdr := schwift.NewAccountHeaders() expectBool(t, hdr.BytesUsedQuota().Exists(), false) expectUint64(t, hdr.BytesUsedQuota().Get(), 0) expectSuccess(t, hdr.Validate()) - hdr["X-Account-Meta-Quota-Bytes"] = "23" + hdr.Headers["X-Account-Meta-Quota-Bytes"] = "23" expectBool(t, hdr.BytesUsedQuota().Exists(), true) expectUint64(t, hdr.BytesUsedQuota().Get(), 23) expectSuccess(t, hdr.Validate()) - hdr["X-Account-Meta-Quota-Bytes"] = "-23" + hdr.Headers["X-Account-Meta-Quota-Bytes"] = "-23" expectBool(t, hdr.BytesUsedQuota().Exists(), true) expectUint64(t, hdr.BytesUsedQuota().Get(), 0) expectError(t, hdr.Validate(), `Bad header X-Account-Meta-Quota-Bytes: strconv.ParseUint: parsing "-23": invalid syntax`) hdr.BytesUsedQuota().Set(9001) - expectHeaders(t, hdr, map[string]string{ + expectHeaders(t, hdr.Headers, map[string]string{ "X-Account-Meta-Quota-Bytes": "9001", }) hdr.BytesUsedQuota().Clear() - expectHeaders(t, hdr, map[string]string{ + expectHeaders(t, hdr.Headers, map[string]string{ "X-Account-Meta-Quota-Bytes": "", }) hdr.BytesUsedQuota().Del() - expectHeaders(t, hdr, nil) + expectHeaders(t, hdr.Headers, nil) hdr.BytesUsedQuota().Clear() - expectHeaders(t, hdr, map[string]string{ + expectHeaders(t, hdr.Headers, map[string]string{ "X-Account-Meta-Quota-Bytes": "", }) } func TestFieldUint64Readonly(t *testing.T) { - hdr := make(schwift.AccountHeaders) + hdr := schwift.NewAccountHeaders() expectBool(t, hdr.BytesUsed().Exists(), false) expectUint64(t, hdr.BytesUsed().Get(), 0) expectSuccess(t, hdr.Validate()) - hdr["X-Account-Bytes-Used"] = "23" + hdr.Headers["X-Account-Bytes-Used"] = "23" expectBool(t, hdr.BytesUsed().Exists(), true) expectUint64(t, hdr.BytesUsed().Get(), 23) expectSuccess(t, hdr.Validate()) - hdr["X-Account-Bytes-Used"] = "-23" + hdr.Headers["X-Account-Bytes-Used"] = "-23" expectBool(t, hdr.BytesUsed().Exists(), true) expectUint64(t, hdr.BytesUsed().Get(), 0) expectError(t, hdr.Validate(), `Bad header X-Account-Bytes-Used: strconv.ParseUint: parsing "-23": invalid syntax`) |
