github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/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 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 {State: constant.ProcessInstanceRunning}, 18 {State: constant.ProcessInstanceRunning}, 19 {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 Sidecars: []Sidecar{ 64 {Name: "authenticator"}, 65 {Name: "clock"}, 66 }, 67 InstanceDetails: []ProcessInstance{ 68 {State: constant.ProcessInstanceRunning}, 69 {State: constant.ProcessInstanceRunning}, 70 {State: constant.ProcessInstanceDown}, 71 }, 72 }, 73 } 74 }) 75 76 Describe("Sort", func() { 77 It("sorts processes with web first and then alphabetically sorted", func() { 78 summaries.Sort() 79 Expect(summaries[0].Type).To(Equal(constant.ProcessTypeWeb)) 80 Expect(summaries[1].Type).To(Equal("console")) 81 Expect(summaries[2].Type).To(Equal("worker")) 82 }) 83 }) 84 85 Describe("String", func() { 86 It("returns all processes and their instance count ", func() { 87 Expect(summaries.String()).To(Equal("web:2/3, console:1/1, worker:1/2")) 88 }) 89 }) 90 }) 91 })