Skip to content

Commit 2394028

Browse files
committed
one more test
1 parent 0769798 commit 2394028

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

internal/pkg/agent/cmd/cmd_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ package cmd
66

77
import (
88
"testing"
9+
10+
"github.com/spf13/cobra"
11+
"github.com/stretchr/testify/require"
912
)
1013

1114
func TestAgent(t *testing.T) {
@@ -30,3 +33,18 @@ func TestAgent(t *testing.T) {
3033
// assert.True(t, strings.Contains(string(contents), "Hello I am running"))
3134
// })
3235
}
36+
37+
func TestAddCommandIfNotNil(t *testing.T) {
38+
cmd := &cobra.Command{}
39+
40+
parent := &cobra.Command{}
41+
addCommandIfNotNil(parent, cmd)
42+
require.Equal(t, 1, len(parent.Commands()))
43+
44+
parent = &cobra.Command{}
45+
addCommandIfNotNil(parent, nil)
46+
require.Equal(t, 0, len(parent.Commands()))
47+
48+
// this should not panic
49+
addCommandIfNotNil(nil, cmd)
50+
}

0 commit comments

Comments
 (0)