mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
add a test for DurationPretty
This commit is contained in:
parent
e9f30e1f22
commit
56f943e890
31
types/time/duration_test.go
Normal file
31
types/time/duration_test.go
Normal file
@ -0,0 +1,31 @@
|
||||
package time
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDurationPretty(t *testing.T) {
|
||||
testCases := []struct {
|
||||
jsonBytes []byte
|
||||
expErr bool
|
||||
expValue time.Duration
|
||||
}{
|
||||
{[]byte(`"10s"`), false, 10 * time.Second},
|
||||
{[]byte(`"48h0m0s"`), false, 48 * time.Hour},
|
||||
{[]byte(`"10kkk"`), true, 0},
|
||||
{[]byte(`"kkk"`), true, 0},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
var d DurationPretty
|
||||
if tc.expErr {
|
||||
assert.Error(t, d.UnmarshalJSON(tc.jsonBytes), "#%d", i)
|
||||
} else {
|
||||
assert.NoError(t, d.UnmarshalJSON(tc.jsonBytes), "#%d", i)
|
||||
assert.Equal(t, tc.expValue, d.Duration, "#%d", i)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user