Skip to content

Commit 3d76e1b

Browse files
authored
Merge pull request #1972 from dearchap/issue_1775
Fix:(issue_1775) Add test for zero value structs
2 parents cd7d34a + e71eab6 commit 3d76e1b

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

command_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3908,6 +3908,11 @@ func TestCommandReadArgsFromStdIn(t *testing.T) {
39083908
}
39093909
}
39103910

3911+
func TestZeroValueCommand(t *testing.T) {
3912+
var cmd Command
3913+
assert.NoError(t, cmd.Run(context.Background(), []string{"foo"}))
3914+
}
3915+
39113916
func TestJSONExportCommand(t *testing.T) {
39123917
cmd := buildExtendedTestCommand()
39133918
cmd.Arguments = []Argument{

flag_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2997,3 +2997,8 @@ func TestStringMapFlagApply_Error(t *testing.T) {
29972997
err := set.Parse([]string{"--goat", "aaa", "bbb="})
29982998
assert.Error(t, err)
29992999
}
3000+
3001+
func TestZeroValueMutexFlag(t *testing.T) {
3002+
var fl MutuallyExclusiveFlags
3003+
assert.NoError(t, fl.check(&Command{}))
3004+
}

value_source_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@ import (
77
"path/filepath"
88
"testing"
99

10+
"github.com/stretchr/testify/assert"
1011
"github.com/stretchr/testify/require"
1112
)
1213

14+
func TestZeroValueSourceChain(t *testing.T) {
15+
var vc ValueSourceChain
16+
assert.Empty(t, vc.EnvKeys())
17+
assert.NotEmpty(t, vc.GoString())
18+
assert.Empty(t, vc.Chain)
19+
assert.Empty(t, vc.String())
20+
}
21+
1322
func TestEnvVarValueSource(t *testing.T) {
1423
t.Run("implements ValueSource", func(t *testing.T) {
1524
src := EnvVar("foo")

0 commit comments

Comments
 (0)