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