github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/commands/environmentvariablegroup/running_environment_variable_group_test.go (about)

     1  package environmentvariablegroup_test
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/cf/api/environmentvariablegroups/environmentvariablegroupsfakes"
     5  	"code.cloudfoundry.org/cli/cf/commandregistry"
     6  	"code.cloudfoundry.org/cli/cf/commands/environmentvariablegroup"
     7  	"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
     8  	"code.cloudfoundry.org/cli/cf/flags"
     9  	"code.cloudfoundry.org/cli/cf/models"
    10  	"code.cloudfoundry.org/cli/cf/requirements"
    11  	"code.cloudfoundry.org/cli/cf/requirements/requirementsfakes"
    12  	testcmd "code.cloudfoundry.org/cli/cf/util/testhelpers/commands"
    13  	testconfig "code.cloudfoundry.org/cli/cf/util/testhelpers/configuration"
    14  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
    15  	testterm "code.cloudfoundry.org/cli/cf/util/testhelpers/terminal"
    16  	. "github.com/onsi/ginkgo"
    17  	. "github.com/onsi/gomega"
    18  )
    19  
    20  var _ = Describe("running-environment-variable-group command", func() {
    21  	var (
    22  		ui                           *testterm.FakeUI
    23  		requirementsFactory          *requirementsfakes.FakeFactory
    24  		configRepo                   coreconfig.Repository
    25  		environmentVariableGroupRepo *environmentvariablegroupsfakes.FakeRepository
    26  		deps                         commandregistry.Dependency
    27  	)
    28  
    29  	updateCommandDependency := func(pluginCall bool) {
    30  		deps.UI = ui
    31  		deps.RepoLocator = deps.RepoLocator.SetEnvironmentVariableGroupsRepository(environmentVariableGroupRepo)
    32  		deps.Config = configRepo
    33  		commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("running-environment-variable-group").SetDependency(deps, pluginCall))
    34  	}
    35  
    36  	BeforeEach(func() {
    37  		ui = &testterm.FakeUI{}
    38  		configRepo = testconfig.NewRepositoryWithDefaults()
    39  		requirementsFactory = new(requirementsfakes.FakeFactory)
    40  		environmentVariableGroupRepo = new(environmentvariablegroupsfakes.FakeRepository)
    41  	})
    42  
    43  	runCommand := func(args ...string) bool {
    44  		return testcmd.RunCLICommand("running-environment-variable-group", args, requirementsFactory, updateCommandDependency, false, ui)
    45  	}
    46  
    47  	Describe("requirements", func() {
    48  		It("requires the user to be logged in", func() {
    49  			requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
    50  			Expect(runCommand()).ToNot(HavePassedRequirements())
    51  		})
    52  
    53  		Context("when arguments are provided", func() {
    54  			var cmd commandregistry.Command
    55  			var flagContext flags.FlagContext
    56  
    57  			BeforeEach(func() {
    58  				cmd = &environmentvariablegroup.RunningEnvironmentVariableGroup{}
    59  				cmd.SetDependency(deps, false)
    60  				flagContext = flags.NewFlagContext(cmd.MetaData().Flags)
    61  			})
    62  
    63  			It("should fail with usage", func() {
    64  				flagContext.Parse("blahblah")
    65  
    66  				reqs, err := cmd.Requirements(requirementsFactory, flagContext)
    67  				Expect(err).NotTo(HaveOccurred())
    68  
    69  				err = testcmd.RunRequirements(reqs)
    70  				Expect(err).To(HaveOccurred())
    71  				Expect(err.Error()).To(ContainSubstring("Incorrect Usage"))
    72  				Expect(err.Error()).To(ContainSubstring("No argument required"))
    73  			})
    74  		})
    75  	})
    76  
    77  	Describe("when logged in", func() {
    78  		BeforeEach(func() {
    79  			requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
    80  			environmentVariableGroupRepo.ListRunningReturns(
    81  				[]models.EnvironmentVariable{
    82  					{Name: "abc", Value: "123"},
    83  					{Name: "def", Value: "456"},
    84  				}, nil)
    85  		})
    86  
    87  		It("Displays the running environment variable group", func() {
    88  			runCommand()
    89  
    90  			Expect(ui.Outputs()).To(ContainSubstrings(
    91  				[]string{"Retrieving the contents of the running environment variable group as my-user..."},
    92  				[]string{"OK"},
    93  				[]string{"Variable Name", "Assigned Value"},
    94  				[]string{"abc", "123"},
    95  				[]string{"def", "456"},
    96  			))
    97  		})
    98  	})
    99  })