mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-20 00:31:17 -08:00
tstime: fold fractional ParseDuration cases into TestParseDuration
Updates #21552 Signed-off-by: Aniket <[email protected]>
This commit is contained in:
1 parent
5e444c9f32
commit
e3ecbb9894
1 file changed
+3
-7
@@ -30,24 +30,20 @@ func TestParseDuration(t *testing.T) {
|
||||
{"1w1d1h", 8*24*time.Hour + time.Hour},
|
||||
{"1y", 0},
|
||||
{"", 0},
|
||||
{"1.5h", 90 * time.Minute},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got, _ := ParseDuration(tt.in); got != tt.want {
|
||||
t.Errorf("ParseDuration(%q) = %d; want %d", tt.in, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDurationFractionalDaysAndWeeks(t *testing.T) {
|
||||
for _, in := range []string{"0.5d", "1.5d", "1.5w", ".5d", "2.25w", "1d0.5d"} {
|
||||
errTests := []string{"0.5d", "1.5d", "1.5w", ".5d", "2.25w", "1d0.5d"}
|
||||
for _, in := range errTests {
|
||||
if d, err := ParseDuration(in); err == nil {
|
||||
t.Errorf("ParseDuration(%q) = %v, want error", in, d)
|
||||
}
|
||||
}
|
||||
// Fractional standard units are still fine.
|
||||
if got, _ := ParseDuration("1.5h"); got != 90*time.Minute {
|
||||
t.Errorf("ParseDuration(%q) = %v, want %v", "1.5h", got, 90*time.Minute)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGoDuration(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user