10 // NewMockUi returns a fully initialized MockUi instance
11 // which is safe for concurrent use.
12 func NewMockUi() *MockUi {
18 // MockUi is a mock UI that is used for tests and is exported publicly
19 // for use in external tests if needed as well. Do not instantite this
20 // directly since the buffers will be initialized on the first write. If
21 // there is no write then you will get a nil panic. Please use the
22 // NewMockUi() constructor function instead. You can fix your code with
24 // sed -i -e 's/new(cli.MockUi)/cli.NewMockUi()/g' *_test.go
27 ErrorWriter *syncBuffer
28 OutputWriter *syncBuffer
33 func (u *MockUi) Ask(query string) (string, error) {
37 fmt.Fprint(u.OutputWriter, query)
38 if _, err := fmt.Fscanln(u.InputReader, &result); err != nil {
45 func (u *MockUi) AskSecret(query string) (string, error) {
49 func (u *MockUi) Error(message string) {
52 fmt.Fprint(u.ErrorWriter, message)
53 fmt.Fprint(u.ErrorWriter, "\n")
56 func (u *MockUi) Info(message string) {
60 func (u *MockUi) Output(message string) {
63 fmt.Fprint(u.OutputWriter, message)
64 fmt.Fprint(u.OutputWriter, "\n")
67 func (u *MockUi) Warn(message string) {
70 fmt.Fprint(u.ErrorWriter, message)
71 fmt.Fprint(u.ErrorWriter, "\n")
74 func (u *MockUi) init() {
75 u.ErrorWriter = new(syncBuffer)
76 u.OutputWriter = new(syncBuffer)
79 type syncBuffer struct {
84 func (b *syncBuffer) Write(data []byte) (int, error) {
87 return b.b.Write(data)
90 func (b *syncBuffer) Read(data []byte) (int, error) {
96 func (b *syncBuffer) Reset() {
102 func (b *syncBuffer) String() string {
103 return string(b.Bytes())
106 func (b *syncBuffer) Bytes() []byte {