Ejemplo n.º 1
0
var _ = Describe("Testing with ginkgo", func() {
	It("TestOrgReqExecute", func() {

		org := models.Organization{}
		org.Name = "my-org-name"
		org.Guid = "my-org-guid"
		orgRepo := &testapi.FakeOrgRepository{Organizations: []models.Organization{org}}
		ui := new(testterm.FakeUI)

		orgReq := NewOrganizationRequirement("my-org-name", ui, orgRepo)
		success := orgReq.Execute()

		Expect(success).To(BeTrue())
		Expect(orgRepo.FindByNameName).To(Equal("my-org-name"))
		Expect(orgReq.GetOrganization()).To(Equal(org))
	})

	It("TestOrgReqWhenOrgDoesNotExist", func() {

		orgRepo := &testapi.FakeOrgRepository{FindByNameNotFound: true}
		ui := new(testterm.FakeUI)

		orgReq := NewOrganizationRequirement("foo", ui, orgRepo)

		testassert.AssertPanic(testterm.FailedWasCalled, func() {
			orgReq.Execute()
		})
	})
})
Ejemplo n.º 2
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()
		})

		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"FAILED"},
			{"No space targeted"},
		})

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

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

		testassert.SliceContains(ui.Outputs, testassert.Lines{
Ejemplo n.º 3
0
	testassert "testhelpers/assert"
	testterm "testhelpers/terminal"
)

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

		instance := models.ServiceInstance{}
		instance.Name = "my-service"
		instance.Guid = "my-service-guid"
		repo := &testapi.FakeServiceRepo{FindInstanceByNameServiceInstance: instance}
		ui := new(testterm.FakeUI)

		req := NewServiceInstanceRequirement("foo", ui, repo)
		success := req.Execute()

		Expect(success).To(BeTrue())
		Expect(repo.FindInstanceByNameName).To(Equal("foo"))
		Expect(req.GetServiceInstance()).To(Equal(instance))
	})
	It("TestServiceInstanceReqExecuteWhenServiceInstanceNotFound", func() {

		repo := &testapi.FakeServiceRepo{FindInstanceByNameNotFound: true}
		ui := new(testterm.FakeUI)

		testassert.AssertPanic(testterm.FailedWasCalled, func() {
			NewServiceInstanceRequirement("foo", ui, repo).Execute()
		})
	})
})
Ejemplo n.º 4
0
			output := captureOutput(func() {
				ui := NewUI(os.Stdin)
				ui.ShowConfiguration(config)
			})

			testassert.SliceContains(output, testassert.Lines{
				{"No", "space", "targeted", "-s SPACE"},
			})
		})
	})

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

func simulateStdin(input string, block func(r io.Reader)) {
	reader, writer := io.Pipe()

	go func() {
		writer.Write([]byte(input))
		defer writer.Close()
	}()

	block(reader)
Ejemplo n.º 5
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()
		})
	})
})
Ejemplo n.º 6
0
	It("TestUserReqExecute", func() {
		user := models.UserFields{}
		user.Username = "******"
		user.Guid = "my-user-guid"

		userRepo := &testapi.FakeUserRepository{FindByUsernameUserFields: user}
		ui := new(testterm.FakeUI)

		userReq := NewUserRequirement("foo", ui, userRepo)
		success := userReq.Execute()

		Expect(success).To(BeTrue())
		Expect(userRepo.FindByUsernameUsername).To(Equal("foo"))
		Expect(userReq.GetUser()).To(Equal(user))
	})

	It("TestUserReqWhenUserDoesNotExist", func() {
		userRepo := &testapi.FakeUserRepository{FindByUsernameNotFound: true}
		ui := new(testterm.FakeUI)

		testassert.AssertPanic(testterm.FailedWasCalled, func() {
			NewUserRequirement("foo", ui, userRepo).Execute()
		})

		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"FAILED"},
			{"User not found"},
		})
	})
})