mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
57 lines
767 B
Go
57 lines
767 B
Go
package command
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestArgOrStdin(t *testing.T) {
|
|
tests := []struct {
|
|
args []string
|
|
stdin string
|
|
i int
|
|
w string
|
|
we error
|
|
}{
|
|
{
|
|
args: []string{
|
|
"a",
|
|
},
|
|
stdin: "b",
|
|
i: 0,
|
|
w: "a",
|
|
we: nil,
|
|
},
|
|
{
|
|
args: []string{
|
|
"a",
|
|
},
|
|
stdin: "b",
|
|
i: 1,
|
|
w: "b",
|
|
we: nil,
|
|
},
|
|
{
|
|
args: []string{
|
|
"a",
|
|
},
|
|
stdin: "",
|
|
i: 1,
|
|
w: "",
|
|
we: ErrNoAvailSrc,
|
|
},
|
|
}
|
|
|
|
for i, tt := range tests {
|
|
var b bytes.Buffer
|
|
b.Write([]byte(tt.stdin))
|
|
g, ge := argOrStdin(tt.args, &b, tt.i)
|
|
if g != tt.w {
|
|
t.Errorf("#%d: expect %v, not %v", i, tt.w, g)
|
|
}
|
|
if ge != tt.we {
|
|
t.Errorf("#%d: expect %v, not %v", i, tt.we, ge)
|
|
}
|
|
}
|
|
}
|