1
0
mirror of https://github.com/Luzifer/rconfig.git synced 2024-09-19 08:53:00 +00:00
rconfig/duration_test.go
Knut Ahlers 37f53184c3
Port tests to pure-Go-tests
to remove dependencies to ginkgo and rconfig/v1

Signed-off-by: Knut Ahlers <knut@ahlers.me>
2021-09-06 18:43:24 +02:00

35 lines
664 B
Go

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