2016-06-28 10:31:23 +00:00
|
|
|
package rconfig
|
|
|
|
|
|
|
|
import (
|
2021-09-06 16:43:24 +00:00
|
|
|
"testing"
|
2016-06-28 10:31:23 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2021-09-06 16:43:24 +00:00
|
|
|
func TestDurationParsing(t *testing.T) {
|
2016-06-28 10:31:23 +00:00
|
|
|
var (
|
|
|
|
args = []string{
|
|
|
|
"--duration=23s", "-o", "45m",
|
|
|
|
}
|
2021-09-06 16:43:24 +00:00
|
|
|
cfg struct {
|
|
|
|
Test time.Duration `flag:"duration"`
|
|
|
|
TestS time.Duration `flag:"other-duration,o"`
|
|
|
|
TestDef time.Duration `default:"30h"`
|
|
|
|
}
|
|
|
|
)
|
2016-06-28 10:31:23 +00:00
|
|
|
|
2021-09-06 16:43:24 +00:00
|
|
|
if err := parse(&cfg, args); err != nil {
|
|
|
|
t.Fatalf("Parsing options caused error: %s", err)
|
|
|
|
}
|
2016-06-28 10:31:23 +00:00
|
|
|
|
2021-09-06 16:43:24 +00:00
|
|
|
for _, test := range [][2]interface{}{
|
|
|
|
{cfg.Test, 23 * time.Second},
|
|
|
|
{cfg.TestS, 45 * time.Minute},
|
2016-06-28 10:31:23 +00:00
|
|
|
|
2021-09-06 16:43:24 +00:00
|
|
|
{cfg.TestDef, 30 * time.Hour},
|
|
|
|
} {
|
|
|
|
if test[0] != test[1] {
|
|
|
|
t.Errorf("Expected value does not match: %#v != %#v", test[0], test[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|