X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f5764a05d616e8d3c55b94503d5a1f789ac66ea7..0f5b0542513b572959e39400bae42e69aeb1a7b6:/sdk/go/arvados/duration_test.go diff --git a/sdk/go/arvados/duration_test.go b/sdk/go/arvados/duration_test.go index 257a2b4ef5..40344d061b 100644 --- a/sdk/go/arvados/duration_test.go +++ b/sdk/go/arvados/duration_test.go @@ -23,6 +23,7 @@ func (s *DurationSuite) TestMarshalJSON(c *check.C) { c.Check(err, check.IsNil) c.Check(d.D, check.Equals, Duration(time.Second+234*time.Millisecond)) buf, err := json.Marshal(d) + c.Check(err, check.IsNil) c.Check(string(buf), check.Equals, `{"D":"1.234s"}`) for _, trial := range []struct { @@ -49,14 +50,24 @@ func (s *DurationSuite) TestUnmarshalJSON(c *check.C) { D Duration } err := json.Unmarshal([]byte(`{"D":1.234}`), &d) - c.Check(err, check.ErrorMatches, `missing unit in duration 1.234`) + c.Check(err, check.ErrorMatches, `.*missing unit in duration "?1\.234"?`) err = json.Unmarshal([]byte(`{"D":"1.234"}`), &d) - c.Check(err, check.ErrorMatches, `.*missing unit in duration 1.234`) + c.Check(err, check.ErrorMatches, `.*missing unit in duration "?1\.234"?`) err = json.Unmarshal([]byte(`{"D":"1"}`), &d) - c.Check(err, check.ErrorMatches, `.*missing unit in duration 1`) + c.Check(err, check.ErrorMatches, `.*missing unit in duration "?1"?`) err = json.Unmarshal([]byte(`{"D":"foobar"}`), &d) - c.Check(err, check.ErrorMatches, `.*invalid duration foobar`) + c.Check(err, check.ErrorMatches, `.*invalid duration "?foobar"?`) err = json.Unmarshal([]byte(`{"D":"60s"}`), &d) c.Check(err, check.IsNil) c.Check(d.D.Duration(), check.Equals, time.Minute) + + d.D = Duration(time.Second) + err = json.Unmarshal([]byte(`{"D":"0"}`), &d) + c.Check(err, check.IsNil) + c.Check(d.D.Duration(), check.Equals, time.Duration(0)) + + d.D = Duration(time.Second) + err = json.Unmarshal([]byte(`{"D":0}`), &d) + c.Check(err, check.IsNil) + c.Check(d.D.Duration(), check.Equals, time.Duration(0)) }