github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/cf/commands/application/ssh_enabled_test.go (about)

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