예제 #1
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
예제 #2
0
var _ = Describe("Testing with ginkgo", func() {

	It("TestApplicationReqExecute", func() {
		app := models.Application{}
		app.Name = "my-app"
		app.Guid = "my-app-guid"
		appRepo := &testapi.FakeApplicationRepository{}
		appRepo.ReadReturns.App = app
		ui := new(testterm.FakeUI)

		appReq := NewApplicationRequirement("foo", ui, appRepo)
		success := appReq.Execute()

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

	It("TestApplicationReqExecuteWhenApplicationNotFound", func() {
		appRepo := &testapi.FakeApplicationRepository{}
		appRepo.ReadReturns.Error = errors.NewModelNotFoundError("app", "foo")
		ui := new(testterm.FakeUI)

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

		testassert.AssertPanic(testterm.FailedWasCalled, func() {
			appReq.Execute()
		})
	})
})
예제 #3
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.FakeServiceRepository{}
			repo.FindInstanceByNameReturns(instance, nil)

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

			Expect(req.Execute()).To(BeTrue())
			Expect(repo.FindInstanceByNameArgsForCall(0)).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.FakeServiceRepository{}
			repo.FindInstanceByNameReturns(models.ServiceInstance{}, errors.NewModelNotFoundError("Service instance", "my-service"))
			testassert.AssertPanic(testterm.QuietPanic, func() {
				NewServiceInstanceRequirement("foo", ui, repo).Execute()
			})
		})
	})
})
예제 #4
0
		org := models.OrganizationFields{}
		org.Name = "my-org"
		org.Guid = "my-org-guid"
		space := models.SpaceFields{}
		space.Name = "my-space"
		space.Guid = "my-space-guid"
		config := testconfig.NewRepositoryWithDefaults()

		req := NewTargetedSpaceRequirement(ui, config)
		success := req.Execute()
		Expect(success).To(BeTrue())

		config.SetSpaceFields(models.SpaceFields{})

		testassert.AssertPanic(testterm.FailedWasCalled, func() {
			NewTargetedSpaceRequirement(ui, config).Execute()
		})

		Expect(ui.Outputs).To(ContainSubstrings(
			[]string{"FAILED"},
			[]string{"No space targeted"},
		))

		ui.ClearOutputs()
		config.SetOrganizationFields(models.OrganizationFields{})

		testassert.AssertPanic(testterm.FailedWasCalled, func() {
			NewTargetedSpaceRequirement(ui, config).Execute()
		})

		Expect(ui.Outputs).To(ContainSubstrings(
예제 #5
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.FailedWasCalled, func() {
			NewBuildpackRequirement("foo", ui, buildpackRepo).Execute()
		})
	})
})
예제 #6
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, nil)

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

		Expect(appReq.Execute()).To(BeTrue())
		Expect(appRepo.ReadArgsForCall(0)).To(Equal("foo"))
		Expect(appReq.GetApplication()).To(Equal(app))
	})

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

		testassert.AssertPanic(testterm.QuietPanic, func() {
			NewApplicationRequirement("foo", ui, appRepo).Execute()
		})
	})
})
예제 #7
0
		config core_config.ReadWriter
	)

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

	Context("when the user has targeted a space", func() {
		It("succeeds", func() {
			req := NewTargetedSpaceRequirement(ui, config)
			Expect(req.Execute()).To(BeTrue())
		})
	})

	Context("when the user does not have a space targeted", func() {
		It("fails", func() {
			config.SetSpaceFields(models.SpaceFields{})

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

			Expect(ui.Outputs).To(ContainSubstrings(
				[]string{"FAILED"},
				[]string{"No space targeted"},
			))
		})
	})
})
예제 #8
0
	var (
		ui *testterm.FakeUI
	)

	BeforeEach(func() {
		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 := &testapi.FakeOrgRepository{Organizations: []models.Organization{org}}
			orgReq := NewOrganizationRequirement("my-org-name", ui, orgRepo)

			Expect(orgReq.Execute()).To(BeTrue())
			Expect(orgRepo.FindByNameName).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 := &testapi.FakeOrgRepository{FindByNameNotFound: true}

		testassert.AssertPanic(testterm.FailedWasCalled, func() {
			NewOrganizationRequirement("foo", ui, orgRepo).Execute()
		})
	})
})
예제 #9
0
)

