github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/service_key_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub"
     7  
     8  	"code.cloudfoundry.org/cli/integration/helpers"
     9  
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/gbytes"
    13  	. "github.com/onsi/gomega/gexec"
    14  )
    15  
    16  var _ = Describe("service-key command", func() {
    17  	var (
    18  		org             string
    19  		space           string
    20  		service         string
    21  		servicePlan     string
    22  		serviceInstance string
    23  		broker          *servicebrokerstub.ServiceBrokerStub
    24  	)
    25  
    26  	BeforeEach(func() {
    27  		org = helpers.NewOrgName()
    28  		space = helpers.NewSpaceName()
    29  		serviceInstance = helpers.PrefixedRandomName("si")
    30  
    31  		helpers.SetupCF(org, space)
    32  	})
    33  
    34  	AfterEach(func() {
    35  		helpers.QuickDeleteOrg(org)
    36  	})
    37  
    38  	When("the service key is not found", func() {
    39  		BeforeEach(func() {
    40  			broker = servicebrokerstub.EnableServiceAccess()
    41  			service = broker.FirstServiceOfferingName()
    42  			servicePlan = broker.FirstServicePlanName()
    43  
    44  			Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0))
    45  			Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0))
    46  		})
    47  
    48  		AfterEach(func() {
    49  			broker.Forget()
    50  		})
    51  
    52  		It("outputs an error message and exits 1", func() {
    53  			session := helpers.CF("service-key", serviceInstance, "some-service-key")
    54  			Eventually(session).Should(Say("FAILED"))
    55  			Eventually(session).Should(Say(fmt.Sprintf("No service key some-service-key found for service instance %s", serviceInstance)))
    56  			Eventually(session).Should(Exit(1))
    57  		})
    58  
    59  		When("the --guid option is given", func() {
    60  			It("outputs nothing and exits 0", func() {
    61  				session := helpers.CF("service-key", serviceInstance, "some-service-key", "--guid")
    62  				Eventually(session).Should(Exit(0))
    63  				Expect(session.Out.Contents()).To(Equal([]byte("\n")))
    64  				Expect(session.Err.Contents()).To(BeEmpty())
    65  			})
    66  		})
    67  	})
    68  })