-
-
Notifications
You must be signed in to change notification settings - Fork 161
Expand file tree
/
Copy pathdefaults_test.go
More file actions
34 lines (31 loc) · 710 Bytes
/
defaults_test.go
File metadata and controls
34 lines (31 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package kong
import (
"testing"
"time"
"github.com/alecthomas/assert/v2"
)
func TestApplyDefaults(t *testing.T) {
type CLI struct {
Str string `default:"str"`
Duration time.Duration `default:"30s"`
}
tests := []struct {
name string
target CLI
expected CLI
}{
{name: "DefaultsWhenNotSet",
expected: CLI{Str: "str", Duration: time.Second * 30}},
{name: "PartiallySetDefaults",
target: CLI{Duration: time.Second},
expected: CLI{Str: "str", Duration: time.Second}},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
err := ApplyDefaults(&tt.target)
assert.NoError(t, err)
assert.Equal(t, tt.expected, tt.target)
})
}
}