1/*
2Copyright 2018 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package genericclioptions
18
19import (
20	"bytes"
21	"io"
22	"io/ioutil"
23)
24
25// IOStreams provides the standard names for iostreams.  This is useful for embedding and for unit testing.
26// Inconsistent and different names make it hard to read and review code
27type IOStreams struct {
28	// In think, os.Stdin
29	In io.Reader
30	// Out think, os.Stdout
31	Out io.Writer
32	// ErrOut think, os.Stderr
33	ErrOut io.Writer
34}
35
36// NewTestIOStreams returns a valid IOStreams and in, out, errout buffers for unit tests
37func NewTestIOStreams() (IOStreams, *bytes.Buffer, *bytes.Buffer, *bytes.Buffer) {
38	in := &bytes.Buffer{}
39	out := &bytes.Buffer{}
40	errOut := &bytes.Buffer{}
41
42	return IOStreams{
43		In:     in,
44		Out:    out,
45		ErrOut: errOut,
46	}, in, out, errOut
47}
48
49// NewTestIOStreamsDiscard returns a valid IOStreams that just discards
50func NewTestIOStreamsDiscard() IOStreams {
51	in := &bytes.Buffer{}
52	return IOStreams{
53		In:     in,
54		Out:    ioutil.Discard,
55		ErrOut: ioutil.Discard,
56	}
57}
58