github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+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  	BeforeEach(func() {
    35  		actor = NewActor()
    36  	})
    37  
    38  	Describe("CommandInfoByName", func() {
    39  		Context("when the command exists", func() {
    40  			Context("when passed the command name", func() {
    41  				It("returns command info", func() {
    42  					commandInfo, err := actor.CommandInfoByName(commandList{}, "app")
    43  					Expect(err).NotTo(HaveOccurred())
    44  
    45  					Expect(commandInfo.Name).To(Equal("app"))
    46  					Expect(commandInfo.Description).To(Equal("Display health and status for app"))
    47  					Expect(commandInfo.Alias).To(BeEmpty())
    48  					Expect(commandInfo.Usage).To(Equal("CF_NAME app APP_NAME"))
    49  					Expect(commandInfo.Flags).To(HaveLen(1))
    50  					Expect(commandInfo.Flags).To(ContainElement(CommandFlag{
    51  						Short:       "",
    52  						Long:        "guid",
    53  						Description: "Retrieve and display the given app's guid.  All other health and status output for the app is suppressed.",
    54  						Default:     "some-default",
    55  					}))
    56  					Expect(commandInfo.RelatedCommands).To(Equal([]string{
    57  						"apps", "events", "logs", "map-route", "push", "unmap-route",
    58  					}))
    59  				})
    60  
    61  				Context("when the command uses timeout environment variables", func() {
    62  					It("has timeout environment variables", func() {
    63  						commandInfo, err := actor.CommandInfoByName(commandList{}, "restage")
    64  						Expect(err).NotTo(HaveOccurred())
    65  
    66  						Expect(commandInfo.Environment).To(ConsistOf(
    67  							EnvironmentVariable{
    68  								Name:         "CF_STAGING_TIMEOUT",
    69  								Description:  "Max wait time for buildpack staging, in minutes",
    70  								DefaultValue: "15",
    71  							},
    72  							EnvironmentVariable{
    73  								Name:         "CF_STARTUP_TIMEOUT",
    74  								Description:  "Max wait time for app instance startup, in minutes",
    75  								DefaultValue: "5",
    76  							}))
    77  					})
    78  				})
    79  
    80  				Context("when the command does not use environment variables", func() {
    81  					It("does not have environment variables", func() {
    82  						commandInfo, err := actor.CommandInfoByName(commandList{}, "app")
    83  						Expect(err).NotTo(HaveOccurred())
    84  
    85  						Expect(commandInfo.Environment).To(BeEmpty())
    86  					})
    87  				})
    88  			})
    89  
    90  			Context("when passed the command alias", func() {
    91  				It("returns command info", func() {
    92  					commandInfo, err := actor.CommandInfoByName(commandList{}, "h")
    93  					Expect(err).NotTo(HaveOccurred())
    94  
    95  					Expect(commandInfo.Name).To(Equal("help"))
    96  					Expect(commandInfo.Description).To(Equal("Show help"))
    97  					Expect(commandInfo.Alias).To(Equal("h"))
    98  					Expect(commandInfo.Usage).To(Equal("CF_NAME help [COMMAND]"))
    99  					Expect(commandInfo.Flags).To(ConsistOf(
   100  						CommandFlag{
   101  							Short:       "a",
   102  							Long:        "",
   103  							Description: "All available CLI commands",
   104  						},
   105  					))
   106  				})
   107  			})
   108  		})
   109  
   110  		Context("when the command does not exist", func() {
   111  			It("returns err", func() {
   112  				_, err := actor.CommandInfoByName(commandList{}, "does-not-exist")
   113  
   114  				Expect(err).To(HaveOccurred())
   115  				Expect(err).To(MatchError(ErrorInvalidCommand{CommandName: "does-not-exist"}))
   116  			})
   117  		})
   118  	})
   119  
   120  	Describe("CommandInfos", func() {
   121  		It("returns back all the command's names and descriptions", func() {
   122  			commands := actor.CommandInfos(commandList{})
   123  
   124  			Expect(commands["app"]).To(Equal(CommandInfo{
   125  				Name:        "app",
   126  				Description: "Display health and status for app",
   127  			}))
   128  			Expect(commands["help"]).To(Equal(CommandInfo{
   129  				Name:        "help",
   130  				Description: "Show help",
   131  				Alias:       "h",
   132  			}))
   133  			Expect(commands["restage"]).To(Equal(CommandInfo{
   134  				Name:        "restage",
   135  				Description: "Restage an app",
   136  				Alias:       "rg",
   137  			}))
   138  		})
   139  	})
   140  })