go.uber.org/yarpc@v1.72.1/internal/shard/main_test.go (about) 1 // Copyright (c) 2022 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package main 22 23 import ( 24 "bytes" 25 "testing" 26 27 "github.com/stretchr/testify/assert" 28 ) 29 30 func TestDo(t *testing.T) { 31 tests := []struct { 32 Args []string 33 WantOutput string 34 WantError bool 35 }{ 36 { 37 WantError: true, 38 }, 39 { 40 Args: []string{}, 41 WantError: true, 42 }, 43 { 44 Args: []string{"1"}, 45 WantError: true, 46 }, 47 { 48 Args: []string{"1", "x"}, 49 WantError: true, 50 }, 51 { 52 Args: []string{"x", "1"}, 53 WantError: true, 54 }, 55 { 56 Args: []string{"1", "3"}, 57 }, 58 { 59 Args: []string{"1", "3", "a"}, 60 WantOutput: "a", 61 }, 62 { 63 Args: []string{"1", "3", "a", "b"}, 64 WantOutput: "a", 65 }, 66 { 67 Args: []string{"1", "3", "a", "b", "c"}, 68 WantOutput: "a", 69 }, 70 { 71 Args: []string{"1", "3", "a", "b", "c", "d"}, 72 WantOutput: "a d", 73 }, 74 } 75 for _, tt := range tests { 76 buffer := bytes.NewBuffer(nil) 77 err := do(tt.Args, buffer) 78 if tt.WantError { 79 assert.Error(t, err) 80 } else { 81 assert.NoError(t, err) 82 } 83 assert.Equal(t, tt.WantOutput, buffer.String()) 84 } 85 }