github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/requirements/service_instance_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("ServiceInstanceRequirement", func() {
    14  	var (
    15  		ui *testterm.FakeUI
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		ui = new(testterm.FakeUI)
    20  	})
    21  
    22  	Context("when a service instance with the given name can be found", func() {
    23  		It("succeeds", func() {
    24  			instance := models.ServiceInstance{}
    25  			instance.Name = "my-service"
    26  			instance.Guid = "my-service-guid"
    27  			repo := &testapi.FakeServiceRepo{FindInstanceByNameServiceInstance: instance}
    28  
    29  			req := NewServiceInstanceRequirement("my-service", ui, repo)
    30  
    31  			Expect(req.Execute()).To(BeTrue())
    32  			Expect(repo.FindInstanceByNameName).To(Equal("my-service"))
    33  			Expect(req.GetServiceInstance()).To(Equal(instance))
    34  		})
    35  	})
    36  
    37  	Context("when a service instance with the given name can't be found", func() {
    38  		It("fails", func() {
    39  			repo := &testapi.FakeServiceRepo{FindInstanceByNameNotFound: true}
    40  			testassert.AssertPanic(testterm.QuietPanic, func() {
    41  				NewServiceInstanceRequirement("foo", ui, repo).Execute()
    42  			})
    43  		})
    44  	})
    45  })