-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to override the config namespace for a command.
- Loading branch information
1 parent
4ea0a63
commit 544b773
Showing
6 changed files
with
127 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package commands | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFlagName(t *testing.T) { | ||
var flag = "thing" | ||
testFn := func(c *CmdConfig) error { | ||
return nil | ||
} | ||
parent := &Command{ | ||
Command: &cobra.Command{ | ||
Use: "doit", | ||
Short: "Do the thing", | ||
}, | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
cmd *Command | ||
expected string | ||
}{ | ||
{ | ||
name: "default", | ||
cmd: CmdBuilder(parent, testFn, "run", "Run it", "", Writer), | ||
expected: "doit.run.thing", | ||
}, | ||
{ | ||
name: "overrideCmdNS", | ||
cmd: CmdBuilder(parent, testFn, "run", "Run it", "", Writer, overrideCmdNS("doctl")), | ||
expected: "doctl.run.thing", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
AddStringFlag(tt.cmd, flag, "", "", "the thing") | ||
|
||
assert.Equal(t, tt.expected, flagName(tt.cmd, flag)) | ||
}) | ||
} | ||
} | ||
|
||
func TestCmdNS(t *testing.T) { | ||
testFn := func(c *CmdConfig) error { | ||
return nil | ||
} | ||
parent := &Command{ | ||
Command: &cobra.Command{ | ||
Use: "doit", | ||
Short: "Do the thing", | ||
}, | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
cmd *Command | ||
expected string | ||
}{ | ||
{ | ||
name: "default", | ||
cmd: CmdBuilder(parent, testFn, "run", "Run it", "", Writer), | ||
expected: "doit.run", | ||
}, | ||
{ | ||
name: "overrideCmdNS", | ||
cmd: CmdBuilder(parent, testFn, "run", "Run it", "", Writer, overrideCmdNS("doctl")), | ||
expected: "doctl.run", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equal(t, tt.expected, cmdNS(tt.cmd)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters