It("fails when the organization is not found", func() { orgRepo.FindByNameNotFound = true callTarget([]string{"-o", "my-organization"}) Expect(ui.Outputs).To(ContainSubstrings( []string{"FAILED"}, []string{"my-organization", "not found"}, )) expectOrgToBeCleared() expectSpaceToBeCleared() }) It("fails to target a space if no organization is targeted", func() { config.SetOrganizationFields(models.OrganizationFields{}) callTarget([]string{"-s", "my-space"}) Expect(ui.Outputs).To(ContainSubstrings( []string{"FAILED"}, []string{"An org must be targeted before targeting a space"}, )) expectSpaceToBeCleared() }) It("fails when the user doesn't have access to the space", func() { spaceRepo.FindByNameErr = true callTarget([]string{"-s", "my-space"})
testapi "github.com/cloudfoundry/cli/testhelpers/api" testassert "github.com/cloudfoundry/cli/testhelpers/assert" testconfig "github.com/cloudfoundry/cli/testhelpers/configuration" testterm "github.com/cloudfoundry/cli/testhelpers/terminal" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Testing with ginkgo", func() { var config configuration.ReadWriter var ui *testterm.FakeUI BeforeEach(func() { ui = new(testterm.FakeUI) config = testconfig.NewRepository() config.SetOrganizationFields(models.OrganizationFields{Guid: "the-org-guid"}) }) It("succeeds when the domain is found", func() { domain := models.DomainFields{Name: "example.com", Guid: "domain-guid"} domainRepo := &testapi.FakeDomainRepository{FindByNameInOrgDomain: domain} domainReq := NewDomainRequirement("example.com", ui, config, domainRepo) success := domainReq.Execute() Expect(success).To(BeTrue()) Expect(domainRepo.FindByNameInOrgName).To(Equal("example.com")) Expect(domainRepo.FindByNameInOrgGuid).To(Equal("the-org-guid")) Expect(domainReq.GetDomain()).To(Equal(domain)) }) It("fails when the domain is not found", func() {
}) Describe("updating the endpoints", func() { Context("when the API request is successful", func() { var ( org models.OrganizationFields space models.SpaceFields ) BeforeEach(func() { org.Name = "my-org" org.Guid = "my-org-guid" space.Name = "my-space" space.Guid = "my-space-guid" config.SetOrganizationFields(org) config.SetSpaceFields(space) testServerFn = validApiInfoEndpoint }) It("stores the data from the /info api in the config", func() { repo.UpdateEndpoint(testServer.URL) Expect(config.AccessToken()).To(Equal("")) Expect(config.AuthenticationEndpoint()).To(Equal("https://login.example.com")) Expect(config.LoggregatorEndpoint()).To(Equal("wss://loggregator.foo.example.org:4443")) Expect(config.ApiEndpoint()).To(Equal(testServer.URL)) Expect(config.ApiVersion()).To(Equal("42.0.0")) Expect(config.HasOrganization()).To(BeFalse()) Expect(config.HasSpace()).To(BeFalse()) })
Expect(testcmd.CommandDidPassRequirements).To(BeFalse()) }) It("fails with usage if no arguments are given", func() { runCommand() Expect(ui.FailedWithUsage).To(BeTrue()) }) Context("when logged in", func() { BeforeEach(func() { requirementsFactory.LoginSuccess = true }) Context("when deleting the currently targeted org", func() { It("untargets the deleted org", func() { config.SetOrganizationFields(org.OrganizationFields) runCommand("org-to-delete") Expect(config.OrganizationFields()).To(Equal(models.OrganizationFields{})) Expect(config.SpaceFields()).To(Equal(models.SpaceFields{})) }) }) Context("when deleting an org that is not targeted", func() { BeforeEach(func() { otherOrgFields := models.OrganizationFields{} otherOrgFields.Guid = "some-other-org-guid" otherOrgFields.Name = "some-other-org" config.SetOrganizationFields(otherOrgFields) spaceFields := models.SpaceFields{}
callRenameOrg([]string{"the-old-org-name", "the-new-org-name"}) Expect(testcmd.CommandDidPassRequirements).To(BeTrue()) }) It("renames an organization", func() { targetedOrgName := configRepo.OrganizationFields().Name callRenameOrg([]string{"the-old-org-name", "the-new-org-name"}) Expect(ui.Outputs).To(ContainSubstrings( []string{"Renaming org", "the-old-org-name", "the-new-org-name", "my-user"}, []string{"OK"}, )) Expect(requirementsFactory.OrganizationName).To(Equal("the-old-org-name")) Expect(orgRepo.RenameOrganizationGuid).To(Equal("the-old-org-guid")) Expect(orgRepo.RenameNewName).To(Equal("the-new-org-name")) Expect(configRepo.OrganizationFields().Name).To(Equal(targetedOrgName)) }) Describe("when the organization is currently targeted", func() { It("updates the name of the org in the config", func() { configRepo.SetOrganizationFields(models.OrganizationFields{ Guid: "the-old-org-guid", Name: "the-old-org-name", }) callRenameOrg([]string{"the-old-org-name", "the-new-org-name"}) Expect(configRepo.OrganizationFields().Name).To(Equal("the-new-org-name")) }) }) }) })
Expect(testcmd.CommandDidPassRequirements).To(BeFalse()) }) It("fails with usage if no arguments are given", func() { runCommand() Expect(ui.FailedWithUsage).To(BeTrue()) }) Context("when logged in", func() { BeforeEach(func() { requirementsFactory.LoginSuccess = true }) Context("when deleting the currently targeted org", func() { It("untargets the deleted org", func() { config.SetOrganizationFields(orgRepo.Organizations[0].OrganizationFields) runCommand("org-to-delete") Expect(config.OrganizationFields()).To(Equal(models.OrganizationFields{})) Expect(config.SpaceFields()).To(Equal(models.SpaceFields{})) }) }) Context("when deleting an org that is not targeted", func() { BeforeEach(func() { otherOrgFields := models.OrganizationFields{} otherOrgFields.Guid = "some-other-org-guid" otherOrgFields.Name = "some-other-org" config.SetOrganizationFields(otherOrgFields) spaceFields := models.SpaceFields{}
It("tells the user which api endpoint is set", func() { Expect(output).To(ContainSubstrings([]string{"API endpoint:", "https://test.example.org"})) }) It("tells the user the api version", func() { Expect(output).To(ContainSubstrings([]string{"API version:", "☃☃☃"})) }) It("tells the user which user is logged in", func() { Expect(output).To(ContainSubstrings([]string{"User:"******"my-user-email"})) }) Context("when an org is targeted", func() { BeforeEach(func() { config.SetOrganizationFields(models.OrganizationFields{ Name: "org-name", Guid: "org-guid", }) }) It("tells the user which org is targeted", func() { Expect(output).To(ContainSubstrings([]string{"Org:", "org-name"})) }) }) Context("when a space is targeted", func() { BeforeEach(func() { config.SetSpaceFields(models.SpaceFields{ Name: "my-space", Guid: "space-guid", }) })