summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/hashicorp/go-sockaddr/cmd/sockaddr/vendor/github.com/mitchellh/cli/ui_mock.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/go-sockaddr/cmd/sockaddr/vendor/github.com/mitchellh/cli/ui_mock.go')
-rw-r--r--vendor/github.com/hashicorp/go-sockaddr/cmd/sockaddr/vendor/github.com/mitchellh/cli/ui_mock.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-sockaddr/cmd/sockaddr/vendor/github.com/mitchellh/cli/ui_mock.go b/vendor/github.com/hashicorp/go-sockaddr/cmd/sockaddr/vendor/github.com/mitchellh/cli/ui_mock.go
new file mode 100644
index 000000000..c46772855
--- /dev/null
+++ b/vendor/github.com/hashicorp/go-sockaddr/cmd/sockaddr/vendor/github.com/mitchellh/cli/ui_mock.go
@@ -0,0 +1,64 @@
+package cli
+
+import (
+ "bytes"
+ "fmt"
+ "io"
+ "sync"
+)
+
+// MockUi is a mock UI that is used for tests and is exported publicly for
+// use in external tests if needed as well.
+type MockUi struct {
+ InputReader io.Reader
+ ErrorWriter *bytes.Buffer
+ OutputWriter *bytes.Buffer
+
+ once sync.Once
+}
+
+func (u *MockUi) Ask(query string) (string, error) {
+ u.once.Do(u.init)
+
+ var result string
+ fmt.Fprint(u.OutputWriter, query)
+ if _, err := fmt.Fscanln(u.InputReader, &result); err != nil {
+ return "", err
+ }
+
+ return result, nil
+}
+
+func (u *MockUi) AskSecret(query string) (string, error) {
+ return u.Ask(query)
+}
+
+func (u *MockUi) Error(message string) {
+ u.once.Do(u.init)
+
+ fmt.Fprint(u.ErrorWriter, message)
+ fmt.Fprint(u.ErrorWriter, "\n")
+}
+
+func (u *MockUi) Info(message string) {
+ u.Output(message)
+}
+
+func (u *MockUi) Output(message string) {
+ u.once.Do(u.init)
+
+ fmt.Fprint(u.OutputWriter, message)
+ fmt.Fprint(u.OutputWriter, "\n")
+}
+
+func (u *MockUi) Warn(message string) {
+ u.once.Do(u.init)
+
+ fmt.Fprint(u.ErrorWriter, message)
+ fmt.Fprint(u.ErrorWriter, "\n")
+}
+
+func (u *MockUi) init() {
+ u.ErrorWriter = new(bytes.Buffer)
+ u.OutputWriter = new(bytes.Buffer)
+}