forked from cloudfoundry-incubator/cflocal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.go
47 lines (38 loc) · 933 Bytes
/
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
package mocks
import (
"fmt"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega/gbytes"
"github.com/sclevine/forge/engine"
)
type MockUI struct {
Err error
Out *gbytes.Buffer
Reply map[string]string
}
func NewMockUI() *MockUI {
return &MockUI{
Out: gbytes.NewBuffer(),
Reply: map[string]string{},
}
}
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 engine.Progress) error {
ginkgo.Fail("UI mock does not support Loading method.")
return nil
}