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