github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/actor/sharedaction/help_test.go (about) 1 package sharedaction_test 2 3 import ( 4 . "code.cloudfoundry.org/cli/actor/sharedaction" 5 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 ) 9 10 type commandList struct { 11 App appCommand `command:"app" description:"Display health and status for app"` 12 Restage restageCommand `command:"restage" alias:"rg" description:"Restage an app"` 13 Help helpCommand `command:"help" alias:"h" description:"Show help"` 14 } 15 16 type appCommand struct { 17 GUID bool `long:"guid" description:"Retrieve and display the given app's guid. All other health and status output for the app is suppressed." default:"some-default"` 18 usage interface{} `usage:"CF_NAME app APP_NAME"` 19 relatedCommands interface{} `related_commands:"apps, events, logs, map-route, unmap-route, push"` 20 } 21 22 type restageCommand struct { 23 envCFStagingTimeout interface{} `environmentName:"CF_STAGING_TIMEOUT" environmentDescription:"Max wait time for buildpack staging, in minutes" environmentDefault:"15"` 24 envCFStartupTimeout interface{} `environmentName:"CF_STARTUP_TIMEOUT" environmentDescription:"Max wait time for app instance startup, in minutes" environmentDefault:"5"` 25 } 26 27 type helpCommand struct { 28 AllCommands bool `short:"a" description:"All available CLI commands"` 29 usage interface{} `usage:"CF_NAME help [COMMAND]"` 30 } 31 32 var _ = Describe("Help Actions", func() { 33 var actor *Actor 34 35 BeforeEach(func() { 36 actor = NewActor() 37 }) 38 39 Describe("CommandInfoByName", func() { 40 Context("when the command exists", func() { 41 Context("when passed the command name", func() { 42 It("returns command info", func() { 43 commandInfo, err := actor.CommandInfoByName(commandList{}, "app") 44 Expect(err).NotTo(HaveOccurred()) 45 46 Expect(commandInfo.Name).To(Equal("app")) 47 Expect(commandInfo.Description).To(Equal("Display health and status for app")) 48 Expect(commandInfo.Alias).To(BeEmpty()) 49 Expect(commandInfo.Usage).To(Equal("CF_NAME app APP_NAME")) 50 Expect(commandInfo.Flags).To(HaveLen(1)) 51 Expect(commandInfo.Flags).To(ContainElement(CommandFlag{ 52 Short: "", 53 Long: "guid", 54 Description: "Retrieve and display the given app's guid. All other health and status output for the app is suppressed.", 55 Default: "some-default", 56 })) 57 Expect(commandInfo.RelatedCommands).To(Equal([]string{ 58 "apps", "events", "logs", "map-route", "push", "unmap-route", 59 })) 60 }) 61 62 Context("when the command uses timeout environment variables", func() { 63 It("has timeout environment variables", func() { 64 commandInfo, err := actor.CommandInfoByName(commandList{}, "restage") 65 Expect(err).NotTo(HaveOccurred()) 66 67 Expect(commandInfo.Environment).To(ConsistOf( 68 EnvironmentVariable{ 69 Name: "CF_STAGING_TIMEOUT", 70 Description: "Max wait time for buildpack staging, in minutes", 71 DefaultValue: "15", 72 }, 73 EnvironmentVariable{ 74 Name: "CF_STARTUP_TIMEOUT", 75 Description: "Max wait time for app instance startup, in minutes", 76 DefaultValue: "5", 77 })) 78 }) 79 }) 80 81 Context("when the command does not use environment variables", func() { 82 It("does not have environment variables", func() { 83 commandInfo, err := actor.CommandInfoByName(commandList{}, "app") 84 Expect(err).NotTo(HaveOccurred()) 85 86 Expect(commandInfo.Environment).To(BeEmpty()) 87 }) 88 }) 89 }) 90 91 Context("when passed the command alias", func() { 92 It("returns command info", func() { 93 commandInfo, err := actor.CommandInfoByName(commandList{}, "h") 94 Expect(err).NotTo(HaveOccurred()) 95 96 Expect(commandInfo.Name).To(Equal("help")) 97 Expect(commandInfo.Description).To(Equal("Show help")) 98 Expect(commandInfo.Alias).To(Equal("h")) 99 Expect(commandInfo.Usage).To(Equal("CF_NAME help [COMMAND]")) 100 Expect(commandInfo.Flags).To(ConsistOf( 101 CommandFlag{ 102 Short: "a", 103 Long: "", 104 Description: "All available CLI commands", 105 }, 106 )) 107 }) 108 }) 109 }) 110 111 Context("when the command does not exist", func() { 112 It("returns err", func() { 113 _, err := actor.CommandInfoByName(commandList{}, "does-not-exist") 114 115 Expect(err).To(HaveOccurred()) 116 Expect(err).To(MatchError(ErrorInvalidCommand{CommandName: "does-not-exist"})) 117 }) 118 }) 119 }) 120 121 Describe("CommandInfos", func() { 122 It("returns back all the command's names and descriptions", func() { 123 commands := actor.CommandInfos(commandList{}) 124 125 Expect(commands["app"]).To(Equal(CommandInfo{ 126 Name: "app", 127 Description: "Display health and status for app", 128 })) 129 Expect(commands["help"]).To(Equal(CommandInfo{ 130 Name: "help", 131 Description: "Show help", 132 Alias: "h", 133 })) 134 Expect(commands["restage"]).To(Equal(CommandInfo{ 135 Name: "restage", 136 Description: "Restage an app", 137 Alias: "rg", 138 })) 139 }) 140 }) 141 })