2017-03-07 16:21:22 +00:00
|
|
|
package parseutil
|
2016-07-11 17:46:23 +00:00
|
|
|
|
2016-07-11 18:19:35 +00:00
|
|
|
import (
|
2017-03-01 13:32:05 +00:00
|
|
|
"encoding/json"
|
2016-07-11 18:19:35 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
2016-07-11 17:46:23 +00:00
|
|
|
|
|
|
|
func Test_ParseDurationSecond(t *testing.T) {
|
|
|
|
outp, err := ParseDurationSecond("9876s")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-07-11 18:19:35 +00:00
|
|
|
if outp != time.Duration(9876)*time.Second {
|
2016-07-11 17:46:23 +00:00
|
|
|
t.Fatal("not equivalent")
|
|
|
|
}
|
|
|
|
outp, err = ParseDurationSecond("9876")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-07-11 18:19:35 +00:00
|
|
|
if outp != time.Duration(9876)*time.Second {
|
2016-07-11 17:46:23 +00:00
|
|
|
t.Fatal("not equivalent")
|
|
|
|
}
|
2017-03-01 13:32:05 +00:00
|
|
|
outp, err = ParseDurationSecond(json.Number("4352"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if outp != time.Duration(4352)*time.Second {
|
|
|
|
t.Fatal("not equivalent")
|
|
|
|
}
|
2016-07-11 17:46:23 +00:00
|
|
|
}
|
2017-03-07 16:21:22 +00:00
|
|
|
|
|
|
|
func Test_ParseBool(t *testing.T) {
|
|
|
|
outp, err := ParseBool("true")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !outp {
|
|
|
|
t.Fatal("wrong output")
|
|
|
|
}
|
|
|
|
outp, err = ParseBool(1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !outp {
|
|
|
|
t.Fatal("wrong output")
|
|
|
|
}
|
|
|
|
outp, err = ParseBool(true)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !outp {
|
|
|
|
t.Fatal("wrong output")
|
|
|
|
}
|
|
|
|
}
|