File: defaults_test.go

package info (click to toggle)
golang-github-alecthomas-kong 0.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 620 kB
  • sloc: makefile: 2
file content (34 lines) | stat: -rw-r--r-- 728 bytes parent folder | download
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/stretchr/testify/require"
)

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 {
		// nolint: scopelint
		t.Run(tt.name, func(t *testing.T) {
			err := ApplyDefaults(&tt.target)
			require.NoError(t, err)
			require.Equal(t, tt.expected, tt.target)
		})
	}
}