From 725ffa66897cf2d8943e4fcedc354abea4899324 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Sat, 17 Feb 2018 18:07:39 +0100 Subject: add test for FieldHTTPTimeReadonly --- field_test.go | 31 +++++++++++++++++++++++++++++++ shared_test.go | 11 +++++++++-- 2 files changed, 40 insertions(+), 2 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) { diff --git a/shared_test.go b/shared_test.go index 2bc5bee..10402bc 100644 --- a/shared_test.go +++ b/shared_test.go @@ -146,14 +146,21 @@ func expectFloat64(t *testing.T, actual float64, expected float64) { } } -func expectInt(t *testing.T, actual int, expected int) { +func expectInt(t *testing.T, actual, expected int) { t.Helper() if actual != expected { t.Errorf("expected value %d, got %d instead\n", expected, actual) } } -func expectUint64(t *testing.T, actual uint64, expected uint64) { +func expectInt64(t *testing.T, actual, expected int64) { + t.Helper() + if actual != expected { + t.Errorf("expected value %d, got %d instead\n", expected, actual) + } +} + +func expectUint64(t *testing.T, actual, expected uint64) { t.Helper() if actual != expected { t.Errorf("expected value %d, got %d instead\n", expected, actual) -- cgit v1.2.3