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

     1  package application_test
     2  
     3  import (
     4  	"github.com/cloudfoundry/cli/cf/models"
     5  	testcmd "github.com/cloudfoundry/cli/testhelpers/commands"
     6  	testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
     7  	testreq "github.com/cloudfoundry/cli/testhelpers/requirements"
     8  	testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
     9  
    10  	. "github.com/cloudfoundry/cli/cf/commands/application"
    11  	"github.com/cloudfoundry/cli/cf/configuration/core_config"
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  )
    15  
    16  var _ = Describe("restart command", func() {
    17  	var (
    18  		ui                  *testterm.FakeUI
    19  		requirementsFactory *testreq.FakeReqFactory
    20  		starter             *testcmd.FakeApplicationStarter
    21  		stopper             *testcmd.FakeApplicationStopper
    22  		config              core_config.ReadWriter
    23  		app                 models.Application
    24  	)
    25  
    26  	BeforeEach(func() {
    27  		ui = &testterm.FakeUI{}
    28  		requirementsFactory = &testreq.FakeReqFactory{}
    29  		starter = &testcmd.FakeApplicationStarter{}
    30  		stopper = &testcmd.FakeApplicationStopper{}
    31  		config = testconfig.NewRepositoryWithDefaults()
    32  
    33  		app = models.Application{}
    34  		app.Name = "my-app"
    35  		app.Guid = "my-app-guid"
    36  	})
    37  
    38  	runCommand := func(args ...string) bool {
    39  		return testcmd.RunCommand(NewRestart(ui, config, starter, stopper), args, requirementsFactory)
    40  	}
    41  
    42  	Describe("requirements", func() {
    43  		It("fails with usage when not provided exactly one arg", func() {
    44  			requirementsFactory.LoginSuccess = true
    45  			runCommand()
    46  			Expect(ui.FailedWithUsage).To(BeTrue())
    47  		})
    48  
    49  		It("fails when not logged in", func() {
    50  			requirementsFactory.Application = app
    51  			requirementsFactory.TargetedSpaceSuccess = true
    52  
    53  			Expect(runCommand()).To(BeFalse())
    54  		})
    55  
    56  		It("fails when a space is not targeted", func() {
    57  			requirementsFactory.Application = app
    58  			requirementsFactory.LoginSuccess = true
    59  
    60  			Expect(runCommand()).To(BeFalse())
    61  		})
    62  	})
    63  
    64  	Context("when logged in, targeting a space, and an app name is provided", func() {
    65  		BeforeEach(func() {
    66  			requirementsFactory.Application = app
    67  			requirementsFactory.LoginSuccess = true
    68  			requirementsFactory.TargetedSpaceSuccess = true
    69  
    70  			stopper.ApplicationStopReturns(app, nil)
    71  		})
    72  
    73  		It("restarts the given app", func() {
    74  			runCommand("my-app")
    75  
    76  			application, orgName, spaceName := stopper.ApplicationStopArgsForCall(0)
    77  			Expect(application).To(Equal(app))
    78  			Expect(orgName).To(Equal(config.OrganizationFields().Name))
    79  			Expect(spaceName).To(Equal(config.SpaceFields().Name))
    80  
    81  			application, orgName, spaceName = starter.ApplicationStartArgsForCall(0)
    82  			Expect(application).To(Equal(app))
    83  			Expect(orgName).To(Equal(config.OrganizationFields().Name))
    84  			Expect(spaceName).To(Equal(config.SpaceFields().Name))
    85  
    86  			Expect(requirementsFactory.ApplicationName).To(Equal("my-app"))
    87  		})
    88  	})
    89  })