forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui_for_app_test.go
177 lines (152 loc) · 5.43 KB
/
ui_for_app_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
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
)
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.Err = NewBuffer()
})
Describe("DisplayInstancesTableForApp", func() {
Context("in english", func() {
It("displays a table with red coloring for down and crashed", func() {
ui.DisplayInstancesTableForApp([][]string{
{"", "header1", "header2", "header3"},
{"#0", "starting", "val1", "val2"},
{"#1", "down", "val1", "val2"},
{"#2", "crashed", "val1", "val2"},
})
Expect(ui.Out).To(Say("\x1b\\[1mheader1\x1b\\[0m\\s+\x1b\\[1mheader2\x1b\\[0m\\s+\x1b\\[1mheader3\x1b\\[0m")) // Makes sure empty values are not bolded
Expect(ui.Out).To(Say(`#0\s+starting\s+val1\s+val2`))
Expect(ui.Out).To(Say("#1\\s+\x1b\\[31;1mdown\x1b\\[0m\\s+val1\\s+val2"))
Expect(ui.Out).To(Say("#2\\s+\x1b\\[31;1mcrashed\x1b\\[0m\\s+val1\\s+val2"))
})
})
Context("in a non-english language", func() {
BeforeEach(func() {
fakeConfig.LocaleReturns("fr-FR")
var err error
ui, err = NewUI(fakeConfig)
Expect(err).NotTo(HaveOccurred())
ui.Out = NewBuffer()
ui.Err = NewBuffer()
})
It("displays a table with red coloring for down and crashed", func() {
ui.DisplayInstancesTableForApp([][]string{
{"", "header1", "header2", "header3"},
{"#0", ui.TranslateText("starting"), "val1", "val2"},
{"#1", ui.TranslateText("down"), "val1", "val2"},
{"#2", ui.TranslateText("crashed"), "val1", "val2"},
})
Expect(ui.Out).To(Say("\x1b\\[1mheader1\x1b\\[0m\\s+\x1b\\[1mheader2\x1b\\[0m\\s+\x1b\\[1mheader3\x1b\\[0m")) // Makes sure empty values are not bolded
Expect(ui.Out).To(Say(`#0\s+%s\s+val1\s+val2`, ui.TranslateText("starting")))
Expect(ui.Out).To(Say("#1\\s+\x1b\\[31;1m%s\x1b\\[0m\\s+val1\\s+val2", ui.TranslateText("down")))
Expect(ui.Out).To(Say("#2\\s+\x1b\\[31;1m%s\x1b\\[0m\\s+val1\\s+val2", ui.TranslateText("crashed")))
})
})
})
Describe("DisplayKeyValueTableForApp", func() {
When("the app is running properly", func() {
BeforeEach(func() {
ui.DisplayKeyValueTableForApp([][]string{
{"name:", "dora"},
{"requested state:", "started"},
{"instances:", "1/1"},
})
})
It("displays a table with the no change in coloring", func() {
Expect(ui.Out).To(Say("name: dora\n"))
Expect(ui.Out).To(Say("requested state: started\n"))
Expect(ui.Out).To(Say("instances: 1/1\n"))
})
})
When("the app is stopped and has 0 instances", func() {
Context("in english", func() {
BeforeEach(func() {
ui.DisplayKeyValueTableForApp([][]string{
{"name:", "dora"},
{"requested state:", "stopped"},
{"instances:", "0/1"},
})
})
It("displays a table with the no change in coloring", func() {
Expect(ui.Out).To(Say("name: dora\n"))
Expect(ui.Out).To(Say("requested state: stopped\n"))
Expect(ui.Out).To(Say("instances: 0/1\n"))
})
})
Context("in a non-english language", func() {
BeforeEach(func() {
fakeConfig.LocaleReturns("fr-FR")
var err error
ui, err = NewUI(fakeConfig)
Expect(err).NotTo(HaveOccurred())
ui.Out = NewBuffer()
ui.Err = NewBuffer()
ui.DisplayKeyValueTableForApp([][]string{
{"name:", "dora"},
{"requested state:", ui.TranslateText("stopped")},
{"instances:", "0/1"},
})
})
It("displays a table with the no change in coloring", func() {
Expect(ui.Out).To(Say("name: dora\n"))
Expect(ui.Out).To(Say("requested state: %s\n", ui.TranslateText("stopped")))
Expect(ui.Out).To(Say("instances: 0/1\n"))
})
})
})
When("the app is not stopped and has 0 instances", func() {
Context("in english", func() {
BeforeEach(func() {
ui.DisplayKeyValueTableForApp([][]string{
{"name:", "dora"},
{"requested state:", "running"},
{"instances:", "0/1"},
})
})
It("displays a table with requested state and instances in red", func() {
Expect(ui.Out).To(Say("name: dora\n"))
Expect(ui.Out).To(Say("requested state: \x1b\\[31;1mrunning\x1b\\[0m\n"))
Expect(ui.Out).To(Say("instances: \x1b\\[31;1m0/1\x1b\\[0m\n"))
})
})
Context("in a non-english language", func() {
BeforeEach(func() {
fakeConfig.LocaleReturns("fr-FR")
var err error
ui, err = NewUI(fakeConfig)
Expect(err).NotTo(HaveOccurred())
ui.Out = NewBuffer()
ui.Err = NewBuffer()
ui.DisplayKeyValueTableForApp([][]string{
{"name:", "dora"},
{"requested state:", ui.TranslateText("running")},
{"instances:", "0/1"},
})
})
It("displays a table with requested state and instances in red", func() {
Expect(ui.Out).To(Say("name: dora\n"))
Expect(ui.Out).To(Say("requested state: \x1b\\[31;1m%s\x1b\\[0m\n", ui.TranslateText("running")))
Expect(ui.Out).To(Say("instances: \x1b\\[31;1m0/1\x1b\\[0m\n"))
})
})
})
})
})