github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/actor/v3action/process_summary_test.go (about)

     1  package v3action_test
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/actor/v3action"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
     6  
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("Process Actions", func() {
    12  	Describe("ProcessSummary", func() {
    13  		var summary ProcessSummary
    14  		BeforeEach(func() {
    15  			summary = ProcessSummary{
    16  				InstanceDetails: []ProcessInstance{
    17  					ProcessInstance{State: constant.ProcessInstanceRunning},
    18  					ProcessInstance{State: constant.ProcessInstanceRunning},
    19  					ProcessInstance{State: constant.ProcessInstanceDown},
    20  				},
    21  			}
    22  		})
    23  
    24  		Describe("TotalInstanceCount", func() {
    25  			It("returns the total number of instances", func() {
    26  				Expect(summary.TotalInstanceCount()).To(Equal(3))
    27  			})
    28  		})
    29  
    30  		Describe("HealthyInstanceCount", func() {
    31  			It("returns the total number of RUNNING instances", func() {
    32  				Expect(summary.HealthyInstanceCount()).To(Equal(2))
    33  			})
    34  		})
    35  	})
    36  
    37  	Describe("ProcessSummaries", func() {
    38  		var summaries ProcessSummaries
    39  
    40  		BeforeEach(func() {
    41  			summaries = ProcessSummaries{
    42  				{
    43  					Process: Process{
    44  						Type: "worker",
    45  					},
    46  					InstanceDetails: []ProcessInstance{
    47  						{State: constant.ProcessInstanceRunning},
    48  						{State: constant.ProcessInstanceDown},
    49  					},
    50  				},
    51  				{
    52  					Process: Process{
    53  						Type: "console",
    54  					},
    55  					InstanceDetails: []ProcessInstance{
    56  						{State: constant.ProcessInstanceRunning},
    57  					},
    58  				},
    59  				{
    60  					Process: Process{
    61  						Type: constant.ProcessTypeWeb,
    62  					},
    63  					InstanceDetails: []ProcessInstance{
    64  						{State: constant.ProcessInstanceRunning},
    65  						{State: constant.ProcessInstanceRunning},
    66  						{State: constant.ProcessInstanceDown},
    67  					},
    68  				},
    69  			}
    70  		})
    71  
    72  		Describe("Sort", func() {
    73  			It("sorts processes with web first and then alphabetically sorted", func() {
    74  				summaries.Sort()
    75  				Expect(summaries[0].Type).To(Equal(constant.ProcessTypeWeb))
    76  				Expect(summaries[1].Type).To(Equal("console"))
    77  				Expect(summaries[2].Type).To(Equal("worker"))
    78  			})
    79  		})
    80  
    81  		Describe("String", func() {
    82  			It("returns all processes and their instance count ", func() {
    83  				Expect(summaries.String()).To(Equal("web:2/3, console:1/1, worker:1/2"))
    84  			})
    85  		})
    86  	})
    87  })