code.cloudfoundry.org/cli@v7.1.0+incompatible/cf/net/warnings_collector_test.go (about) 1 package net_test 2 3 import ( 4 "os" 5 6 "code.cloudfoundry.org/cli/cf/net" 7 "code.cloudfoundry.org/cli/cf/net/netfakes" 8 "code.cloudfoundry.org/cli/cf/terminal/terminalfakes" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("WarningsCollector", func() { 14 var ( 15 ui *terminalfakes.FakeUI 16 oldRaiseErrorValue string 17 warningsCollector net.WarningsCollector 18 ) 19 20 BeforeEach(func() { 21 ui = new(terminalfakes.FakeUI) 22 }) 23 24 Describe("PrintWarnings", func() { 25 BeforeEach(func() { 26 oldRaiseErrorValue = os.Getenv("CF_RAISE_ERROR_ON_WARNINGS") 27 }) 28 29 AfterEach(func() { 30 os.Setenv("CF_RAISE_ERROR_ON_WARNINGS", oldRaiseErrorValue) 31 }) 32 33 Context("when the CF_RAISE_ERROR_ON_WARNINGS environment variable is set", func() { 34 BeforeEach(func() { 35 os.Setenv("CF_RAISE_ERROR_ON_WARNINGS", "true") 36 }) 37 38 Context("when there are warnings", func() { 39 BeforeEach(func() { 40 warning_producer_one := new(netfakes.FakeWarningProducer) 41 warning_producer_one.WarningsReturns([]string{"something"}) 42 warningsCollector = net.NewWarningsCollector(ui, warning_producer_one) 43 }) 44 45 It("returns an error", func() { 46 err := warningsCollector.PrintWarnings() 47 Expect(err).To(HaveOccurred()) 48 }) 49 }) 50 51 Context("when there are no warnings", func() { 52 BeforeEach(func() { 53 warningsCollector = net.NewWarningsCollector(ui) 54 }) 55 56 It("does not return an error", func() { 57 err := warningsCollector.PrintWarnings() 58 Expect(err).ToNot(HaveOccurred()) 59 }) 60 }) 61 }) 62 63 Context("when the CF_RAISE_ERROR_ON_WARNINGS environment variable is not set", func() { 64 BeforeEach(func() { 65 os.Setenv("CF_RAISE_ERROR_ON_WARNINGS", "") 66 }) 67 68 It("does not return an error", func() { 69 warning_producer_one := new(netfakes.FakeWarningProducer) 70 warning_producer_one.WarningsReturns([]string{"Hello", "Darling"}) 71 warningsCollector := net.NewWarningsCollector(ui, warning_producer_one) 72 73 err := warningsCollector.PrintWarnings() 74 Expect(err).ToNot(HaveOccurred()) 75 }) 76 77 It("does not print out duplicate warnings", func() { 78 warning_producer_one := new(netfakes.FakeWarningProducer) 79 warning_producer_one.WarningsReturns([]string{"Hello Darling"}) 80 warning_producer_two := new(netfakes.FakeWarningProducer) 81 warning_producer_two.WarningsReturns([]string{"Hello Darling"}) 82 warningsCollector := net.NewWarningsCollector(ui, warning_producer_one, warning_producer_two) 83 84 warningsCollector.PrintWarnings() 85 Expect(ui.WarnCallCount()).To(Equal(1)) 86 Expect(ui.WarnArgsForCall(0)).To(ContainSubstring("Hello Darling")) 87 }) 88 89 It("does not print out Endpoint deprecated warnings", func() { 90 warning_producer_one := new(netfakes.FakeWarningProducer) 91 warning_producer_one.WarningsReturns([]string{"Endpoint deprecated"}) 92 warning_producer_two := new(netfakes.FakeWarningProducer) 93 warning_producer_two.WarningsReturns([]string{"A warning"}) 94 warningsCollector := net.NewWarningsCollector(ui, warning_producer_one, warning_producer_two) 95 96 warningsCollector.PrintWarnings() 97 Expect(ui.WarnCallCount()).To(Equal(1)) 98 Expect(ui.WarnArgsForCall(0)).To(ContainSubstring("A warning")) 99 }) 100 }) 101 }) 102 })