Skip to content

Commit

Permalink
Merge pull request #1972 from dearchap/issue_1775
Browse files Browse the repository at this point in the history
Fix:(issue_1775) Add test for zero value structs
  • Loading branch information
abennett committed Aug 26, 2024
2 parents cd7d34a + e71eab6 commit 3d76e1b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3908,6 +3908,11 @@ func TestCommandReadArgsFromStdIn(t *testing.T) {
}
}

func TestZeroValueCommand(t *testing.T) {
var cmd Command
assert.NoError(t, cmd.Run(context.Background(), []string{"foo"}))
}

func TestJSONExportCommand(t *testing.T) {
cmd := buildExtendedTestCommand()
cmd.Arguments = []Argument{
Expand Down
5 changes: 5 additions & 0 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2997,3 +2997,8 @@ func TestStringMapFlagApply_Error(t *testing.T) {
err := set.Parse([]string{"--goat", "aaa", "bbb="})
assert.Error(t, err)
}

func TestZeroValueMutexFlag(t *testing.T) {
var fl MutuallyExclusiveFlags
assert.NoError(t, fl.check(&Command{}))
}
9 changes: 9 additions & 0 deletions value_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestZeroValueSourceChain(t *testing.T) {
var vc ValueSourceChain
assert.Empty(t, vc.EnvKeys())
assert.NotEmpty(t, vc.GoString())
assert.Empty(t, vc.Chain)
assert.Empty(t, vc.String())
}

func TestEnvVarValueSource(t *testing.T) {
t.Run("implements ValueSource", func(t *testing.T) {
src := EnvVar("foo")
Expand Down

0 comments on commit 3d76e1b

Please sign in to comment.