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

     1  package commands_test
     2  
     3  import (
     4  	testapi "github.com/cloudfoundry/cli/cf/api/stacks/fakes"
     5  	. "github.com/cloudfoundry/cli/cf/commands"
     6  	"github.com/cloudfoundry/cli/cf/models"
     7  	testcmd "github.com/cloudfoundry/cli/testhelpers/commands"
     8  	testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
     9  	testreq "github.com/cloudfoundry/cli/testhelpers/requirements"
    10  	testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
    11  	. "github.com/onsi/ginkgo"
    12  	. "github.com/onsi/gomega"
    13  
    14  	. "github.com/cloudfoundry/cli/testhelpers/matchers"
    15  )
    16  
    17  var _ = Describe("stacks command", func() {
    18  	var (
    19  		ui                  *testterm.FakeUI
    20  		cmd                 ListStacks
    21  		repo                *testapi.FakeStackRepository
    22  		requirementsFactory *testreq.FakeReqFactory
    23  	)
    24  
    25  	BeforeEach(func() {
    26  		ui = &testterm.FakeUI{}
    27  		config := testconfig.NewRepositoryWithDefaults()
    28  		requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true}
    29  		repo = &testapi.FakeStackRepository{}
    30  		cmd = NewListStacks(ui, config, repo)
    31  	})
    32  
    33  	Describe("login requirements", func() {
    34  		It("fails if the user is not logged in", func() {
    35  			requirementsFactory.LoginSuccess = false
    36  
    37  			Expect(testcmd.RunCommand(cmd, []string{}, requirementsFactory)).To(BeFalse())
    38  		})
    39  	})
    40  
    41  	It("lists the stacks", func() {
    42  		stack1 := models.Stack{
    43  			Name:        "Stack-1",
    44  			Description: "Stack 1 Description",
    45  		}
    46  		stack2 := models.Stack{
    47  			Name:        "Stack-2",
    48  			Description: "Stack 2 Description",
    49  		}
    50  
    51  		repo.FindAllReturns([]models.Stack{stack1, stack2}, nil)
    52  		testcmd.RunCommand(cmd, []string{}, requirementsFactory)
    53  
    54  		Expect(ui.Outputs).To(ContainSubstrings(
    55  			[]string{"Getting stacks in org", "my-org", "my-space", "my-user"},
    56  			[]string{"OK"},
    57  			[]string{"Stack-1", "Stack 1 Description"},
    58  			[]string{"Stack-2", "Stack 2 Description"},
    59  		))
    60  	})
    61  })