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

     1  package requirements_test
     2  
     3  import (
     4  	testapi "github.com/cloudfoundry/cli/cf/api/fakes"
     5  	"github.com/cloudfoundry/cli/cf/models"
     6  	. "github.com/cloudfoundry/cli/cf/requirements"
     7  	testassert "github.com/cloudfoundry/cli/testhelpers/assert"
     8  	testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("SpaceRequirement", func() {
    14  	var (
    15  		ui *testterm.FakeUI
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		ui = new(testterm.FakeUI)
    20  	})
    21  
    22  	Context("when a space with the given name exists", func() {
    23  		It("succeeds", func() {
    24  			space := models.Space{}
    25  			space.Name = "awesome-sauce-space"
    26  			space.Guid = "my-space-guid"
    27  			spaceRepo := &testapi.FakeSpaceRepository{Spaces: []models.Space{space}}
    28  
    29  			spaceReq := NewSpaceRequirement("awesome-sauce-space", ui, spaceRepo)
    30  
    31  			Expect(spaceReq.Execute()).To(BeTrue())
    32  			Expect(spaceRepo.FindByNameName).To(Equal("awesome-sauce-space"))
    33  			Expect(spaceReq.GetSpace()).To(Equal(space))
    34  		})
    35  	})
    36  
    37  	Context("when a space with the given name does not exist", func() {
    38  		It("fails", func() {
    39  			spaceRepo := &testapi.FakeSpaceRepository{FindByNameNotFound: true}
    40  			testassert.AssertPanic(testterm.QuietPanic, func() {
    41  				NewSpaceRequirement("foo", ui, spaceRepo).Execute()
    42  			})
    43  		})
    44  	})
    45  })