github.com/loafoe/cli@v7.1.0+incompatible/cf/requirements/space_test.go (about)

     1  package requirements_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	"code.cloudfoundry.org/cli/cf/api/spaces/spacesfakes"
     7  	"code.cloudfoundry.org/cli/cf/models"
     8  	. "code.cloudfoundry.org/cli/cf/requirements"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("SpaceRequirement", func() {
    14  	var spaceRepo *spacesfakes.FakeSpaceRepository
    15  	BeforeEach(func() {
    16  		spaceRepo = new(spacesfakes.FakeSpaceRepository)
    17  	})
    18  
    19  	Context("when a space with the given name exists", func() {
    20  		It("succeeds", func() {
    21  			space := models.Space{}
    22  			space.Name = "awesome-sauce-space"
    23  			space.GUID = "my-space-guid"
    24  			spaceRepo.FindByNameReturns(space, nil)
    25  
    26  			spaceReq := NewSpaceRequirement("awesome-sauce-space", spaceRepo)
    27  
    28  			err := spaceReq.Execute()
    29  			Expect(err).NotTo(HaveOccurred())
    30  			Expect(spaceReq.GetSpace()).To(Equal(space))
    31  			Expect(spaceRepo.FindByNameArgsForCall(0)).To(Equal("awesome-sauce-space"))
    32  		})
    33  	})
    34  
    35  	Context("when a space with the given name does not exist", func() {
    36  		It("errors", func() {
    37  			spaceError := errors.New("space-repo-err")
    38  			spaceRepo.FindByNameReturns(models.Space{}, spaceError)
    39  
    40  			err := NewSpaceRequirement("foo", spaceRepo).Execute()
    41  
    42  			Expect(err).To(HaveOccurred())
    43  			Expect(err).To(Equal(spaceError))
    44  		})
    45  	})
    46  })