github.com/elopio/cli@v6.21.2-0.20160902224010-ea909d1fdb2f+incompatible/actors/v2actions/help_test.go (about) 1 package v2actions_test 2 3 import ( 4 . "code.cloudfoundry.org/cli/actors/v2actions" 5 "code.cloudfoundry.org/cli/commands/v2" 6 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 ) 10 11 var _ = Describe("Help Actions", func() { 12 var actor Actor 13 BeforeEach(func() { 14 actor = NewActor() 15 }) 16 17 Describe("CommandInfoByName", func() { 18 Context("when the command exists", func() { 19 Context("when passed the command name", func() { 20 It("returns command info", func() { 21 commandInfo, err := actor.CommandInfoByName(v2.Commands, "app") 22 Expect(err).NotTo(HaveOccurred()) 23 24 Expect(commandInfo.Name).To(Equal("app")) 25 Expect(commandInfo.Description).To(Equal("Display health and status for app")) 26 Expect(commandInfo.Alias).To(BeEmpty()) 27 Expect(commandInfo.Usage).To(Equal("CF_NAME app APP_NAME")) 28 Expect(commandInfo.Flags).To(HaveLen(1)) 29 Expect(commandInfo.Flags).To(ContainElement(CommandFlag{ 30 Short: "", 31 Long: "guid", 32 Description: "Retrieve and display the given app's guid. All other health and status output for the app is suppressed.", 33 })) 34 Expect(commandInfo.RelatedCommands).To(Equal([]string{ 35 "apps", "events", "logs", "map-route", "push", "unmap-route", 36 })) 37 }) 38 }) 39 40 Context("when passed the command alias", func() { 41 It("returns command info", func() { 42 commandInfo, err := actor.CommandInfoByName(v2.Commands, "h") 43 Expect(err).NotTo(HaveOccurred()) 44 45 Expect(commandInfo.Name).To(Equal("help")) 46 Expect(commandInfo.Description).To(Equal("Show help")) 47 Expect(commandInfo.Alias).To(Equal("h")) 48 Expect(commandInfo.Usage).To(Equal("CF_NAME help [COMMAND]")) 49 Expect(commandInfo.Flags).To(ConsistOf( 50 CommandFlag{ 51 Short: "a", 52 Long: "", 53 Description: "All available CLI commands", 54 }, 55 )) 56 }) 57 }) 58 }) 59 60 Context("when the command does not exist", func() { 61 It("returns err", func() { 62 _, err := actor.CommandInfoByName(v2.Commands, "does-not-exist") 63 64 Expect(err).To(HaveOccurred()) 65 Expect(err).To(MatchError(ErrorInvalidCommand{CommandName: "does-not-exist"})) 66 }) 67 }) 68 }) 69 70 Describe("CommandInfos", func() { 71 It("returns back all the command's names and descriptions", func() { 72 commands := actor.CommandInfos(v2.Commands) 73 74 Expect(len(commands)).To(BeNumerically(">=", 153)) 75 Expect(commands["app"]).To(Equal(CommandInfo{ 76 Name: "app", 77 Description: "Display health and status for app", 78 })) 79 Expect(commands["curl"]).To(Equal(CommandInfo{ 80 Name: "curl", 81 Description: "Executes a request to the targeted API endpoint", 82 })) 83 Expect(commands["apps"]).To(Equal(CommandInfo{ 84 Name: "apps", 85 Description: "List all apps in the target space", 86 Alias: "a", 87 })) 88 Expect(commands["routes"]).To(Equal(CommandInfo{ 89 Name: "routes", 90 Description: "List all routes in the current space or the current organization", 91 Alias: "r", 92 })) 93 }) 94 }) 95 })