summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Burke <rich.g.burke@gmail.com>2018-12-30 11:40:50 +0000
committerRichard Burke <rich.g.burke@gmail.com>2018-12-30 11:40:50 +0000
commit9ca45f6d12bf5af4819b730ce673a27334a55714 (patch)
tree962935ee3dc02c3a9473fefe6f7f189e983746ca
parent5e2d226c081300d1fcadc40504be89e2ae192b5c (diff)
Add unit test for custom commands
-rw-r--r--cmd/grv/config_parse_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/cmd/grv/config_parse_test.go b/cmd/grv/config_parse_test.go
index 0a0bfd2..63fe773 100644
--- a/cmd/grv/config_parse_test.go
+++ b/cmd/grv/config_parse_test.go
@@ -273,6 +273,25 @@ func (defCommandValues *DefCommandValues) Equal(command ConfigCommand) bool {
defCommandValues.functionBody == other.functionBody
}
+type CustomCommandValues struct {
+ commandName string
+ args []string
+}
+
+func (customCommandValues *CustomCommandValues) Equal(command ConfigCommand) bool {
+ if command == nil {
+ return false
+ }
+
+ other, ok := command.(*CustomCommand)
+ if !ok {
+ return false
+ }
+
+ return customCommandValues.commandName == other.commandName &&
+ reflect.DeepEqual(customCommandValues.args, other.args)
+}
+
func TestParseSingleCommand(t *testing.T) {
var singleCommandTests = []struct {
input string
@@ -650,3 +669,26 @@ func TestCommandDescriptorsHaveRequiredFieldsSet(t *testing.T) {
}
}
}
+
+func TestCustomCommandIsReturnedWhenUserDefinedCommandIsInvoked(t *testing.T) {
+ if err := DefineCustomCommand("customcommand"); err != nil {
+ t.Errorf("Failed to defined custom command %v", err)
+ }
+
+ parser := NewConfigParser(strings.NewReader("customcommand arg1 arg2 \"arg 3\""), "")
+
+ expectedCommand := &CustomCommandValues{
+ commandName: "customcommand",
+ args: []string{"arg1", "arg2", "arg 3"},
+ }
+
+ configCommand, _, err := parser.Parse()
+
+ if err != nil {
+ t.Errorf("Failed to parse command invocation %v", err)
+ }
+
+ if !expectedCommand.Equal(configCommand) {
+ t.Errorf("CustomCommand does not match expected value. Expected: %v, Actual: %v", expectedCommand, configCommand)
+ }
+}