[ARVADOS] created: 1.3.0-981-g6e73eff39

Git user git at public.curoverse.com
Fri May 31 20:15:54 UTC 2019


        at  6e73eff3926a2e7345333edd02531e8e6fbe15ef (commit)


commit 6e73eff3926a2e7345333edd02531e8e6fbe15ef
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Fri May 31 16:15:05 2019 -0400

    15003: Format durations as "336h", not "336h0m0s".
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/lib/config/cmd_test.go b/lib/config/cmd_test.go
index bedcc0dd8..e4d838f85 100644
--- a/lib/config/cmd_test.go
+++ b/lib/config/cmd_test.go
@@ -79,6 +79,25 @@ Clusters:
 	c.Check(stderr.String(), check.Matches, `(?ms).*unexpected object in config entry: Clusters.z1234.PostgreSQL.ConnectionPool\n.*`)
 }
 
+func (s *CommandSuite) TestDumpFormatting(c *check.C) {
+	var stdout, stderr bytes.Buffer
+	in := `
+Clusters:
+ z1234:
+  Containers:
+   CloudVMs:
+    TimeoutBooting: 600s
+  Services:
+   Controller:
+    InternalURLs:
+     http://localhost:12345: {}
+`
+	code := DumpCommand.RunCommand("arvados config-dump", nil, bytes.NewBufferString(in), &stdout, &stderr)
+	c.Check(code, check.Equals, 0)
+	c.Check(stdout.String(), check.Matches, `(?ms).*TimeoutBooting: 10m\n.*`)
+	c.Check(stdout.String(), check.Matches, `(?ms).*http://localhost:12345: {}\n.*`)
+}
+
 func (s *CommandSuite) TestDumpUnknownKey(c *check.C) {
 	var stdout, stderr bytes.Buffer
 	in := `
diff --git a/sdk/go/arvados/duration.go b/sdk/go/arvados/duration.go
index d3e11c7a5..2696fdb05 100644
--- a/sdk/go/arvados/duration.go
+++ b/sdk/go/arvados/duration.go
@@ -7,6 +7,7 @@ package arvados
 import (
 	"encoding/json"
 	"fmt"
+	"strings"
 	"time"
 )
 
@@ -27,9 +28,13 @@ func (d Duration) MarshalJSON() ([]byte, error) {
 	return json.Marshal(d.String())
 }
 
-// String implements fmt.Stringer.
+// String returns a format similar to (time.Duration)String() but with
+// "0m" and "0s" removed: e.g., "1h" instead of "1h0m0s".
 func (d Duration) String() string {
-	return time.Duration(d).String()
+	s := time.Duration(d).String()
+	s = strings.Replace(s, "m0s", "m", 1)
+	s = strings.Replace(s, "h0m", "h", 1)
+	return s
 }
 
 // Duration returns a time.Duration.
diff --git a/sdk/go/arvados/duration_test.go b/sdk/go/arvados/duration_test.go
new file mode 100644
index 000000000..ee787a6a7
--- /dev/null
+++ b/sdk/go/arvados/duration_test.go
@@ -0,0 +1,45 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: Apache-2.0
+
+package arvados
+
+import (
+	"encoding/json"
+	"time"
+
+	check "gopkg.in/check.v1"
+)
+
+var _ = check.Suite(&DurationSuite{})
+
+type DurationSuite struct{}
+
+func (s *DurationSuite) TestMarshalJSON(c *check.C) {
+	var d struct {
+		D Duration
+	}
+	err := json.Unmarshal([]byte(`{"D":"1.234s"}`), &d)
+	c.Check(err, check.IsNil)
+	c.Check(d.D, check.Equals, Duration(time.Second+234*time.Millisecond))
+	buf, err := json.Marshal(d)
+	c.Check(string(buf), check.Equals, `{"D":"1.234s"}`)
+
+	for _, trial := range []struct {
+		seconds int
+		out     string
+	}{
+		{30, "30s"},
+		{60, "1m"},
+		{120, "2m"},
+		{150, "2m30s"},
+		{3600, "1h"},
+		{7201, "2h1s"},
+		{360600, "100h10m"},
+		{360610, "100h10m10s"},
+	} {
+		buf, err := json.Marshal(Duration(time.Duration(trial.seconds) * time.Second))
+		c.Check(err, check.IsNil)
+		c.Check(string(buf), check.Equals, `"`+trial.out+`"`)
+	}
+}

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list