Esempio n. 1
0
		ui = new(testterm.FakeUI)
	})

	Context("when an org with the given name exists", func() {
		It("succeeds", func() {
			org := models.Organization{}
			org.Name = "my-org-name"
			org.Guid = "my-org-guid"
			orgRepo := &test_org.FakeOrganizationRepository{}
			orgReq := NewOrganizationRequirement("my-org-name", ui, orgRepo)

			orgRepo.ListOrgsReturns([]models.Organization{org}, nil)
			orgRepo.FindByNameReturns(org, nil)

			Expect(orgReq.Execute()).To(BeTrue())
			Expect(orgRepo.FindByNameArgsForCall(0)).To(Equal("my-org-name"))
			Expect(orgReq.GetOrganization()).To(Equal(org))
		})
	})

	It("fails when the org with the given name does not exist", func() {
		orgRepo := &test_org.FakeOrganizationRepository{}

		orgRepo.FindByNameReturns(models.Organization{}, errors.New("not found"))

		testassert.AssertPanic(testterm.QuietPanic, func() {
			NewOrganizationRequirement("foo", ui, orgRepo).Execute()
		})
	})
})
Esempio n. 2
0
	)

	BeforeEach(func() {
		ui = new(testterm.FakeUI)
	})

	Context("when a space with the given name exists", func() {
		It("succeeds", func() {
			space := models.Space{}
			space.Name = "awesome-sauce-space"
			space.Guid = "my-space-guid"
			spaceRepo := &testapi.FakeSpaceRepository{Spaces: []models.Space{space}}

			spaceReq := NewSpaceRequirement("awesome-sauce-space", ui, spaceRepo)

			Expect(spaceReq.Execute()).To(BeTrue())
			Expect(spaceRepo.FindByNameName).To(Equal("awesome-sauce-space"))
			Expect(spaceReq.GetSpace()).To(Equal(space))
		})
	})

	Context("when a space with the given name does not exist", func() {
		It("fails", func() {
			spaceRepo := &testapi.FakeSpaceRepository{FindByNameNotFound: true}
			testassert.AssertPanic(testterm.QuietPanic, func() {
				NewSpaceRequirement("foo", ui, spaceRepo).Execute()
			})
		})
	})
})
Esempio n. 3
0
	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() {
		domainRepo := &testapi.FakeDomainRepository{FindByNameInOrgApiResponse: errors.NewModelNotFoundError("Domain", "")}
		domainReq := NewDomainRequirement("example.com", ui, config, domainRepo)

		testassert.AssertPanic(testterm.QuietPanic, func() {
			domainReq.Execute()
		})
	})

	It("fails when an error occurs fetching the domain", func() {
		domainRepo := &testapi.FakeDomainRepository{FindByNameInOrgApiResponse: errors.NewWithError("", errors.New(""))}
		domainReq := NewDomainRequirement("example.com", ui, config, domainRepo)

		testassert.AssertPanic(testterm.QuietPanic, func() {
			domainReq.Execute()
		})
	})
})
Esempio n. 4
0
var _ = Describe("ApplicationRequirement", func() {
	var ui *testterm.FakeUI
	var appRepo *testApplication.FakeApplicationRepository

	BeforeEach(func() {
		ui = new(testterm.FakeUI)
		appRepo = &testApplication.FakeApplicationRepository{}
	})

	It("succeeds when an app with the given name exists", func() {
		app := models.Application{}
		app.Name = "my-app"
		app.Guid = "my-app-guid"
		appRepo.ReadReturns.App = app

		appReq := NewApplicationRequirement("foo", ui, appRepo)

		Expect(appReq.Execute()).To(BeTrue())
		Expect(appRepo.ReadArgs.Name).To(Equal("foo"))
		Expect(appReq.GetApplication()).To(Equal(app))
	})

	It("fails when an app with the given name cannot be found", func() {
		appRepo.ReadReturns.Error = errors.NewModelNotFoundError("app", "foo")

		testassert.AssertPanic(testterm.QuietPanic, func() {
			NewApplicationRequirement("foo", ui, appRepo).Execute()
		})
	})
})
Esempio n. 5
0
	)

	BeforeEach(func() {
		ui = new(testterm.FakeUI)
	})

	Context("when a service instance with the given name can be found", func() {
		It("succeeds", func() {
			instance := models.ServiceInstance{}
			instance.Name = "my-service"
			instance.Guid = "my-service-guid"
			repo := &testapi.FakeServiceRepo{FindInstanceByNameServiceInstance: instance}

			req := NewServiceInstanceRequirement("my-service", ui, repo)

			Expect(req.Execute()).To(BeTrue())
			Expect(repo.FindInstanceByNameName).To(Equal("my-service"))
			Expect(req.GetServiceInstance()).To(Equal(instance))
		})
	})

	Context("when a service instance with the given name can't be found", func() {
		It("fails", func() {
			repo := &testapi.FakeServiceRepo{FindInstanceByNameNotFound: true}
			testassert.AssertPanic(testterm.QuietPanic, func() {
				NewServiceInstanceRequirement("foo", ui, repo).Execute()
			})
		})
	})
})
Esempio n. 6
0
	)

	BeforeEach(func() {
		ui = new(testterm.FakeUI)
		config = testconfig.NewRepositoryWithDefaults()
	})

	Context("when the user has an org targeted", func() {
		It("succeeds", func() {
			req := NewTargetedOrgRequirement(ui, config)
			success := req.Execute()
			Expect(success).To(BeTrue())
		})
	})

	Context("when the user does not have an org targeted", func() {
		It("fails", func() {
			config.SetOrganizationFields(models.OrganizationFields{})

			testassert.AssertPanic(testterm.QuietPanic, func() {
				NewTargetedOrgRequirement(ui, config).Execute()
			})

			Expect(ui.Outputs).To(ContainSubstrings(
				[]string{"FAILED"},
				[]string{"No org targeted"},
			))
		})
	})
})
Esempio n. 7
0
	var (
		ui *testterm.FakeUI
	)

	BeforeEach(func() {
		ui = new(testterm.FakeUI)
	})

	Context("when a zone with the given name exists", func() {
		It("succeeds", func() {
			zone := models.Zone{}
			zone.Name = "my-zone-name"
			zone.Guid = "my-zone-guid"
			zoneRepo := &testapi.FakeZoneRepository{Zones: []models.Zone{zone}}
			zoneReq := NewZoneRequirement("my-zone-name", "my-org-guid", ui, zoneRepo)

			Expect(zoneReq.Execute()).To(BeTrue())
			Expect(zoneRepo.FindByNameName).To(Equal("my-zone-name"))
			Expect(zoneReq.GetZone()).To(Equal(zone))
		})
	})

	It("fails when the zone with the given name does not exist", func() {
		zoneRepo := &testapi.FakeZoneRepository{FindByNameNotFound: true}

		testassert.AssertPanic(testterm.QuietPanic, func() {
			NewZoneRequirement("foo", "my-org-guid", ui, zoneRepo).Execute()
		})
	})
})
Esempio n. 8
0
			of.Name = "of-name"

			output := io_helpers.CaptureOutput(func() {
				ui := NewUI(os.Stdin, NewTeePrinter())
				ui.ShowConfiguration(config)
			})

			Expect(output).To(ContainSubstrings([]string{"No", "space", "targeted", "-s SPACE"}))
		})
	})

	Describe("failing", func() {
		It("panics with a specific string", func() {
			io_helpers.CaptureOutput(func() {
				testassert.AssertPanic(QuietPanic, func() {
					NewUI(os.Stdin, NewTeePrinter()).Failed("uh oh")
				})
			})
		})

		It("does not use 'T' func to translate when it is not initialized", func() {
			t := i18n.T
			i18n.T = nil

			io_helpers.CaptureOutput(func() {
				testassert.AssertPanic(QuietPanic, func() {
					NewUI(os.Stdin, NewTeePrinter()).Failed("uh oh")
				})
			})

			i18n.T = t
Esempio n. 9
0
)

var _ = Describe("BuildpackRequirement", func() {
	var (
		ui *testterm.FakeUI
	)

	BeforeEach(func() {
		ui = new(testterm.FakeUI)
	})

	It("succeeds when a buildpack with the given name exists", func() {
		buildpack := models.Buildpack{Name: "my-buildpack"}
		buildpackRepo := &testapi.FakeBuildpackRepository{FindByNameBuildpack: buildpack}

		buildpackReq := NewBuildpackRequirement("my-buildpack", ui, buildpackRepo)

		Expect(buildpackReq.Execute()).To(BeTrue())
		Expect(buildpackRepo.FindByNameName).To(Equal("my-buildpack"))
		Expect(buildpackReq.GetBuildpack()).To(Equal(buildpack))
	})

	It("fails when the buildpack cannot be found", func() {
		buildpackRepo := &testapi.FakeBuildpackRepository{FindByNameNotFound: true}

		testassert.AssertPanic(testterm.QuietPanic, func() {
			NewBuildpackRequirement("foo", ui, buildpackRepo).Execute()
		})
	})
})