X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/442a871e7f3476938d0ebb3adbe3b9a7742f03ad..1166aeb6033725709ded753a0c00f69320a9a873:/sdk/go/arvados/duration_test.go diff --git a/sdk/go/arvados/duration_test.go b/sdk/go/arvados/duration_test.go index ee787a6a76..257a2b4ef5 100644 --- a/sdk/go/arvados/duration_test.go +++ b/sdk/go/arvados/duration_test.go @@ -43,3 +43,20 @@ func (s *DurationSuite) TestMarshalJSON(c *check.C) { c.Check(string(buf), check.Equals, `"`+trial.out+`"`) } } + +func (s *DurationSuite) TestUnmarshalJSON(c *check.C) { + var d struct { + D Duration + } + err := json.Unmarshal([]byte(`{"D":1.234}`), &d) + 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`) + err = json.Unmarshal([]byte(`{"D":"1"}`), &d) + 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`) + err = json.Unmarshal([]byte(`{"D":"60s"}`), &d) + c.Check(err, check.IsNil) + c.Check(d.D.Duration(), check.Equals, time.Minute) +}