diff options
Diffstat (limited to 'field_test.go')
| -rw-r--r-- | field_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/field_test.go b/field_test.go index c931108..c86f07d 100644 --- a/field_test.go +++ b/field_test.go @@ -19,6 +19,7 @@ package schwift import ( + "net/http" "strconv" "testing" ) @@ -82,6 +83,36 @@ func TestFieldTimestamp(t *testing.T) { expectError(t, hdr.Validate(), `Bad header X-Timestamp: strconv.ParseFloat: parsing "wtf": invalid syntax`) } +func TestFieldHTTPTimestamp(t *testing.T) { + testWithContainer(t, func(c *Container) { + obj := c.Object("test") + err := obj.Upload(nil, nil, nil) + if !expectSuccess(t, err) { + return + } + + hdr, err := obj.Headers() + if !expectSuccess(t, err) { + return + } + expectBool(t, hdr.UpdatedAt().Exists(), true) + + actual := hdr.UpdatedAt().Get() + expected, _ := http.ParseTime(hdr.Get("Last-Modified")) + expectInt64(t, actual.Unix(), expected.Unix()) + }) + + hdr := make(ObjectHeaders) + expectBool(t, hdr.UpdatedAt().Exists(), false) + expectBool(t, hdr.UpdatedAt().Get().IsZero(), true) + expectError(t, hdr.Validate(), "") + + hdr["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"`) +} + //////////////////////////////////////////////////////////////////////////////// func TestFieldUint64(t *testing.T) { |
