go.etcd.io/etcd@v3.3.27+incompatible/etcdctl/ctlv2/command/util_test.go (about) 1 // Copyright 2015 The etcd Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package command 16 17 import ( 18 "bytes" 19 "testing" 20 ) 21 22 func TestArgOrStdin(t *testing.T) { 23 tests := []struct { 24 args []string 25 stdin string 26 i int 27 w string 28 we error 29 }{ 30 { 31 args: []string{ 32 "a", 33 }, 34 stdin: "b", 35 i: 0, 36 w: "a", 37 we: nil, 38 }, 39 { 40 args: []string{ 41 "a", 42 }, 43 stdin: "b", 44 i: 1, 45 w: "b", 46 we: nil, 47 }, 48 { 49 args: []string{ 50 "a", 51 }, 52 stdin: "", 53 i: 1, 54 w: "", 55 we: ErrNoAvailSrc, 56 }, 57 } 58 59 for i, tt := range tests { 60 var b bytes.Buffer 61 b.Write([]byte(tt.stdin)) 62 g, ge := argOrStdin(tt.args, &b, tt.i) 63 if g != tt.w { 64 t.Errorf("#%d: expect %v, not %v", i, tt.w, g) 65 } 66 if ge != tt.we { 67 t.Errorf("#%d: expect %v, not %v", i, tt.we, ge) 68 } 69 } 70 }