deps.UI = ui deps.Config = configRepo deps.RepoLocator = deps.RepoLocator.SetApplicationRepository(appRepo) commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("enable-ssh").SetDependency(deps, pluginCall)) } runCommand := func(args ...string) bool { return testcmd.RunCLICommand("enable-ssh", args, requirementsFactory, updateCommandDependency, false, ui) } Describe("requirements", func() { It("fails with usage when called without enough arguments", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) runCommand() Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage", "Requires", "argument"}, )) }) It("fails requirements when not logged in", func() { Expect(runCommand("my-app", "none")).To(BeFalse()) }) It("fails if a space is not targeted", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Failing{Message: "not targeting space"}) Expect(runCommand("my-app", "none")).To(BeFalse()) }) })
ServiceInstanceURL: "fake-service-instance-url", }, Credentials: map[string]interface{}{ "username": "******", "password": "******", "host": "fake-host", "port": "3306", "database": "fake-db-name", "uri": "mysql://*****:*****@fake-host:3306/fake-db-name", }, } }) It("deletes service key successfully when '-f' option is provided", func() { Expect(callDeleteServiceKey([]string{"fake-service-instance", "fake-service-key", "-f"})).To(BeTrue()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Deleting key", "fake-service-key", "for service instance", "fake-service-instance", "as", "my-user"}, []string{"OK"})) }) It("deletes service key successfully when '-f' option is not provided and confirmed 'yes'", func() { ui.Inputs = append(ui.Inputs, "yes") Expect(callDeleteServiceKey([]string{"fake-service-instance", "fake-service-key"})).To(BeTrue()) Expect(ui.Prompts).To(ContainSubstrings([]string{"Really delete the service key", "fake-service-key"})) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Deleting key", "fake-service-key", "for service instance", "fake-service-instance", "as", "my-user"}, []string{"OK"})) }) It("skips to delete service key when '-f' option is not provided and confirmed 'no'", func() {
Apps: []models.ApplicationFields{app1, app2}, Port: 9090, } cb(route) cb(route2) cb(route3) return nil } }) It("lists routes", func() { runCommand() Expect(ui.Outputs()).To(BeInDisplayOrder( []string{"Getting routes for org my-org / space my-space as my-user ..."}, []string{"space", "host", "domain", "port", "path", "type", "apps", "service"}, )) Expect(terminal.Decolorize(ui.Outputs()[3])).To(MatchRegexp(`^my-space\s+hostname-1\s+example.com\s+dora\s+test-service\s*$`)) Expect(terminal.Decolorize(ui.Outputs()[4])).To(MatchRegexp(`^my-space\s+hostname-2\s+cookieclicker\.co\s+/foo\s+dora,bora\s*$`)) Expect(terminal.Decolorize(ui.Outputs()[5])).To(MatchRegexp(`^my-space\s+cookieclicker\.co\s+9090\s+tcp\s+dora,bora\s*$`)) }) }) Context("when there are routes in different spaces", func() { BeforeEach(func() { routeRepo.ListAllRoutesStub = func(cb func(models.Route) bool) error { space1 := models.SpaceFields{Name: "space-1"}
deps.UI = ui deps.Config = configRepo deps.RepoLocator = deps.RepoLocator.SetApplicationRepository(appRepo) commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("set-health-check").SetDependency(deps, pluginCall)) } runCommand := func(args ...string) bool { return testcmd.RunCLICommand("set-health-check", args, requirementsFactory, updateCommandDependency, false, ui) } Describe("requirements", func() { It("fails with usage when called without enough arguments", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) runCommand("FAKE_APP") Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage", "Requires", "argument"}, )) }) It("fails with usage when health_check_type is not provided with 'none' or 'port'", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) runCommand("FAKE_APP", "bad_type") Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage", "HEALTH_CHECK_TYPE", "port", "none"}, )) }) It("fails requirements when not logged in", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
func failedUpdate(ui *testterm.FakeUI, buildpackName string) { Expect(ui.Outputs()).To(ContainSubstrings( []string{"Updating buildpack", buildpackName}, []string{"FAILED"}, )) }
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() { Expect(func() { cmd.Requirements(factory, flagContext) }).To(Panic()) 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.Parse("service-instance") }) It("returns a LoginRequirement", func() { actualRequirements := cmd.Requirements(factory, flagContext) Expect(factory.NewLoginRequirementCallCount()).To(Equal(1))
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") }) It("returns a LoginRequirement", func() { actualRequirements, err := cmd.Requirements(factory, flagContext) Expect(err).NotTo(HaveOccurred()) Expect(factory.NewLoginRequirementCallCount()).To(Equal(1))
Expect(callCreateService([]string{"cleardb", "spark", "my-cleardb-service"})).To(BeFalse()) }) It("fails when a space is not targeted", func() { requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Failing{Message: "not targeted"}) Expect(callCreateService([]string{"cleardb", "spark", "my-cleardb-service"})).To(BeFalse()) }) }) It("successfully creates a service", func() { callCreateService([]string{"cleardb", "spark", "my-cleardb-service"}) spaceGUID, serviceName := serviceBuilder.GetServicesByNameForSpaceWithPlansArgsForCall(0) Expect(spaceGUID).To(Equal(config.SpaceFields().GUID)) Expect(serviceName).To(Equal("cleardb")) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Creating service instance", "my-cleardb-service", "my-org", "my-space", "my-user"}, []string{"OK"}, )) name, planGUID, _, _ := serviceRepo.CreateServiceInstanceArgsForCall(0) Expect(name).To(Equal("my-cleardb-service")) Expect(planGUID).To(Equal("cleardb-spark-guid")) }) Context("when passing in tags", func() { It("sucessfully creates a service and passes the tags as json", func() { callCreateService([]string{"cleardb", "spark", "my-cleardb-service", "-t", "tag1, tag2,tag3, tag4"}) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Creating service instance", "my-cleardb-service", "my-org", "my-space", "my-user"}, []string{"OK"},
config.SetPluginRepo(models.PluginRepo{ Name: "repo2", URL: "", }) }) Context("If repo name is provided by '-r'", func() { It("list plugins from just the named repo", func() { err := callRepoPlugins("-r", "repo2") Expect(err).NotTo(HaveOccurred()) Expect(fakePluginRepo.GetPluginsArgsForCall(0)[0].Name).To(Equal("repo2")) Expect(len(fakePluginRepo.GetPluginsArgsForCall(0))).To(Equal(1)) Expect(ui.Outputs()).To(ContainSubstrings([]string{"Getting plugins from repository 'repo2'"})) }) }) Context("If no repo name is provided", func() { It("list plugins from just the named repo", func() { err := callRepoPlugins() Expect(err).NotTo(HaveOccurred()) Expect(fakePluginRepo.GetPluginsArgsForCall(0)[0].Name).To(Equal("repo1")) Expect(len(fakePluginRepo.GetPluginsArgsForCall(0))).To(Equal(2)) Expect(fakePluginRepo.GetPluginsArgsForCall(0)[1].Name).To(Equal("repo2")) Expect(ui.Outputs()).To(ContainSubstrings([]string{"Getting plugins from all repositories"})) }) })
callRemovePluginRepo("repo1") Expect(len(config.PluginRepos())).To(Equal(1)) Expect(config.PluginRepos()[0].Name).To(Equal("repo2")) Expect(config.PluginRepos()[0].URL).To(Equal("http://server2.org:8080")) }) }) Context("When named repo doesn't exist", func() { BeforeEach(func() { config.SetPluginRepo(models.PluginRepo{ Name: "repo1", URL: "http://someserver1.com:1234", }) config.SetPluginRepo(models.PluginRepo{ Name: "repo2", URL: "http://server2.org:8080", }) }) It("doesn't change the config the config", func() { callRemovePluginRepo("fake-repo") Expect(len(config.PluginRepos())).To(Equal(2)) Expect(config.PluginRepos()[0].Name).To(Equal("repo1")) Expect(config.PluginRepos()[0].URL).To(Equal("http://someserver1.com:1234")) Expect(ui.Outputs()).To(ContainSubstrings([]string{"fake-repo", "does not exist as a repo"})) }) }) })
applicationReq := new(requirementsfakes.FakeApplicationRequirement) applicationReq.GetApplicationReturns(app) requirementsFactory.NewApplicationRequirementReturns(applicationReq) updateCommandDependency(logRepo) cmd := commandregistry.Commands.FindCommand("start").(*Start) cmd.StagingTimeout = 0 cmd.PingerThrottle = 1 cmd.StartupTimeout = 1 commandregistry.Register(cmd) }) It("can still respond to staging failures", func() { testcmd.RunCLICommandWithoutDependency("start", []string{"my-app"}, requirementsFactory, ui) Expect(ui.Outputs()).To(ContainSubstrings( []string{"my-app"}, []string{"FAILED"}, []string{"BLAH, FAILED"}, )) }) }) Context("when the timeout happens exactly when the connection is established", func() { var startWait *sync.WaitGroup BeforeEach(func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Passing{}) configRepo = testconfig.NewRepositoryWithDefaults() logRepo.TailLogsForStub = func(appGUID string, onConnect func(), logChan chan<- logs.Loggable, errChan chan<- error) {
curlRepo = new(apifakes.OldFakeCurlRepository) trace.LoggingToStdout = false }) runCurlWithInputs := func(args []string) bool { return testcmd.RunCLICommand("curl", args, requirementsFactory, updateCommandDependency, false, ui) } runCurlAsPluginWithInputs := func(args []string) bool { return testcmd.RunCLICommand("curl", args, requirementsFactory, updateCommandDependency, true, ui) } It("fails with usage when not given enough input", func() { runCurlWithInputs([]string{}) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage", "An argument is missing or not correctly enclosed"}, )) }) Context("requirements", func() { Context("when no api is set", func() { BeforeEach(func() { requirementsFactory.NewAPIEndpointRequirementReturns(requirements.Failing{Message: "no api set"}) }) It("fails", func() { Expect(runCurlWithInputs([]string{"/foo"})).To(BeFalse()) }) })
BeforeEach(func() { ui = &testterm.FakeUI{} deps := commandregistry.Dependency{ UI: ui, } cmd = &commands.Version{} cmd.SetDependency(deps, false) }) Describe("Execute", func() { var flagContext flags.FlagContext BeforeEach(func() { cf.Version = "5.0.0" cf.Name = "my-special-cf" cf.BuiltOnDate = "2016-02-29" }) It("prints the version", func() { cmd.Execute(flagContext) Expect(ui.Outputs()).To(Equal([]string{ "my-special-cf version 5.0.0-2016-02-29", })) }) }) })
runCommand := func(args ...string) bool { return testcmd.RunCLICommand("space-ssh-allowed", args, requirementsFactory, updateCommandDependency, false, ui) } BeforeEach(func() { ui = &testterm.FakeUI{} requirementsFactory = new(requirementsfakes.FakeFactory) }) Describe("requirements", func() { It("fails with usage when called without enough arguments", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) runCommand() Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage", "Requires", "argument"}, )) }) It("fails requirements when not logged in", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"}) Expect(runCommand("my-space")).To(BeFalse()) }) It("does not pass requirements if org is not targeted", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) targetedOrgReq := new(requirementsfakes.FakeTargetedOrgRequirement) targetedOrgReq.ExecuteReturns(errors.New("no org targeted")) requirementsFactory.NewTargetedOrgRequirementReturns(targetedOrgReq)
{ Name: "quota-unlimited-routes", MemoryLimit: 434, InstanceMemoryLimit: 1, RoutesLimit: -1, ServicesLimit: 2, NonBasicServicesAllowed: false, AppInstanceLimit: 10, ReservedRoutePorts: "4", }, }, nil) }) It("lists quotas", func() { Expect(Expect(runCommand()).To(HavePassedRequirements())).To(HavePassedRequirements()) Expect(terminal.Decolorize(ui.Outputs()[0])).To(Equal("Getting quotas as my-user...")) Expect(terminal.Decolorize(ui.Outputs()[1])).To(Equal("OK")) Expect(terminal.Decolorize(ui.Outputs()[3])).To(MatchRegexp("name\\s*total memory\\s*instance memory\\s*routes\\s*service instances\\s*paid plans\\s*app instances\\s*route ports\\s*")) Expect(terminal.Decolorize(ui.Outputs()[4])).To(MatchRegexp("quota-name\\s*1G\\s*512M\\s*111\\s*222\\s*allowed\\s*unlimited\\s*4")) Expect(terminal.Decolorize(ui.Outputs()[5])).To(MatchRegexp("quota-non-basic-not-allowed\\s*434M\\s*unlimited\\s*1\\s*2\\s*disallowed\\s*10\\s*4")) Expect(terminal.Decolorize(ui.Outputs()[6])).To(MatchRegexp("quota-unlimited-routes\\s*434M\\s*1M\\s*unlimited\\s*2\\s*disallowed\\s*10\\s*4")) }) It("displays unlimited services properly", func() { quotaRepo.FindAllReturns([]models.QuotaFields{ { Name: "quota-with-no-limit-to-services", MemoryLimit: 434, InstanceMemoryLimit: 1, RoutesLimit: 2, ServicesLimit: -1,
Expect(usage).To(ContainElement(" Unmap a TCP route:")) Expect(usage).To(ContainElement(" cf unmap-route APP_NAME DOMAIN --port 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, domain_name as arguments"}, []string{"NAME"}, []string{"USAGE"}, )) }) }) Context("when provided exactly two args", func() { BeforeEach(func() { flagContext.Parse("app-name", "domain-name") }) It("returns a LoginRequirement", func() { actualRequirements, err := cmd.Requirements(factory, 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")) }) }) }) Context("when logged in", func() { BeforeEach(func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) }) It("tells the user what it's about to do", func() { runCommand() Expect(ui.Outputs()).To(ContainSubstrings( []string{"Getting", "security groups", "my-user"}, )) }) It("handles api errors with an error message", func() { repo.FindAllReturns([]models.SecurityGroup{}, errors.New("YO YO YO, ERROR YO")) runCommand() Expect(ui.Outputs()).To(ContainSubstrings( []string{"FAILED"}, )) }) Context("when there are no security groups", func() { It("Should tell the user that there are no security groups", func() {
}, nil, ) }) It("refreshes the auth token", func() { runCommand() Expect(authRepo.RefreshAuthTokenCallCount()).To(Equal(1)) }) Context("when refreshing the auth token fails", func() { It("fails and returns the error", func() { authRepo.RefreshAuthTokenReturns("", errors.New("Refreshing went wrong")) runCommand() Expect(ui.Outputs()).To(ContainSubstrings( []string{"Refreshing went wrong"}, []string{"FAILED"}, )) }) }) Context("When no flags are provided", func() { It("tells the user it is obtaining the service access", func() { runCommand() Expect(ui.Outputs()).To(ContainSubstrings( []string{"Getting service access as", "my-user"}, )) }) It("prints all of the brokers", func() {
deps.RepoLocator = deps.RepoLocator.SetSpaceRepository(spaceRepo) commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("disallow-space-ssh").SetDependency(deps, pluginCall)) } runCommand := func(args ...string) bool { return testcmd.RunCLICommand("disallow-space-ssh", args, requirementsFactory, updateCommandDependency, false, ui) } Describe("requirements", func() { BeforeEach(func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) }) It("fails with usage when called without enough arguments", func() { runCommand() Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage", "Requires", "argument"}, )) }) It("fails requirements when not logged in", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"}) Expect(runCommand("my-space")).To(BeFalse()) }) It("does not pass requirements if org is not targeted", func() { targetedOrgReq := new(requirementsfakes.FakeTargetedOrgRequirement) targetedOrgReq.ExecuteReturns(errors.New("no org targeted")) requirementsFactory.NewTargetedOrgRequirementReturns(targetedOrgReq)
updateCommandDependency := func(pluginCall bool) { deps.UI = ui deps.Config = configRepo commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("ssh-enabled").SetDependency(deps, pluginCall)) } runCommand := func(args ...string) bool { return testcmd.RunCLICommand("ssh-enabled", args, requirementsFactory, updateCommandDependency, false, ui) } Describe("requirements", func() { It("fails with usage when called without enough arguments", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) runCommand() Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage", "Requires", "argument"}, )) }) It("fails requirements when not logged in", func() { Expect(runCommand("my-app", "none")).To(BeFalse()) }) It("fails if a space is not targeted", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Failing{Message: "not targeting space"}) Expect(runCommand("my-app", "none")).To(BeFalse()) }) })
}, }, nil } return []models.V3Route{ { Host: "route-2-host", Path: "", }, }, nil } }) It("prints a table of the results", func() { Expect(runCLIErr).NotTo(HaveOccurred()) outputs := make([]string, len(ui.Outputs())) for i := range ui.Outputs() { outputs[i] = terminal.Decolorize(ui.Outputs()[i]) } Expect(outputs).To(ConsistOf( MatchRegexp(`name.*requested state.*instances.*memory.*disk.*urls`), MatchRegexp("app-1-name.*stopped.*1.*1G.*2G.*route-1-host/route-1-path, route-1-host-2"), MatchRegexp("app-2-name.*running.*2.*512M.*1G.*route-2-host"), )) }) }) Context("when getting the routes fails", func() { BeforeEach(func() { repository.GetRoutesReturns([]models.V3Route{}, errors.New("get-routes-err")) })
Expect(runCLIErr.Error()).To(ContainSubstring("--skip-ssl-validation")) }) }) Context("when the user does not provide an endpoint", func() { Context("when the endpoint is set in the config", func() { BeforeEach(func() { config.SetAPIEndpoint("https://api.run.pivotal.io") config.SetAPIVersion("2.0") config.SetSSLDisabled(true) }) It("prints out the api endpoint and appropriately sets the config", func() { callApi([]string{}) Expect(ui.Outputs()).To(ContainSubstrings([]string{"https://api.run.pivotal.io", "2.0"})) Expect(config.IsSSLDisabled()).To(BeTrue()) }) Context("when the --unset flag is passed", func() { It("unsets the APIEndpoint", func() { callApi([]string{"--unset"}) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Unsetting api endpoint..."}, []string{"OK"}, []string{"No api endpoint set."}, )) Expect(config.APIEndpoint()).To(Equal("")) }) })
func successfulUpdate(ui *testterm.FakeUI, buildpackName string) { Expect(ui.Outputs()).To(ContainSubstrings( []string{"Updating buildpack", buildpackName}, []string{"OK"}, )) }
ui = &testterm.FakeUI{} configRepo = testconfig.NewRepositoryWithDefaults() logsRepo = new(logsfakes.FakeRepository) requirementsFactory = new(requirementsfakes.FakeFactory) }) runCommand := func(args ...string) bool { return testcmd.RunCLICommand("logs", args, requirementsFactory, updateCommandDependency, false, ui) } Describe("requirements", func() { It("fails with usage when called without one argument", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) runCommand() Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage", "Requires an argument"}, )) }) It("fails requirements when not logged in", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Failing{}) Expect(runCommand("my-app")).To(BeFalse()) }) It("fails if a space is not targeted", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Failing{Message: "not targeting space"}) Expect(runCommand("--recent", "my-app")).To(BeFalse()) })
app = models.Application{} app.Name = "my-app" app.GUID = "my-app-guid" app.State = "started" }) JustBeforeEach(func() { appRepo.ReadReturns(app, nil) applicationReq := new(requirementsfakes.FakeApplicationRequirement) applicationReq.GetApplicationReturns(app) requirementsFactory.NewApplicationRequirementReturns(applicationReq) }) It("fails with usage when the app name is not given", func() { runCommand() Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage", "Requires an argument"}, )) }) It("stops the app with the given name", func() { runCommand("my-app") Expect(ui.Outputs()).To(ContainSubstrings( []string{"Stopping app", "my-app", "my-org", "my-space", "my-user"}, []string{"OK"}, )) appGUID, _ := appRepo.UpdateArgsForCall(0) Expect(appGUID).To(Equal("my-app-guid")) })
BeforeEach(func() { requirementsFactory = new(requirementsfakes.FakeFactory) requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) repo = new(apifakes.OldFakeBuildpackRepository) bitsRepo = new(apifakes.FakeBuildpackBitsRepository) ui = &testterm.FakeUI{} }) It("fails requirements when the user is not logged in", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"}) Expect(testcmd.RunCLICommand("create-buildpack", []string{"my-buildpack", "my-dir", "0"}, requirementsFactory, updateCommandDependency, false, ui)).To(BeFalse()) }) It("fails with usage when given fewer than three arguments", func() { testcmd.RunCLICommand("create-buildpack", []string{}, requirementsFactory, updateCommandDependency, false, ui) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage", "Requires", "arguments"}, )) }) Context("when a file is provided", func() { It("prints error and do not call create buildpack", func() { bitsRepo.CreateBuildpackZipFileReturns(nil, "", fmt.Errorf("create buildpack error")) testcmd.RunCLICommand("create-buildpack", []string{"my-buildpack", "file", "5"}, requirementsFactory, updateCommandDependency, false, ui) Expect(ui.Outputs()).To(ContainSubstrings([]string{"FAILED"})) Expect(ui.Outputs()).To(ContainSubstrings([]string{"Failed to create a local temporary zip file for the buildpack"})) Expect(ui.Outputs()).NotTo(ContainSubstrings([]string{"Creating buildpack"})) })
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() { flagContext.Parse("myquota") actualRequirements, err = cmd.Requirements(reqFactory, flagContext) Expect(err).NotTo(HaveOccurred())
deps.UI = ui deps.Config = configRepo deps.RepoLocator = deps.RepoLocator.SetApplicationRepository(appRepo) commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("get-health-check").SetDependency(deps, pluginCall)) } runCommand := func(args ...string) bool { return testcmd.RunCLICommand("get-health-check", args, requirementsFactory, updateCommandDependency, false, ui) } Describe("requirements", func() { It("fails with usage when called without enough arguments", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) runCommand() Expect(ui.Outputs()).To(ContainSubstrings( []string{"get-health-check"}, []string{"Incorrect Usage", "Requires", "argument"}, )) }) It("fails requirements when not logged in", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"}) Expect(runCommand("my-app")).To(BeFalse()) }) It("fails if a space is not targeted", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Failing{Message: "not targeting space"}) Expect(runCommand("my-app")).To(BeFalse()) })
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()) Expect(func() { cmd.Requirements(reqFactory, flagContext) }).To(Panic()) 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()) actualRequirements = cmd.Requirements(reqFactory, flagContext) }) It("returns a LoginRequirement", func() {
Context("If --checksum flag is provided", func() { It("computes and prints the sha1 checksum of the binary", func() { config.PluginsReturns(map[string]pluginconfig.PluginMetadata{ "Test1": { Location: "../../../fixtures/plugins/test_1.go", Version: plugin.VersionType{Major: 1, Minor: 2, Build: 3}, Commands: []plugin.Command{ {Name: "test_1_cmd1", HelpText: "help text for test_1_cmd1"}, }, }, }) runCommand("--checksum") Expect(ui.Outputs()).To(ContainSubstrings( []string{"Plugin Name", "Version", "sha1", "Command Help"}, )) }) }) Context("when arguments are provided", func() { var cmd commandregistry.Command var flagContext flags.FlagContext BeforeEach(func() { cmd = &plugincmd.Plugins{} cmd.SetDependency(deps, false) flagContext = flags.NewFlagContext(cmd.MetaData().Flags) })