github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/commands/domain/create_shared_domain_test.go (about)

     1  package domain_test
     2  
     3  import (
     4  	testapi "github.com/cloudfoundry/cli/cf/api/fakes"
     5  	"github.com/cloudfoundry/cli/cf/configuration/core_config"
     6  	testcmd "github.com/cloudfoundry/cli/testhelpers/commands"
     7  	testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
     8  	testreq "github.com/cloudfoundry/cli/testhelpers/requirements"
     9  	testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
    10  
    11  	. "github.com/cloudfoundry/cli/cf/commands/domain"
    12  	. "github.com/cloudfoundry/cli/testhelpers/matchers"
    13  	. "github.com/onsi/ginkgo"
    14  	. "github.com/onsi/gomega"
    15  )
    16  
    17  var _ = Describe("Testing with ginkgo", func() {
    18  	var (
    19  		requirementsFactory *testreq.FakeReqFactory
    20  		ui                  *testterm.FakeUI
    21  		domainRepo          *testapi.FakeDomainRepository
    22  		configRepo          core_config.ReadWriter
    23  	)
    24  	BeforeEach(func() {
    25  		requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true}
    26  		domainRepo = &testapi.FakeDomainRepository{}
    27  		configRepo = testconfig.NewRepositoryWithAccessToken(core_config.TokenInfo{Username: "my-user"})
    28  	})
    29  
    30  	runCommand := func(args ...string) bool {
    31  		ui = new(testterm.FakeUI)
    32  		cmd := NewCreateSharedDomain(ui, configRepo, domainRepo)
    33  		return testcmd.RunCommand(cmd, args, requirementsFactory)
    34  	}
    35  
    36  	It("TestShareDomainRequirements", func() {
    37  		Expect(runCommand("example.com")).To(BeTrue())
    38  
    39  		requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: false}
    40  
    41  		Expect(runCommand("example.com")).To(BeFalse())
    42  	})
    43  
    44  	It("TestShareDomainFailsWithUsage", func() {
    45  		runCommand()
    46  		Expect(ui.FailedWithUsage).To(BeTrue())
    47  
    48  		runCommand("example.com")
    49  		Expect(ui.FailedWithUsage).To(BeFalse())
    50  	})
    51  
    52  	It("TestShareDomain", func() {
    53  		runCommand("example.com")
    54  
    55  		Expect(domainRepo.CreateSharedDomainName).To(Equal("example.com"))
    56  		Expect(ui.Outputs).To(ContainSubstrings(
    57  			[]string{"Creating shared domain", "example.com", "my-user"},
    58  			[]string{"OK"},
    59  		))
    60  	})
    61  })