forked from cloudfoundry-incubator/cflocal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.go
52 lines (43 loc) · 1.02 KB
/
ui.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
package mocks
import (
"fmt"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega/gbytes"
"github.com/sclevine/cflocal/ui"
)
type MockUI struct {
Err error
Out *gbytes.Buffer
Reply map[string]string
Progress chan ui.Progress
}
func NewMockUI() *MockUI {
return &MockUI{
Out: gbytes.NewBuffer(),
Reply: map[string]string{},
Progress: make(chan ui.Progress, 1),
}
}
func (m *MockUI) Prompt(prompt string) string {
fmt.Fprint(m.Out, prompt, "\n")
return m.Reply[prompt]
}
func (m *MockUI) Output(format string, args ...interface{}) {
fmt.Fprintf(m.Out, format+"\n", args...)
}
func (m *MockUI) Warn(format string, args ...interface{}) {
fmt.Fprintf(m.Out, "Warning: "+format+"\n", args...)
}
func (m *MockUI) Error(err error) {
if m.Err != nil {
ginkgo.Fail("Error should not be called twice.")
}
m.Err = err
}
func (m *MockUI) Loading(message string, progress <-chan ui.Progress) error {
fmt.Fprintln(m.Out, "Loading: "+message)
for p := range progress {
m.Progress <- p
}
return nil
}