code-intelligence.com/cifuzz@v0.40.0/internal/cmdutils/invocation_test.go (about) 1 package cmdutils 2 3 import ( 4 "testing" 5 6 "github.com/spf13/cobra" 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func mockCommand(name string) *cobra.Command { 12 cmd := &cobra.Command{ 13 Use: name, 14 PreRun: func(cmd *cobra.Command, args []string) { 15 InitCurrentInvocation(cmd) 16 }, 17 Run: func(cmd *cobra.Command, args []string) {}, 18 } 19 20 return cmd 21 } 22 23 func TestSettingCommandNameWhenInvoked(t *testing.T) { 24 name := "test" 25 cmd := mockCommand(name) 26 err := cmd.Execute() 27 require.NoError(t, err) 28 29 assert.Equal(t, name, CurrentInvocation.Command, "command name in current invocation is not set correctly") 30 }