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