github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/cf/commands/space/space_ssh_allowed_test.go (about)

     1  package space_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	"code.cloudfoundry.org/cli/cf/commandregistry"
     7  	"code.cloudfoundry.org/cli/cf/models"
     8  	"code.cloudfoundry.org/cli/cf/requirements"
     9  	"code.cloudfoundry.org/cli/cf/requirements/requirementsfakes"
    10  	testcmd "code.cloudfoundry.org/cli/cf/util/testhelpers/commands"
    11  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
    12  	testterm "code.cloudfoundry.org/cli/cf/util/testhelpers/terminal"
    13  	. "github.com/onsi/ginkgo"
    14  	. "github.com/onsi/gomega"
    15  )
    16  
    17  var _ = Describe("space-ssh-allowed command", func() {
    18  	var (
    19  		ui                  *testterm.FakeUI
    20  		requirementsFactory *requirementsfakes.FakeFactory
    21  		deps                commandregistry.Dependency
    22  	)
    23  
    24  	updateCommandDependency := func(pluginCall bool) {
    25  		deps.UI = ui
    26  		commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("space-ssh-allowed").SetDependency(deps, pluginCall))
    27  	}
    28  
    29  	runCommand := func(args ...string) bool {
    30  		return testcmd.RunCLICommand("space-ssh-allowed", args, requirementsFactory, updateCommandDependency, false, ui)
    31  	}
    32  
    33  	BeforeEach(func() {
    34  		ui = &testterm.FakeUI{}
    35  		requirementsFactory = new(requirementsfakes.FakeFactory)
    36  	})
    37  
    38  	Describe("requirements", func() {
    39  		It("fails with usage when called without enough arguments", func() {
    40  			requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
    41  
    42  			runCommand()
    43  			Expect(ui.Outputs()).To(ContainSubstrings(
    44  				[]string{"Incorrect Usage", "Requires", "argument"},
    45  			))
    46  
    47  		})
    48  
    49  		It("fails requirements when not logged in", func() {
    50  			requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
    51  			Expect(runCommand("my-space")).To(BeFalse())
    52  		})
    53  
    54  		It("does not pass requirements if org is not targeted", func() {
    55  			requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
    56  			targetedOrgReq := new(requirementsfakes.FakeTargetedOrgRequirement)
    57  			targetedOrgReq.ExecuteReturns(errors.New("no org targeted"))
    58  			requirementsFactory.NewTargetedOrgRequirementReturns(targetedOrgReq)
    59  
    60  			Expect(runCommand("my-space")).To(BeFalse())
    61  		})
    62  
    63  		It("does not pass requirements if space does not exist", func() {
    64  			requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
    65  			requirementsFactory.NewTargetedOrgRequirementReturns(new(requirementsfakes.FakeTargetedOrgRequirement))
    66  			spaceReq := new(requirementsfakes.FakeSpaceRequirement)
    67  			spaceReq.ExecuteReturns(errors.New("no space"))
    68  			requirementsFactory.NewSpaceRequirementReturns(spaceReq)
    69  
    70  			Expect(runCommand("my-space")).To(BeFalse())
    71  		})
    72  	})
    73  
    74  	Describe("space-ssh-allowed", func() {
    75  		var space models.Space
    76  
    77  		BeforeEach(func() {
    78  			requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
    79  			requirementsFactory.NewTargetedOrgRequirementReturns(new(requirementsfakes.FakeTargetedOrgRequirement))
    80  
    81  			space = models.Space{}
    82  			space.Name = "the-space-name"
    83  			space.GUID = "the-space-guid"
    84  			spaceReq := new(requirementsfakes.FakeSpaceRequirement)
    85  			spaceReq.GetSpaceReturns(space)
    86  			requirementsFactory.NewSpaceRequirementReturns(spaceReq)
    87  		})
    88  
    89  		Context("when SSH is enabled for the space", func() {
    90  			It("notifies the user", func() {
    91  				space.AllowSSH = true
    92  				spaceReq := new(requirementsfakes.FakeSpaceRequirement)
    93  				spaceReq.GetSpaceReturns(space)
    94  				requirementsFactory.NewSpaceRequirementReturns(spaceReq)
    95  
    96  				runCommand("the-space-name")
    97  
    98  				Expect(ui.Outputs()).To(ContainSubstrings([]string{"ssh support is enabled in space 'the-space-name'"}))
    99  			})
   100  		})
   101  
   102  		Context("when SSH is disabled for the space", func() {
   103  			It("notifies the user", func() {
   104  				runCommand("the-space-name")
   105  
   106  				Expect(ui.Outputs()).To(ContainSubstrings([]string{"ssh support is disabled in space 'the-space-name'"}))
   107  			})
   108  		})
   109  	})
   110  })