[ARVADOS] updated: 1.3.0-1047-geaf26ebd2

Git user git at public.curoverse.com
Thu Jun 13 13:32:13 UTC 2019


Summary of changes:
 sdk/go/arvados/duration.go      |  4 +++-
 sdk/go/arvados/duration_test.go | 17 +++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

       via  eaf26ebd285952ec6695270f0eda04ea7bf7e6c6 (commit)
      from  68211a7ead5f3cbe1a90b1b7769118a2b3543211 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit eaf26ebd285952ec6695270f0eda04ea7bf7e6c6
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Thu Jun 13 09:32:02 2019 -0400

    15000: Include bad value in error message.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/sdk/go/arvados/duration.go b/sdk/go/arvados/duration.go
index 2696fdb05..ee482fdf3 100644
--- a/sdk/go/arvados/duration.go
+++ b/sdk/go/arvados/duration.go
@@ -20,7 +20,9 @@ func (d *Duration) UnmarshalJSON(data []byte) error {
 	if data[0] == '"' {
 		return d.Set(string(data[1 : len(data)-1]))
 	}
-	return fmt.Errorf("duration must be given as a string like \"600s\" or \"1h30m\"")
+	// Mimic error message returned by ParseDuration for a number
+	// without units.
+	return fmt.Errorf("missing unit in duration %s", data)
 }
 
 // MarshalJSON implements json.Marshaler.
diff --git a/sdk/go/arvados/duration_test.go b/sdk/go/arvados/duration_test.go
index ee787a6a7..257a2b4ef 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)
+}

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list