This repository has been archived by the owner on Nov 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from pdalpra/timeout-as-time.Duration
Use time.Duration as type for timeouts
- Loading branch information
Showing
7 changed files
with
55 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package time | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
) | ||
|
||
// DurationToSecondsString converts the specified duration to the number | ||
// seconds it represents, formatted as a string. | ||
func DurationToSecondsString(duration time.Duration) string { | ||
return strconv.FormatFloat(duration.Seconds(), 'f', 0, 64) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package time | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestDurationToSecondsString(t *testing.T) { | ||
cases := []struct { | ||
in time.Duration | ||
expected string | ||
}{ | ||
{0 * time.Second, "0"}, | ||
{1 * time.Second, "1"}, | ||
{1 * time.Minute, "60"}, | ||
{24 * time.Hour, "86400"}, | ||
} | ||
|
||
for _, c := range cases { | ||
s := DurationToSecondsString(c.in) | ||
if s != c.expected { | ||
t.Errorf("wrong value for input `%v`: expected `%s`, got `%s`", c.in, c.expected, s) | ||
t.Fail() | ||
} | ||
} | ||
} |