targetedOrgReq.ExecuteReturns(nil) reqFactory.NewTargetedOrgRequirementReturns(targetedOrgReq) spaceRequirement = new(requirementsfakes.FakeSpaceRequirement) spaceRequirement.ExecuteReturns(nil) reqFactory.NewSpaceRequirementReturns(spaceRequirement) cmd = space.ShowSpace{} flagContext = flags.NewFlagContext(cmd.MetaData().Flags) cmd.SetDependency(deps, false) }) Describe("Requirements", func() { Context("when the wrong number of args are provided", func() { BeforeEach(func() { err := flagContext.Parse() Expect(err).NotTo(HaveOccurred()) }) It("fails with no args", func() { _, err := cmd.Requirements(reqFactory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"FAILED"}, []string{"Incorrect Usage. Requires an argument"}, )) }) }) Context("when provided exactly one arg", func() { var actualRequirements []requirements.Requirement
cmd = "a.CreateQuota{} cmd.SetDependency(deps, false) flagContext = flags.NewFlagContext(cmd.MetaData().Flags) loginRequirement = &passingRequirement{Name: "login-requirement"} requirementsFactory.NewLoginRequirementReturns(loginRequirement) minAPIVersionRequirement = &passingRequirement{Name: "min-api-version-requirement"} requirementsFactory.NewMinAPIVersionRequirementReturns(minAPIVersionRequirement) }) Context("when not provided exactly one arg", func() { BeforeEach(func() { flagContext.Parse("quota", "extra-arg") }) It("fails with usage", func() { _, err := cmd.Requirements(requirementsFactory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"FAILED"}, []string{"Incorrect Usage. Requires an argument"}, )) }) }) Context("when provided exactly one arg", func() { BeforeEach(func() { flagContext.Parse("quota")
. "github.com/onsi/gomega" ) var _ = Describe("Flag Constructors", func() { var ( fc flags.FlagContext ) BeforeEach(func() { fc = flags.New() }) Describe("NewStringFlag()", func() { It("init the flag context with a new string flagset", func() { fc.Parse("-s", "test") Expect(fc.IsSet("s")).To(BeFalse()) Expect(fc.String("s")).To(Equal("")) fc.NewStringFlag("s", "s2", "setting new string flag") fc.Parse("-s", "test2") Expect(fc.IsSet("s")).To(BeTrue()) Expect(fc.IsSet("s2")).To(BeTrue()) Expect(fc.String("s")).To(Equal("test2")) Expect(fc.String("s2")).To(Equal("test2")) }) }) Describe("NewStringFlagWithDefault()", func() { It("init the flag context with a new string flagset with default value", func() { fc.Parse("-s", "test")
reqFactory.NewLoginRequirementReturns(loginRequirement) targetedSpaceRequirement = &passingRequirement{Name: "targeted-space-requirement"} reqFactory.NewTargetedSpaceRequirementReturns(targetedSpaceRequirement) applicationRequirement = new(requirementsfakes.FakeApplicationRequirement) applicationRequirement.ExecuteReturns(nil) reqFactory.NewApplicationRequirementReturns(applicationRequirement) }) Describe("Requirements", func() { BeforeEach(func() { cmd.SetDependency(deps, false) }) Context("when not provided exactly 1 argument", func() { It("fails", func() { err := flagContext.Parse("too", "many") Expect(err).NotTo(HaveOccurred()) _, err = cmd.Requirements(reqFactory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage", "Requires an argument"}, )) }) }) Context("when provided exactly one arg", func() { var actualRequirements []requirements.Requirement BeforeEach(func() { err := flagContext.Parse("service-name") Expect(err).NotTo(HaveOccurred())
Describe("Requirements", func() { It("fails if the user is not logged in", func() { cmd.Requirements(requirementsFactory, flagContext) Expect(requirementsFactory.NewLoginRequirementCallCount()).To(Equal(1)) }) It("fails when the routing API endpoint is not set", func() { cmd.Requirements(requirementsFactory, flagContext) Expect(requirementsFactory.NewRoutingAPIRequirementCallCount()).To(Equal(1)) }) It("should fail with usage", func() { flagContext.Parse("blahblah") cmd.Requirements(requirementsFactory, flagContext) Expect(requirementsFactory.NewUsageRequirementCallCount()).To(Equal(1)) }) }) Describe("Execute", func() { var err error BeforeEach(func() { err := flagContext.Parse() Expect(err).NotTo(HaveOccurred()) }) JustBeforeEach(func() {
factory = new(requirementsfakes.FakeFactory) loginRequirement = &passingRequirement{} factory.NewLoginRequirementReturns(loginRequirement) targetedSpaceRequirement = &passingRequirement{} factory.NewTargetedSpaceRequirementReturns(targetedSpaceRequirement) applicationRequirement = new(requirementsfakes.FakeApplicationRequirement) factory.NewApplicationRequirementReturns(applicationRequirement) }) Describe("Requirements", func() { Context("when not provided exactly one arg", func() { BeforeEach(func() { flagContext.Parse("app-name", "extra-arg") }) It("fails with usage", func() { _, err := cmd.Requirements(factory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage. Requires an argument"}, []string{"NAME"}, []string{"USAGE"}, )) }) }) Context("when provided exactly one arg", func() { BeforeEach(func() {
flagContext = flags.NewFlagContext(cmd.MetaData().Flags) cmd = spacequota.SetSpaceQuota{} cmd.SetDependency(deps, false) configRepo.UsernameReturns("my-user") }) Describe("Requirements", func() { Context("when provided a quota and space", func() { var reqs []requirements.Requirement BeforeEach(func() { var err error flagContext.Parse("space", "space-quota") reqs, err = cmd.Requirements(requirementsFactory, flagContext) Expect(err).NotTo(HaveOccurred()) }) It("returns a LoginRequirement", func() { Expect(reqs).To(ContainElement(loginReq)) }) It("requires the user to target an org", func() { Expect(reqs).To(ContainElement(orgReq)) }) }) Context("when not provided a quota and space", func() { BeforeEach(func() {
loginRequirement = &passingRequirement{} factory.NewLoginRequirementReturns(loginRequirement) userRequirement = new(requirementsfakes.FakeUserRequirement) userRequirement.ExecuteReturns(nil) factory.NewUserRequirementReturns(userRequirement) organizationRequirement = new(requirementsfakes.FakeOrganizationRequirement) organizationRequirement.ExecuteReturns(nil) factory.NewOrganizationRequirementReturns(organizationRequirement) }) Describe("Requirements", func() { Context("when not provided exactly four args", func() { BeforeEach(func() { flagContext.Parse("the-user-name", "the-org-name", "the-space-name") }) It("fails with usage", func() { _, err := cmd.Requirements(factory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage. Requires USERNAME, ORG, SPACE, ROLE as arguments"}, []string{"NAME"}, []string{"USAGE"}, )) }) }) Context("when provided four args", func() { BeforeEach(func() {
BeforeEach(func() { cmdFlagMap = make(map[string]flags.FlagSet) cmdFlagMap["name"] = &flags.StringFlag{Name: "name", ShortName: "n", Usage: "test string flag"} cmdFlagMap["skip"] = &flags.BoolFlag{Name: "skip", Usage: "test bool flag"} cmdFlagMap["instance"] = &flags.IntFlag{Name: "instance", Usage: "test int flag"} cmdFlagMap["float"] = &flags.Float64Flag{Name: "float", Usage: "test float64 flag"} cmdFlagMap["skip2"] = &flags.BoolFlag{Name: "skip2", Usage: "test bool flag"} cmdFlagMap["slice"] = &flags.StringSliceFlag{Name: "slice", Usage: "test stringSlice flag"} fCtx = flags.NewFlagContext(cmdFlagMap) }) It("accepts flags with either single '-' or double '-' ", func() { err := fCtx.Parse("--name", "blue") Expect(err).NotTo(HaveOccurred()) err = fCtx.Parse("-name", "") Expect(err).NotTo(HaveOccurred()) }) It("sets a flag with it's full name", func() { err := fCtx.Parse("-name", "blue") Expect(err).NotTo(HaveOccurred()) Expect(fCtx.IsSet("name")).To(BeTrue()) Expect(fCtx.IsSet("n")).To(BeTrue()) Expect(fCtx.String("name")).To(Equal("blue")) Expect(fCtx.String("n")).To(Equal("blue")) })
requirementsFactory = new(requirementsfakes.FakeFactory) config = testconfig.NewRepositoryWithDefaults() deps = commandregistry.Dependency{ UI: ui, Config: config, PluginRepo: fakePluginRepo, } cmd = new(pluginrepo.RepoPlugins) cmd = cmd.SetDependency(deps, false).(*pluginrepo.RepoPlugins) flagContext = flags.NewFlagContext(cmd.MetaData().Flags) }) var callRepoPlugins = func(args ...string) error { err := flagContext.Parse(args...) if err != nil { return err } cmd.Execute(flagContext) return nil } Context("when using the default CF-Community repo", func() { BeforeEach(func() { config.SetPluginRepo(models.PluginRepo{ Name: "cf", URL: "http://plugins.cloudfoundry.org", }) })
minApiVersionReq = new(requirementsfakes.FakeRequirement) minApiVersionReq.ExecuteReturns(nil) reqFactory.NewMinAPIVersionRequirementReturns(minApiVersionReq) cmd = spacequota.CreateSpaceQuota{} flagContext = flags.NewFlagContext(cmd.MetaData().Flags) }) Describe("Requirements", func() { BeforeEach(func() { cmd.SetDependency(deps, false) }) Context("when not exactly one arg is provided", func() { It("fails", func() { flagContext.Parse() _, err := cmd.Requirements(reqFactory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"FAILED"}, []string{"Incorrect Usage. Requires an argument"}, )) }) }) Context("when provided exactly one arg", func() { var actualRequirements []requirements.Requirement var err error Context("when no flags are provided", func() { BeforeEach(func() {
cmd.SetDependency(deps, false) flagContext = flags.NewFlagContext(cmd.MetaData().Flags) factory = new(requirementsfakes.FakeFactory) loginRequirement = &passingRequirement{Name: "login-requirement"} factory.NewLoginRequirementReturns(loginRequirement) maxAPIVersionRequirement = &passingRequirement{Name: "max-api-version-requirement"} factory.NewMaxAPIVersionRequirementReturns(maxAPIVersionRequirement) }) Describe("Requirements", func() { Context("when not provided exactly one arg", func() { BeforeEach(func() { flagContext.Parse("service", "extra-arg") }) It("fails with usage", func() { _, err := cmd.Requirements(factory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"FAILED"}, []string{"Incorrect Usage. Requires an argument"}, )) }) }) Context("when provided exactly one arg", func() { BeforeEach(func() { flagContext.Parse("service")
GUID: "fake-domain-guid", Name: "fake-domain-name", } domainRequirement.GetDomainReturns(fakeDomain) serviceInstanceRequirement = new(requirementsfakes.FakeServiceInstanceRequirement) factory.NewServiceInstanceRequirementReturns(serviceInstanceRequirement) minAPIVersionRequirement = &passingRequirement{Name: "min-api-version-requirement"} factory.NewMinAPIVersionRequirementReturns(minAPIVersionRequirement) }) Describe("Requirements", func() { Context("when not provided exactly two args", func() { BeforeEach(func() { flagContext.Parse("domain-name") }) It("fails with usage", func() { _, err := cmd.Requirements(factory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"FAILED"}, []string{"Incorrect Usage. Requires DOMAIN and SERVICE_INSTANCE as arguments"}, )) }) }) Context("when provided exactly two args", func() { BeforeEach(func() { flagContext.Parse("domain-name", "service-instance")
endpointRequirement = &passingRequirement{Name: "endpoint-requirement"} factory.NewAPIEndpointRequirementReturns(endpointRequirement) }) Describe("Requirements", func() { It("returns an EndpointRequirement", func() { actualRequirements, err := cmd.Requirements(factory, flagContext) Expect(err).NotTo(HaveOccurred()) Expect(factory.NewAPIEndpointRequirementCallCount()).To(Equal(1)) Expect(actualRequirements).To(ContainElement(endpointRequirement)) }) Context("when not provided exactly zero args", func() { BeforeEach(func() { flagContext.Parse("domain-name") }) It("fails with usage", func() { var firstErr error reqs, err := cmd.Requirements(factory, flagContext) Expect(err).NotTo(HaveOccurred()) for _, req := range reqs { err := req.Execute() if err != nil { firstErr = err break } }
} cmd = &commands.Help{} cmd.SetDependency(deps, false) flagContext = flags.NewFlagContext(cmd.MetaData().Flags) fakeFactory = new(requirementsfakes.FakeFactory) }) AfterEach(func() { buffer.Close() }) Context("when no argument is provided", func() { It("prints the main help menu of the 'cf' app", func() { flagContext.Parse() err := cmd.Execute(flagContext) Expect(err).NotTo(HaveOccurred()) Eventually(buffer.Contents).Should(ContainSubstring("A command line tool to interact with Cloud Foundry")) Eventually(buffer).Should(gbytes.Say("CF_TRACE=true")) }) }) Context("when a command name is provided as an argument", func() { Context("When the command exists", func() { It("prints the usage help for the command", func() { flagContext.Parse("target") err := cmd.Execute(flagContext) Expect(err).NotTo(HaveOccurred())
factory.NewMinAPIVersionRequirementReturns(minAPIVersionRequirement) routingAPIRepo.ListRouterGroupsStub = func(cb func(models.RouterGroup) bool) error { for _, r := range routerGroups { if !cb(r) { break } } return nil } }) Describe("Requirements", func() { Context("when not provided exactly one arg", func() { BeforeEach(func() { flagContext.Parse("arg-1", "extra-arg") }) It("fails with usage", func() { _, err := cmd.Requirements(factory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage. Requires DOMAIN as an argument"}, []string{"NAME"}, []string{"USAGE"}, )) }) }) Context("when provided exactly one arg", func() { BeforeEach(func() {
domainRequirement = new(requirementsfakes.FakeDomainRequirement) domainRequirement.GetDomainReturns(models.DomainFields{ GUID: "domain-guid", Name: "domain-name", }) factory.NewDomainRequirementReturns(domainRequirement) minAPIVersionRequirement = &passingRequirement{} factory.NewMinAPIVersionRequirementReturns(minAPIVersionRequirement) }) Describe("Requirements", func() { Context("when not provided exactly two args", func() { BeforeEach(func() { err := flagContext.Parse("space-name") Expect(err).NotTo(HaveOccurred()) }) It("fails with usage", func() { _, err := cmd.Requirements(factory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage. Requires SPACE and DOMAIN as arguments"}, []string{"NAME"}, []string{"USAGE"}, )) }) }) Context("when provided exactly two args", func() {
Expect(usage).To(ContainElement(" cf delete-route DOMAIN --port PORT [-f]")) }) It("has a TCP route example", func() { Expect(usage).To(ContainElement(" cf delete-route example.com --port 50000 # example.com:50000")) }) It("has a TCP option", func() { Expect(usage).To(ContainElement(" --port Port used to identify the TCP route")) }) }) Describe("Requirements", func() { Context("when not provided exactly one arg", func() { BeforeEach(func() { flagContext.Parse("app-name", "extra-arg") }) It("fails with usage", func() { _, err := cmd.Requirements(factory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"FAILED"}, []string{"Incorrect Usage. Requires an argument"}, )) }) }) Context("when provided exactly one arg", func() { BeforeEach(func() { flagContext.Parse("domain-name")
loginRequirement = &passingRequirement{Name: "login-requirement"} reqFactory.NewLoginRequirementReturns(loginRequirement) targetedSpaceRequirement = &passingRequirement{Name: "targeted-space-requirement"} reqFactory.NewTargetedSpaceRequirementReturns(targetedSpaceRequirement) serviceInstanceRequirement = &requirementsfakes.FakeServiceInstanceRequirement{} reqFactory.NewServiceInstanceRequirementReturns(serviceInstanceRequirement) }) Describe("Requirements", func() { BeforeEach(func() { cmd.SetDependency(deps, pluginCall) }) Context("when not provided exactly 1 argument", func() { It("fails", func() { err := flagContext.Parse("too", "many") Expect(err).NotTo(HaveOccurred()) _, err = cmd.Requirements(reqFactory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage", "Requires an argument"}, )) }) }) Context("when provided exactly one arg", func() { var actualRequirements []requirements.Requirement BeforeEach(func() { err := flagContext.Parse("service-name") Expect(err).NotTo(HaveOccurred())
flagContext = flags.NewFlagContext(cmd.MetaData().Flags) factory = new(requirementsfakes.FakeFactory) loginRequirement = &passingRequirement{} factory.NewLoginRequirementReturns(loginRequirement) minAPIVersionRequirement = &passingRequirement{} factory.NewMinAPIVersionRequirementReturns(minAPIVersionRequirement) }) Describe("Requirements", func() { Context("when not provided exactly one arg", func() { BeforeEach(func() { flagContext.Parse("service-instance", "extra-arg") }) It("fails with usage", func() { _, err := cmd.Requirements(factory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage. Requires an argument"}, []string{"NAME"}, []string{"USAGE"}, )) }) }) Context("when provided exactly one arg", func() { BeforeEach(func() {
factory.NewTargetedSpaceRequirementReturns(targetedSpaceRequirement) minAPIVersionRequirement = &passingRequirement{Name: "min-api-version-requirement"} factory.NewMinAPIVersionRequirementReturns(minAPIVersionRequirement) }) It("has an alias of `csb`", func() { cmd := &servicebroker.CreateServiceBroker{} Expect(cmd.MetaData().ShortName).To(Equal("csb")) }) Describe("Requirements", func() { Context("when not provided exactly four args", func() { BeforeEach(func() { flagContext.Parse("service-broker") }) It("fails with usage", func() { _, err := cmd.Requirements(factory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"FAILED"}, []string{"Incorrect Usage. Requires SERVICE_BROKER, USERNAME, PASSWORD, URL as arguments"}, )) }) }) Context("when provided exactly four args", func() { BeforeEach(func() { flagContext.Parse("service-broker", "username", "password", "url")
factory = new(requirementsfakes.FakeFactory) loginRequirement = &passingRequirement{Name: "login-requirement"} factory.NewLoginRequirementReturns(loginRequirement) targetedOrgRequirement = new(requirementsfakes.FakeTargetedOrgRequirement) factory.NewTargetedOrgRequirementReturns(targetedOrgRequirement) minAPIVersionRequirement = &passingRequirement{Name: "min-api-version-requirement"} factory.NewMinAPIVersionRequirementReturns(minAPIVersionRequirement) }) Describe("Requirements", func() { Context("when not provided exactly two args", func() { BeforeEach(func() { flagContext.Parse("app-name") }) It("fails with usage", func() { _, err := cmd.Requirements(factory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"FAILED"}, []string{"Incorrect Usage. Requires host and domain as arguments"}, )) }) }) Context("when provided exactly two args", func() { BeforeEach(func() { flagContext.Parse("domain-name", "host-name")
loginReq.ExecuteReturns(nil) reqFactory.NewLoginRequirementReturns(loginReq) orgRequirement = new(requirementsfakes.FakeOrganizationRequirement) orgRequirement.ExecuteReturns(nil) reqFactory.NewOrganizationRequirementReturns(orgRequirement) cmd = organization.ShowOrg{} flagContext = flags.NewFlagContext(cmd.MetaData().Flags) cmd.SetDependency(deps, false) }) Describe("Requirements", func() { Context("when the wrong number of args are provided", func() { BeforeEach(func() { err := flagContext.Parse() Expect(err).NotTo(HaveOccurred()) }) It("fails with no args", func() { _, err := cmd.Requirements(reqFactory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"FAILED"}, []string{"Incorrect Usage. Requires an argument"}, )) }) }) Context("when provided exactly one arg", func() { var actualRequirements []requirements.Requirement
targetedSpaceRequirement = &passingRequirement{} factory.NewTargetedSpaceRequirementReturns(targetedSpaceRequirement) deaApplicationRequirement = new(requirementsfakes.FakeDEAApplicationRequirement) factory.NewDEAApplicationRequirementReturns(deaApplicationRequirement) app := models.Application{} app.InstanceCount = 1 app.GUID = "app-guid" app.Name = "app-name" deaApplicationRequirement.GetApplicationReturns(app) }) Describe("Requirements", func() { Context("when not provided one or two args", func() { BeforeEach(func() { flagContext.Parse("app-name", "the-path", "extra-arg") }) It("fails with usage", func() { _, err := cmd.Requirements(factory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"FAILED"}, []string{"Incorrect Usage. Requires an argument"}, )) }) }) Context("when provided exactly one arg", func() { BeforeEach(func() { flagContext.Parse("app-name")
factory = new(requirementsfakes.FakeFactory) loginRequirement = &passingRequirement{Name: "login-requirement"} factory.NewLoginRequirementReturns(loginRequirement) minAPIVersionRequirement = &passingRequirement{Name: "min-api-version-requirement"} factory.NewMinAPIVersionRequirementReturns(minAPIVersionRequirement) serviceInstanceRequirement = new(requirementsfakes.FakeServiceInstanceRequirement) factory.NewServiceInstanceRequirementReturns(serviceInstanceRequirement) }) Describe("Requirements", func() { Context("when not provided exactly one arg", func() { BeforeEach(func() { flagContext.Parse("service-instance", "extra-arg") }) It("fails with usage", func() { _, err := cmd.Requirements(factory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"FAILED"}, []string{"Incorrect Usage. Requires an argument"}, )) }) }) Context("when provided exactly one arg", func() { BeforeEach(func() { flagContext.Parse("service-instance")
loginRequirement = &passingRequirement{} factory.NewLoginRequirementReturns(loginRequirement) userRequirement = new(requirementsfakes.FakeUserRequirement) userRequirement.ExecuteReturns(nil) factory.NewUserRequirementReturns(userRequirement) organizationRequirement = new(requirementsfakes.FakeOrganizationRequirement) organizationRequirement.ExecuteReturns(nil) factory.NewOrganizationRequirementReturns(organizationRequirement) }) Describe("Requirements", func() { Context("when not provided exactly three args", func() { BeforeEach(func() { flagContext.Parse("the-user-name", "the-org-name") }) It("fails with usage", func() { _, err := cmd.Requirements(factory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage. Requires USERNAME, ORG, ROLE as arguments"}, []string{"NAME"}, []string{"USAGE"}, )) }) }) Context("when provided three args", func() { BeforeEach(func() {
fc = flags.New() fc.NewStringSliceFlag("L", "", "") fc.NewStringSliceFlag("command", "c", "") fc.NewIntFlag("app-instance-index", "i", "") fc.NewBoolFlag("skip-host-validation", "k", "") fc.NewBoolFlag("skip-remote-execution", "N", "") fc.NewBoolFlag("request-pseudo-tty", "t", "") fc.NewBoolFlag("force-pseudo-tty", "tt", "") fc.NewBoolFlag("disable-pseudo-tty", "T", "") args = []string{} parseError = nil }) JustBeforeEach(func() { err := fc.Parse(args...) Expect(err).NotTo(HaveOccurred()) opts, parseError = options.NewSSHOptions(fc) }) Context("when an app name is provided", func() { Context("as the only argument", func() { BeforeEach(func() { args = append(args, "app-1") }) It("populates the AppName field", func() { Expect(parseError).NotTo(HaveOccurred()) Expect(opts.AppName).To(Equal("app-1")) })
runCommand := func(args ...string) bool { return testcmd.RunCLICommand("buildpacks", args, requirementsFactory, updateCommandDependency, false, ui) } Context("when arguments are provided", func() { var cmd commandregistry.Command var flagContext flags.FlagContext BeforeEach(func() { cmd = &buildpack.ListBuildpacks{} cmd.SetDependency(deps, false) flagContext = flags.NewFlagContext(cmd.MetaData().Flags) }) It("should fail with usage", func() { flagContext.Parse("blahblah") reqs, err := cmd.Requirements(requirementsFactory, flagContext) Expect(err).NotTo(HaveOccurred()) err = testcmd.RunRequirements(reqs) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("Incorrect Usage")) Expect(err.Error()).To(ContainSubstring("No argument required")) }) }) It("fails requirements when login fails", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"}) Expect(runCommand()).To(BeFalse()) })
Expect(usage).To(ContainElement(" --random-port Create a random port for the TCP route")) }) It("shows the usage", func() { Expect(usage).To(ContainElement(" Map an HTTP route:")) Expect(usage).To(ContainElement(" cf map-route APP_NAME DOMAIN [--hostname HOSTNAME] [--path PATH]")) Expect(usage).To(ContainElement(" Map a TCP route:")) Expect(usage).To(ContainElement(" cf map-route APP_NAME DOMAIN (--port PORT | --random-port)")) }) }) Describe("Requirements", func() { Context("when not provided exactly two args", func() { BeforeEach(func() { flagContext.Parse("app-name") }) It("fails with usage", func() { _, err := cmd.Requirements(factory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage. Requires APP_NAME and DOMAIN as arguments"}, []string{"NAME"}, []string{"USAGE"}, )) }) }) Context("when provided exactly two args", func() { BeforeEach(func() {