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