github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+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: []Instance{ 17 Instance{State: "RUNNING"}, 18 Instance{State: "RUNNING"}, 19 Instance{State: "STOPPED"}, 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: []Instance{ 47 {State: "RUNNING"}, 48 {State: "STOPPED"}, 49 }, 50 }, 51 { 52 Process: Process{ 53 Type: "console", 54 }, 55 InstanceDetails: []Instance{ 56 {State: "RUNNING"}, 57 }, 58 }, 59 { 60 Process: Process{ 61 Type: constant.ProcessTypeWeb, 62 }, 63 InstanceDetails: []Instance{ 64 {State: "RUNNING"}, 65 {State: "RUNNING"}, 66 {State: "STOPPED"}, 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 })