github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/requirements/application_test.go (about)

     1  package requirements_test
     2  
     3  import (
     4  	testApplication "github.com/cloudfoundry/cli/cf/api/applications/fakes"
     5  	"github.com/cloudfoundry/cli/cf/errors"
     6  	"github.com/cloudfoundry/cli/cf/models"
     7  	. "github.com/cloudfoundry/cli/cf/requirements"
     8  	testassert "github.com/cloudfoundry/cli/testhelpers/assert"
     9  	testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("ApplicationRequirement", func() {
    15  	var ui *testterm.FakeUI
    16  	var appRepo *testApplication.FakeApplicationRepository
    17  
    18  	BeforeEach(func() {
    19  		ui = new(testterm.FakeUI)
    20  		appRepo = &testApplication.FakeApplicationRepository{}
    21  	})
    22  
    23  	It("succeeds when an app with the given name exists", func() {
    24  		app := models.Application{}
    25  		app.Name = "my-app"
    26  		app.Guid = "my-app-guid"
    27  		appRepo.ReadReturns.App = app
    28  
    29  		appReq := NewApplicationRequirement("foo", ui, appRepo)
    30  
    31  		Expect(appReq.Execute()).To(BeTrue())
    32  		Expect(appRepo.ReadArgs.Name).To(Equal("foo"))
    33  		Expect(appReq.GetApplication()).To(Equal(app))
    34  	})
    35  
    36  	It("fails when an app with the given name cannot be found", func() {
    37  		appRepo.ReadReturns.Error = errors.NewModelNotFoundError("app", "foo")
    38  
    39  		testassert.AssertPanic(testterm.QuietPanic, func() {
    40  			NewApplicationRequirement("foo", ui, appRepo).Execute()
    41  		})
    42  	})
    43  })