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

     1  package application_test
     2  
     3  import (
     4  	testapi "github.com/cloudfoundry/cli/cf/api/fakes"
     5  	. "github.com/cloudfoundry/cli/cf/commands/application"
     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("list-apps command", func() {
    19  	var (
    20  		ui                  *testterm.FakeUI
    21  		configRepo          core_config.ReadWriter
    22  		appSummaryRepo      *testapi.FakeAppSummaryRepo
    23  		requirementsFactory *testreq.FakeReqFactory
    24  	)
    25  
    26  	BeforeEach(func() {
    27  		ui = &testterm.FakeUI{}
    28  		appSummaryRepo = &testapi.FakeAppSummaryRepo{}
    29  		configRepo = testconfig.NewRepositoryWithDefaults()
    30  		requirementsFactory = &testreq.FakeReqFactory{
    31  			LoginSuccess:         true,
    32  			TargetedSpaceSuccess: true,
    33  		}
    34  	})
    35  
    36  	runCommand := func(args ...string) bool {
    37  		cmd := NewListApps(ui, configRepo, appSummaryRepo)
    38  		return testcmd.RunCommand(cmd, args, requirementsFactory)
    39  	}
    40  
    41  	Describe("requirements", func() {
    42  		It("requires the user to be logged in", func() {
    43  			requirementsFactory.LoginSuccess = false
    44  
    45  			Expect(runCommand()).To(BeFalse())
    46  		})
    47  
    48  		It("requires the user to have a space targeted", func() {
    49  			requirementsFactory.TargetedSpaceSuccess = false
    50  
    51  			Expect(runCommand()).To(BeFalse())
    52  		})
    53  		It("should fail with usage when provided any arguments", func() {
    54  			requirementsFactory.LoginSuccess = true
    55  			requirementsFactory.TargetedSpaceSuccess = true
    56  			Expect(runCommand("blahblah")).To(BeFalse())
    57  			Expect(ui.FailedWithUsage).To(BeTrue())
    58  		})
    59  	})
    60  
    61  	Context("when the user is logged in and a space is targeted", func() {
    62  		It("lists apps in a table", func() {
    63  			app1Routes := []models.RouteSummary{
    64  				models.RouteSummary{
    65  					Host: "app1",
    66  					Domain: models.DomainFields{
    67  						Name: "cfapps.io",
    68  					},
    69  				},
    70  				models.RouteSummary{
    71  					Host: "app1",
    72  					Domain: models.DomainFields{
    73  						Name: "example.com",
    74  					},
    75  				}}
    76  
    77  			app2Routes := []models.RouteSummary{
    78  				models.RouteSummary{
    79  					Host:   "app2",
    80  					Domain: models.DomainFields{Name: "cfapps.io"},
    81  				}}
    82  
    83  			app := models.Application{}
    84  			app.Name = "Application-1"
    85  			app.State = "started"
    86  			app.RunningInstances = 1
    87  			app.InstanceCount = 1
    88  			app.Memory = 512
    89  			app.DiskQuota = 1024
    90  			app.Routes = app1Routes
    91  
    92  			app2 := models.Application{}
    93  			app2.Name = "Application-2"
    94  			app2.State = "started"
    95  			app2.RunningInstances = 1
    96  			app2.InstanceCount = 2
    97  			app2.Memory = 256
    98  			app2.DiskQuota = 1024
    99  			app2.Routes = app2Routes
   100  
   101  			appSummaryRepo.GetSummariesInCurrentSpaceApps = []models.Application{app, app2}
   102  
   103  			runCommand()
   104  
   105  			Expect(ui.Outputs).To(ContainSubstrings(
   106  				[]string{"Getting apps in", "my-org", "my-space", "my-user"},
   107  				[]string{"OK"},
   108  				[]string{"Application-1", "started", "1/1", "512M", "1G", "app1.cfapps.io", "app1.example.com"},
   109  				[]string{"Application-2", "started", "1/2", "256M", "1G", "app2.cfapps.io"},
   110  			))
   111  		})
   112  
   113  		Context("when an app's running instances is unknown", func() {
   114  			It("dipslays a '?' for running instances", func() {
   115  				appRoutes := []models.RouteSummary{
   116  					models.RouteSummary{
   117  						Host:   "app1",
   118  						Domain: models.DomainFields{Name: "cfapps.io"},
   119  					}}
   120  				app := models.Application{}
   121  				app.Name = "Application-1"
   122  				app.State = "started"
   123  				app.RunningInstances = -1
   124  				app.InstanceCount = 2
   125  				app.Memory = 512
   126  				app.DiskQuota = 1024
   127  				app.Routes = appRoutes
   128  
   129  				appSummaryRepo.GetSummariesInCurrentSpaceApps = []models.Application{app}
   130  
   131  				runCommand()
   132  
   133  				Expect(ui.Outputs).To(ContainSubstrings(
   134  					[]string{"Getting apps in", "my-org", "my-space", "my-user"},
   135  					[]string{"OK"},
   136  					[]string{"Application-1", "started", "?/2", "512M", "1G", "app1.cfapps.io"},
   137  				))
   138  			})
   139  		})
   140  
   141  		Context("when there are no apps", func() {
   142  			It("tells the user that there are no apps", func() {
   143  				runCommand()
   144  				Expect(ui.Outputs).To(ContainSubstrings(
   145  					[]string{"Getting apps in", "my-org", "my-space", "my-user"},
   146  					[]string{"OK"},
   147  					[]string{"No apps found"},
   148  				))
   149  			})
   150  		})
   151  	})
   152  })