github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/requirements/dea_application_test.go (about)

     1  package requirements_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	"code.cloudfoundry.org/cli/cf/models"
     7  	"code.cloudfoundry.org/cli/cf/requirements"
     8  
     9  	"code.cloudfoundry.org/cli/cf/api/applications/applicationsfakes"
    10  
    11  	. "github.com/onsi/ginkgo"
    12  	. "github.com/onsi/gomega"
    13  )
    14  
    15  var _ = Describe("DeaApplication", func() {
    16  	var (
    17  		req     requirements.DEAApplicationRequirement
    18  		appRepo *applicationsfakes.FakeRepository
    19  		appName string
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		appName = "fake-app-name"
    24  		appRepo = new(applicationsfakes.FakeRepository)
    25  		req = requirements.NewDEAApplicationRequirement(appName, appRepo)
    26  	})
    27  
    28  	Describe("GetApplication", func() {
    29  		It("returns an empty application", func() {
    30  			Expect(req.GetApplication()).To(Equal(models.Application{}))
    31  		})
    32  
    33  		Context("when the requirement has been executed", func() {
    34  			BeforeEach(func() {
    35  				app := models.Application{}
    36  				app.GUID = "fake-app-guid"
    37  				appRepo.ReadReturns(app, nil)
    38  
    39  				req.Execute()
    40  			})
    41  
    42  			It("returns the application", func() {
    43  				Expect(req.GetApplication().GUID).To(Equal("fake-app-guid"))
    44  			})
    45  		})
    46  	})
    47  
    48  	Describe("Execute", func() {
    49  		Context("when the returned application is a Diego application", func() {
    50  			BeforeEach(func() {
    51  				app := models.Application{}
    52  				app.Diego = true
    53  				appRepo.ReadReturns(app, nil)
    54  			})
    55  
    56  			It("fails with error", func() {
    57  				err := req.Execute()
    58  				Expect(err).To(HaveOccurred())
    59  				Expect(err.Error()).To(ContainSubstring("The app is running on the Diego backend, which does not support this command."))
    60  			})
    61  		})
    62  
    63  		Context("when the returned application is not a Diego application", func() {
    64  			BeforeEach(func() {
    65  				app := models.Application{}
    66  				app.Diego = false
    67  				appRepo.ReadReturns(app, nil)
    68  			})
    69  
    70  			It("succeeds", func() {
    71  				err := req.Execute()
    72  				Expect(err).NotTo(HaveOccurred())
    73  			})
    74  		})
    75  
    76  		Context("when finding the application results in an error", func() {
    77  			BeforeEach(func() {
    78  				appRepo.ReadReturns(models.Application{}, errors.New("find-err"))
    79  			})
    80  
    81  			It("fails with error", func() {
    82  				err := req.Execute()
    83  				Expect(err.Error()).To(ContainSubstring("find-err"))
    84  			})
    85  		})
    86  	})
    87  })