util/time: ParseDuration fix
All checks were successful
lint / lint (pull_request) Successful in 1m0s
pr / test (pull_request) Successful in 58s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2023-05-29 13:59:30 +03:00
parent ce125b77c1
commit 9b3bccd1f1
2 changed files with 10 additions and 3 deletions

View File

@@ -23,13 +23,21 @@ func TestUnmarshalJSON(t *testing.T) {
TTL Duration `json:"ttl"`
}
v := &str{}
var err error
err := json.Unmarshal([]byte(`{"ttl":"10ms"}`), v)
err = json.Unmarshal([]byte(`{"ttl":"10ms"}`), v)
if err != nil {
t.Fatal(err)
} else if v.TTL != 10000000 {
t.Fatalf("invalid duration %v != 10000000", v.TTL)
}
err = json.Unmarshal([]byte(`{"ttl":"1y"}`), v)
if err != nil {
t.Fatal(err)
} else if v.TTL != 31536000000000000 {
t.Fatalf("invalid duration %v != 31536000000000000", v.TTL)
}
}
func TestParseDuration(t *testing.T) {