BeforeEach(func() { oldRaiseErrorValue = os.Getenv("CF_RAISE_ERROR_ON_WARNINGS") }) AfterEach(func() { os.Setenv("CF_RAISE_ERROR_ON_WARNINGS", oldRaiseErrorValue) }) Context("when the CF_RAISE_ERROR_ON_WARNINGS environment variable is set", func() { BeforeEach(func() { os.Setenv("CF_RAISE_ERROR_ON_WARNINGS", "true") }) Context("when there are warnings", func() { BeforeEach(func() { warning_producer_one := testnet.NewWarningProducer([]string{"Hello", "Darling"}) warning_producer_two := testnet.NewWarningProducer([]string{"Goodbye", "Sweetie"}) warning_producer_three := testnet.NewWarningProducer(nil) warningsCollector = net.NewWarningsCollector(ui, warning_producer_one, warning_producer_two, warning_producer_three) }) It("panics with an error that contains all the warnings", func() { Expect(warningsCollector.PrintWarnings).To(Panic()) }) }) Context("when there are no warnings", func() { BeforeEach(func() { warningsCollector = net.NewWarningsCollector(ui) })
testterm "github.com/cloudfoundry/cli/testhelpers/terminal" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("WarningsCollector", func() { var ( ui *testterm.FakeUI ) BeforeEach(func() { ui = new(testterm.FakeUI) }) It("prints warnings in all warning producers", func() { warning_producer_one := testnet.NewWarningProducer([]string{"Hello", "Darling"}) warning_producer_two := testnet.NewWarningProducer([]string{"Goodbye", "Sweetie"}) warning_producer_three := testnet.NewWarningProducer(nil) warnings_collector := net.NewWarningsCollector(ui, warning_producer_one, warning_producer_two, warning_producer_three) warnings_collector.PrintWarnings() Expect(ui.WarnOutputs).To(ContainSubstrings( []string{"Hello"}, []string{"Darling"}, []string{"Goodbye"}, []string{"Sweetie"}, )) }) })