github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+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/command_registry"
     6  	"github.com/cloudfoundry/cli/cf/configuration/core_config"
     7  	"github.com/cloudfoundry/cli/cf/models"
     8  	testcmd "github.com/cloudfoundry/cli/testhelpers/commands"
     9  	testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
    10  	testreq "github.com/cloudfoundry/cli/testhelpers/requirements"
    11  	testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  
    15  	. "github.com/cloudfoundry/cli/testhelpers/matchers"
    16  )
    17  
    18  var _ = Describe("stacks command", func() {
    19  	var (
    20  		ui                  *testterm.FakeUI
    21  		repo                *testapi.FakeStackRepository
    22  		config              core_config.Repository
    23  		requirementsFactory *testreq.FakeReqFactory
    24  		deps                command_registry.Dependency
    25  	)
    26  
    27  	updateCommandDependency := func(pluginCall bool) {
    28  		deps.Ui = ui
    29  		deps.Config = config
    30  		deps.RepoLocator = deps.RepoLocator.SetStackRepository(repo)
    31  		command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("stacks").SetDependency(deps, pluginCall))
    32  	}
    33  
    34  	BeforeEach(func() {
    35  		ui = &testterm.FakeUI{}
    36  		config = testconfig.NewRepositoryWithDefaults()
    37  		requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true}
    38  		repo = &testapi.FakeStackRepository{}
    39  	})
    40  
    41  	Describe("login requirements", func() {
    42  		It("fails if the user is not logged in", func() {
    43  			requirementsFactory.LoginSuccess = false
    44  
    45  			Expect(testcmd.RunCliCommand("stacks", []string{}, requirementsFactory, updateCommandDependency, false)).To(BeFalse())
    46  		})
    47  
    48  		It("should fail with usage when provided any arguments", func() {
    49  			requirementsFactory.LoginSuccess = true
    50  			Expect(testcmd.RunCliCommand("stacks", []string{"etcetc"}, requirementsFactory, updateCommandDependency, false)).To(BeFalse())
    51  			Expect(ui.Outputs).To(ContainSubstrings(
    52  				[]string{"FAILED"},
    53  				[]string{"Incorrect Usage."},
    54  			))
    55  		})
    56  	})
    57  
    58  	It("lists the stacks", func() {
    59  		stack1 := models.Stack{
    60  			Name:        "Stack-1",
    61  			Description: "Stack 1 Description",
    62  		}
    63  		stack2 := models.Stack{
    64  			Name:        "Stack-2",
    65  			Description: "Stack 2 Description",
    66  		}
    67  
    68  		repo.FindAllReturns([]models.Stack{stack1, stack2}, nil)
    69  		testcmd.RunCliCommand("stacks", []string{}, requirementsFactory, updateCommandDependency, false)
    70  
    71  		Expect(ui.Outputs).To(ContainSubstrings(
    72  			[]string{"Getting stacks in org", "my-org", "my-space", "my-user"},
    73  			[]string{"OK"},
    74  			[]string{"Stack-1", "Stack 1 Description"},
    75  			[]string{"Stack-2", "Stack 2 Description"},
    76  		))
    77  	})
    78  })