github.com/cloudfoundry/cli@v7.1.0+incompatible/util/ui/ui_v7_test.go (about) 1 package ui_test 2 3 import ( 4 "code.cloudfoundry.org/cli/util/configv3" 5 . "code.cloudfoundry.org/cli/util/ui" 6 "code.cloudfoundry.org/cli/util/ui/uifakes" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 ) 11 12 var _ = Describe("UI", func() { 13 var ( 14 ui *UI 15 fakeConfig *uifakes.FakeConfig 16 out *Buffer 17 errBuff *Buffer 18 ) 19 20 BeforeEach(func() { 21 fakeConfig = new(uifakes.FakeConfig) 22 fakeConfig.ColorEnabledReturns(configv3.ColorEnabled) 23 24 var err error 25 ui, err = NewUI(fakeConfig) 26 Expect(err).NotTo(HaveOccurred()) 27 28 out = NewBuffer() 29 ui.Out = out 30 ui.OutForInteration = out 31 errBuff = NewBuffer() 32 ui.Err = errBuff 33 }) 34 35 // Covers the happy paths, additional cases are tested in TranslateText 36 Describe("DisplayWarnings", func() { 37 It("displays the warnings to ui.Err", func() { 38 ui.DisplayWarnings([]string{"warning-1", "warning-2"}) 39 Expect(ui.Err).To(Say("warning-1\n")) 40 Expect(ui.Err).To(Say("warning-2\n")) 41 }) 42 43 When("the locale is not set to english", func() { 44 BeforeEach(func() { 45 fakeConfig.LocaleReturns("fr-FR") 46 47 var err error 48 ui, err = NewUI(fakeConfig) 49 Expect(err).NotTo(HaveOccurred()) 50 51 errBuff = NewBuffer() 52 ui.Err = errBuff 53 }) 54 55 When("there are multiple warnings", func() { 56 It("displays translated warnings to ui.Err", func() { 57 ui.DisplayWarnings([]string{"un-translateable warning", "FEATURE FLAGS", "Number of instances"}) 58 Expect(string(errBuff.Contents())).To(Equal("un-translateable warning\nINDICATEURS DE FONCTION\nNombre d'instances\n")) 59 }) 60 }) 61 62 When("there is a single warning ", func() { 63 It("displays the translated warning to ui.Err", func() { 64 ui.DisplayWarnings([]string{"un-translateable warning"}) 65 Expect(string(errBuff.Contents())).To(Equal("un-translateable warning\n")) 66 }) 67 }) 68 69 Context("there are no warnings", func() { 70 It("does not print out a new line", func() { 71 ui.DisplayWarnings(nil) 72 Expect(errBuff.Contents()).To(BeEmpty()) 73 }) 74 }) 75 }) 76 }) 77 })