|
|
@ -73,6 +73,54 @@ func TestCommand_Run_DoesNotOverwriteErrorFromBefore(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestCommand_Run_BeforeSavesMetadata(t *testing.T) {
|
|
|
|
|
|
|
|
var receivedMsgFromAction string
|
|
|
|
|
|
|
|
var receivedMsgFromAfter string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app := NewApp()
|
|
|
|
|
|
|
|
app.Commands = []Command{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Name: "bar",
|
|
|
|
|
|
|
|
Before: func(c *Context) error {
|
|
|
|
|
|
|
|
c.App.Metadata["msg"] = "hello world"
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Action: func(c *Context) error {
|
|
|
|
|
|
|
|
msg, ok := c.App.Metadata["msg"]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
return errors.New("msg not found")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
receivedMsgFromAction = msg.(string)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
After: func(c *Context) error {
|
|
|
|
|
|
|
|
msg, ok := c.App.Metadata["msg"]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
return errors.New("msg not found")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
receivedMsgFromAfter = msg.(string)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err := app.Run([]string{"foo", "bar"})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Fatalf("expected no error from Run, got %s", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expectedMsg := "hello world"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if receivedMsgFromAction != expectedMsg {
|
|
|
|
|
|
|
|
t.Fatalf("expected msg from Action to match. Given: %q\nExpected: %q",
|
|
|
|
|
|
|
|
receivedMsgFromAction, expectedMsg)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if receivedMsgFromAfter != expectedMsg {
|
|
|
|
|
|
|
|
t.Fatalf("expected msg from After to match. Given: %q\nExpected: %q",
|
|
|
|
|
|
|
|
receivedMsgFromAction, expectedMsg)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestCommand_OnUsageError_WithWrongFlagValue(t *testing.T) {
|
|
|
|
func TestCommand_OnUsageError_WithWrongFlagValue(t *testing.T) {
|
|
|
|
app := NewApp()
|
|
|
|
app := NewApp()
|
|
|
|
app.Commands = []Command{
|
|
|
|
app.Commands = []Command{
|
|
|
|