本文整理汇总了Golang中github.com/cloudfoundry/cli/testhelpers/assert.AssertPanic函数的典型用法代码示例。如果您正苦于以下问题:Golang AssertPanic函数的具体用法?Golang AssertPanic怎么用?Golang AssertPanic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AssertPanic函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
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:
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:
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:
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:
)
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:
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:
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:
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:
)
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:
)
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:
)
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:
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:
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:
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:
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()
})
})
})
})