vitess.io/vitess@v0.16.2/go/flags/endtoend/flags_test.go (about) 1 /* 2 Copyright 2022 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package flags 18 19 // These tests ensure that we are changing flags intentionally and do not accidentally make 20 // changes such as removing a flag. Since there's no way to test the command-line 21 // flag handling portion explicitly in the unit tests we do so here. 22 23 import ( 24 "bytes" 25 _ "embed" 26 "os/exec" 27 "testing" 28 29 "vitess.io/vitess/go/test/utils" 30 31 "github.com/stretchr/testify/require" 32 ) 33 34 var ( 35 //go:embed mysqlctl.txt 36 mysqlctlTxt string 37 38 //go:embed mysqlctld.txt 39 mysqlctldTxt string 40 41 //go:embed vtaclcheck.txt 42 vtaclcheckTxt string 43 44 //go:embed vtexplain.txt 45 vtexplainTxt string 46 47 //go:embed vtgate.txt 48 vtgateTxt string 49 50 //go:embed vtgr.txt 51 vtgrTxt string 52 53 //go:embed vttablet.txt 54 vttabletTxt string 55 56 //go:embed vttlstest.txt 57 vttlstestTxt string 58 59 //go:embed vtctld.txt 60 vtctldTxt string 61 62 //go:embed vtorc.txt 63 vtorcTxt string 64 65 //go:embed vtctlclient.txt 66 vtctlclientTxt string 67 68 //go:embed vtctldclient.txt 69 vtctldclientTxt string 70 71 //go:embed vttestserver.txt 72 vttestserverTxt string 73 74 //go:embed zkctld.txt 75 zkctldTxt string 76 77 //go:embed vtbackup.txt 78 vtbackupTxt string 79 80 //go:embed zkctl.txt 81 zkctlTxt string 82 83 //go:embed zk.txt 84 zkTxt string 85 86 helpOutput = map[string]string{ 87 "mysqlctl": mysqlctlTxt, 88 "mysqlctld": mysqlctldTxt, 89 "vtaclcheck": vtaclcheckTxt, 90 "vtexplain": vtexplainTxt, 91 "vtgate": vtgateTxt, 92 "vtgr": vtgrTxt, 93 "vttablet": vttabletTxt, 94 "vttlstest": vttlstestTxt, 95 "vtctld": vtctldTxt, 96 "vtctlclient": vtctlclientTxt, 97 "vtctldclient": vtctldclientTxt, 98 "vtorc": vtorcTxt, 99 "vttestserver": vttestserverTxt, 100 "zkctld": zkctldTxt, 101 "vtbackup": vtbackupTxt, 102 "zk": zkTxt, 103 "zkctl": zkctlTxt, 104 } 105 ) 106 107 func TestHelpOutput(t *testing.T) { 108 args := []string{"--help"} 109 for binary, helptext := range helpOutput { 110 t.Run(binary, func(t *testing.T) { 111 cmd := exec.Command(binary, args...) 112 output := bytes.Buffer{} 113 cmd.Stderr = &output 114 cmd.Stdout = &output 115 err := cmd.Run() 116 require.NoError(t, err) 117 utils.MustMatch(t, helptext, output.String()) 118 }) 119 } 120 }