vitess.io/vitess@v0.16.2/go/cmd/vtorc/main_test.go (about) 1 package main 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/spf13/pflag" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func Test_transformArgsForPflag(t *testing.T) { 12 fs := pflag.NewFlagSet("test", pflag.ContinueOnError) 13 fs.String("foobar", "baz", "") 14 fs.StringP("name", "n", "", "") 15 fs.BoolP("debug", "d", true, "") 16 17 tests := []struct { 18 args []string 19 transformed []string 20 }{ 21 { 22 args: []string{"--foobar=hello", "--name", "myname", "-d"}, 23 transformed: []string{"--foobar=hello", "--name", "myname", "-d"}, 24 }, 25 { 26 args: []string{"-foobar=hello", "-name", "myname", "-d"}, 27 transformed: []string{"--foobar=hello", "--name", "myname", "-d"}, 28 }, 29 { 30 args: []string{"--", "-foobar=hello"}, 31 transformed: []string{"--", "-foobar=hello"}, 32 }, 33 { 34 args: []string{"-dn"}, // combined shortopts 35 transformed: []string{"-dn"}, 36 }, 37 } 38 39 for _, tt := range tests { 40 tt := tt 41 name := strings.Join(tt.args, " ") 42 43 t.Run(name, func(t *testing.T) { 44 got := transformArgsForPflag(fs, tt.args) 45 assert.Equal(t, tt.transformed, got) 46 }) 47 } 48 }