mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
Test for Persistent-Run propagation
This commit is contained in:
parent
42e6ce397f
commit
799a8ef863
1 changed files with 17 additions and 0 deletions
|
@ -869,3 +869,20 @@ func TestPreRun(t *testing.T) {
|
|||
t.Error("Wrong *Pre functions called!")
|
||||
}
|
||||
}
|
||||
|
||||
// Check if cmdEchoSub gets PersistentPreRun from rootCmd even if is added last
|
||||
func TestPeristentPreRunPropagation(t *testing.T) {
|
||||
rootCmd := initialize()
|
||||
|
||||
// First add the cmdEchoSub to cmdPrint
|
||||
cmdPrint.AddCommand(cmdEchoSub)
|
||||
// Now add cmdPrint to rootCmd
|
||||
rootCmd.AddCommand(cmdPrint)
|
||||
|
||||
rootCmd.SetArgs(strings.Split("print echosub lala", " "))
|
||||
rootCmd.Execute()
|
||||
|
||||
if rootPersPre == nil || len(rootPersPre) == 0 || rootPersPre[0] != "lala" {
|
||||
t.Error("RootCmd PersistentPreRun not called but should have been")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue