Codebase list golang-github-alecthomas-kong / 9c19b2d3-dc8b-41a0-9c9a-78506f97c374/upstream/sid defaults_test.go
9c19b2d3-dc8b-41a0-9c9a-78506f97c374/upstream/sid

Tree @9c19b2d3-dc8b-41a0-9c9a-78506f97c374/upstream/sid (Download .tar.gz)

defaults_test.go @9c19b2d3-dc8b-41a0-9c9a-78506f97c374/upstream/sidraw · history · blame

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