var _ = Describe("Testing with ginkgo", func() {
	It("TestBuildpackReqExecute", func() {

		buildpack := models.Buildpack{}
		buildpack.Name = "my-buildpack"
		buildpack.Guid = "my-buildpack-guid"
		buildpackRepo := &testapi.FakeBuildpackRepository{FindByNameBuildpack: buildpack}
		ui := new(testterm.FakeUI)

		buildpackReq := NewBuildpackRequirement("foo", ui, buildpackRepo)
		success := buildpackReq.Execute()

		Expect(success).To(BeTrue())
		Expect(buildpackRepo.FindByNameName).To(Equal("foo"))
		Expect(buildpackReq.GetBuildpack()).To(Equal(buildpack))
	})
	It("TestBuildpackReqExecuteWhenBuildpackNotFound", func() {

		buildpackRepo := &testapi.FakeBuildpackRepository{FindByNameNotFound: true}
		ui := new(testterm.FakeUI)

		buildpackReq := NewBuildpackRequirement("foo", ui, buildpackRepo)

		testassert.AssertPanic(testterm.FailedWasCalled, func() {
			buildpackReq.Execute()
		})
	})
})
예제 #10
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.FailedWasCalled, func() {
				NewServiceInstanceRequirement("foo", ui, repo).Execute()
			})
		})
	})
})
예제 #11
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()
		})
	})
})
예제 #12
0
파일: ui_test.go 프로젝트: GABONIA/cli
				ui.ShowConfiguration(config)
			})

			Expect(output).To(ContainSubstrings([]string{"No", "org", "targeted", "-o ORG"}))
		})

		It("prompts the user to target a space when no space is targeted", func() {
			of := models.OrganizationFields{}
			of.Guid = "of-guid"
			of.Name = "of-name"

			output := io_helpers.CaptureOutput(func() {
				ui := NewUI(os.Stdin)
				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(FailedWasCalled, func() {
					NewUI(os.Stdin).Failed("uh oh")
				})
			})
		})
	})
})
예제 #13
0
var _ = Describe("ApplicationRequirement", func() {
	var ui *testterm.FakeUI
	var appRepo *testapi.FakeApplicationRepository

	BeforeEach(func() {
		ui = new(testterm.FakeUI)
		appRepo = &testapi.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.FailedWasCalled, func() {
			NewApplicationRequirement("foo", ui, appRepo).Execute()
		})
	})
})
예제 #14
0
	It("succeeds when the domain is found", func() {
		domain := models.DomainFields{Name: "example.com", Guid: "domain-guid"}
		domainRepo := &testapi.FakeDomainRepository{FindByNameInOrgDomain: []models.DomainFields{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()
		})
	})
})
예제 #15
0
파일: space_test.go 프로젝트: vframbach/cli
	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{}
			spaceRepo.FindByNameReturns(space, nil)

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

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

	Context("when a space with the given name does not exist", func() {
		It("fails", func() {
			spaceRepo := &testapi.FakeSpaceRepository{}
			spaceRepo.FindByNameReturns(models.Space{}, errors.New("space-repo-err"))
			testassert.AssertPanic(testterm.QuietPanic, func() {
				NewSpaceRequirement("foo", ui, spaceRepo).Execute()
			})
		})
	})
})
예제 #16
0
	. "github.com/onsi/gomega"
)

var _ = Describe("Testing with ginkgo", func() {
	It("TestSpaceReqExecute", func() {

		space := models.Space{}
		space.Name = "awesome-sauce-space"
		space.Guid = "my-space-guid"
		spaceRepo := &testapi.FakeSpaceRepository{Spaces: []models.Space{space}}
		ui := new(testterm.FakeUI)

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

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

	It("TestSpaceReqExecuteWhenSpaceNotFound", func() {

		spaceRepo := &testapi.FakeSpaceRepository{FindByNameNotFound: true}
		ui := new(testterm.FakeUI)

		testassert.AssertPanic(testterm.FailedWasCalled, func() {
			NewSpaceRequirement("foo", ui, spaceRepo).Execute()
		})
	})
})
예제 #17
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()
		})
	})
})
예제 #18
0
파일: ui_test.go 프로젝트: yingkitw/cli
			of.Name = "of-name"

			output := io_helpers.CaptureOutput(func() {
				ui := NewUI(os.Stdin, os.Stdout, NewTeePrinter(os.Stdout), fakeLogger)
				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, os.Stdout, NewTeePrinter(os.Stdout), fakeLogger).Failed("uh oh")
				})
			})
		})

		Context("when 'T' func is not initialized", func() {
			var t go_i18n.TranslateFunc
			BeforeEach(func() {
				t = i18n.T
				i18n.T = nil
			})

			AfterEach(func() {
				i18n.T = t
			})
예제 #19
0
파일: ui_test.go 프로젝트: hail100/cli
				ui.ShowConfiguration(config)
			})

			Expect(output).To(ContainSubstrings([]string{"No", "org", "targeted", "-o ORG"}))
		})

		It("prompts the user to target a space when no space is targeted", func() {
			of := models.OrganizationFields{}
			of.Guid = "of-guid"
			of.Name = "of-name"

			output := io_helpers.CaptureOutput(func() {
				ui := NewUI(os.Stdin)
				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).Failed("uh oh")
				})
			})
		})
	})
})