github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/cf/commands/application/get_health_check_test.go (about) 1 package application_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/cf/api/applications/applicationsfakes" 7 "code.cloudfoundry.org/cli/cf/commandregistry" 8 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 9 "code.cloudfoundry.org/cli/cf/models" 10 "code.cloudfoundry.org/cli/cf/requirements" 11 "code.cloudfoundry.org/cli/cf/requirements/requirementsfakes" 12 testcmd "code.cloudfoundry.org/cli/util/testhelpers/commands" 13 testconfig "code.cloudfoundry.org/cli/util/testhelpers/configuration" 14 testterm "code.cloudfoundry.org/cli/util/testhelpers/terminal" 15 16 . "code.cloudfoundry.org/cli/util/testhelpers/matchers" 17 . "github.com/onsi/ginkgo" 18 . "github.com/onsi/gomega" 19 ) 20 21 var _ = Describe("set-health-check command", func() { 22 var ( 23 ui *testterm.FakeUI 24 requirementsFactory *requirementsfakes.FakeFactory 25 appRepo *applicationsfakes.FakeRepository 26 configRepo coreconfig.Repository 27 deps commandregistry.Dependency 28 ) 29 30 BeforeEach(func() { 31 ui = &testterm.FakeUI{} 32 configRepo = testconfig.NewRepositoryWithDefaults() 33 requirementsFactory = new(requirementsfakes.FakeFactory) 34 appRepo = new(applicationsfakes.FakeRepository) 35 }) 36 37 updateCommandDependency := func(pluginCall bool) { 38 deps.UI = ui 39 deps.Config = configRepo 40 deps.RepoLocator = deps.RepoLocator.SetApplicationRepository(appRepo) 41 commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("get-health-check").SetDependency(deps, pluginCall)) 42 } 43 44 runCommand := func(args ...string) bool { 45 return testcmd.RunCLICommand("get-health-check", args, requirementsFactory, updateCommandDependency, false, ui) 46 } 47 48 Describe("requirements", func() { 49 It("fails with usage when called without enough arguments", func() { 50 requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) 51 52 runCommand() 53 Expect(ui.Outputs()).To(ContainSubstrings( 54 []string{"get-health-check"}, 55 []string{"Incorrect Usage", "Requires", "argument"}, 56 )) 57 }) 58 59 It("fails requirements when not logged in", func() { 60 requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"}) 61 Expect(runCommand("my-app")).To(BeFalse()) 62 }) 63 64 It("fails if a space is not targeted", func() { 65 requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) 66 requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Failing{Message: "not targeting space"}) 67 Expect(runCommand("my-app")).To(BeFalse()) 68 }) 69 }) 70 71 Describe("getting health_check_type", func() { 72 BeforeEach(func() { 73 requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) 74 requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Passing{}) 75 }) 76 77 Context("when application is not found", func() { 78 It("Fails", func() { 79 appRequirement := new(requirementsfakes.FakeApplicationRequirement) 80 appRequirement.ExecuteReturns(errors.New("no app")) 81 requirementsFactory.NewApplicationRequirementReturns(appRequirement) 82 Expect(runCommand("non-exist-app")).To(BeFalse()) 83 }) 84 }) 85 86 Context("when application exists", func() { 87 BeforeEach(func() { 88 app := models.Application{} 89 app.Name = "my-app" 90 app.GUID = "my-app-guid" 91 app.HealthCheckType = "port" 92 93 applicationReq := new(requirementsfakes.FakeApplicationRequirement) 94 applicationReq.GetApplicationReturns(app) 95 requirementsFactory.NewApplicationRequirementReturns(applicationReq) 96 }) 97 98 It("shows the health_check_type", func() { 99 runCommand("my-app") 100 101 Expect(ui.Outputs()).To(ContainSubstrings([]string{"Getting", "my-app", "health_check_type"})) 102 Expect(ui.Outputs()).To(ContainSubstrings([]string{"port"})) 103 }) 104 }) 105 }) 106 107 })