@@ -9,14 +9,14 @@ import (
99 "github.com/stretchr/testify/require"
1010)
1111
12- func setUpBytesHex (bytesHex * []byte ) * FlagSet {
13- f := NewFlagSet ("test" , ContinueOnError )
14- f .BytesHexVar (bytesHex , "bytes" , []byte {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 }, "Some bytes in HEX" )
15- f .BytesHexVarP (bytesHex , "bytes2" , "B" , []byte {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 }, "Some bytes in HEX" )
16- return f
17- }
18-
1912func TestBytesHex (t * testing.T ) {
13+ newFlag := func (bytesHex * []byte ) * FlagSet {
14+ f := NewFlagSet ("test" , ContinueOnError )
15+ f .BytesHexVar (bytesHex , "bytes" , []byte {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 }, "Some bytes in HEX" )
16+ f .BytesHexVarP (bytesHex , "bytes2" , "B" , []byte {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 }, "Some bytes in HEX" )
17+ return f
18+ }
19+
2020 testCases := []struct {
2121 input string
2222 success bool
@@ -40,7 +40,7 @@ func TestBytesHex(t *testing.T) {
4040
4141 for i := range testCases {
4242 var bytesHex []byte
43- f := setUpBytesHex (& bytesHex )
43+ f := newFlag (& bytesHex )
4444
4545 tc := & testCases [i ]
4646
@@ -77,14 +77,14 @@ func TestBytesHex(t *testing.T) {
7777 }
7878}
7979
80- func setUpBytesBase64 (bytesBase64 * []byte ) * FlagSet {
81- f := NewFlagSet ("test" , ContinueOnError )
82- f .BytesBase64Var (bytesBase64 , "bytes" , []byte {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 }, "Some bytes in Base64" )
83- f .BytesBase64VarP (bytesBase64 , "bytes2" , "B" , []byte {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 }, "Some bytes in Base64" )
84- return f
85- }
86-
8780func TestBytesBase64 (t * testing.T ) {
81+ newFlag := func (bytesBase64 * []byte ) * FlagSet {
82+ f := NewFlagSet ("test" , ContinueOnError )
83+ f .BytesBase64Var (bytesBase64 , "bytes" , []byte {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 }, "Some bytes in Base64" )
84+ f .BytesBase64VarP (bytesBase64 , "bytes2" , "B" , []byte {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 }, "Some bytes in Base64" )
85+ return f
86+ }
87+
8888 testCases := []struct {
8989 input string
9090 success bool
@@ -104,11 +104,9 @@ func TestBytesBase64(t *testing.T) {
104104
105105 for i := range testCases {
106106 var bytesBase64 []byte
107- f := setUpBytesBase64 (& bytesBase64 )
108-
107+ f := newFlag (& bytesBase64 )
109108 tc := & testCases [i ]
110109
111- // --bytes
112110 args := []string {
113111 fmt .Sprintf ("--bytes=%s" , tc .input ),
114112 fmt .Sprintf ("-B %s" , tc .input ),
@@ -117,7 +115,6 @@ func TestBytesBase64(t *testing.T) {
117115
118116 for _ , arg := range args {
119117 err := f .Parse ([]string {arg })
120-
121118 if ! tc .success {
122119 require .Errorf (t , err ,
123120 "expected failure while processing %q" , tc .input ,
@@ -132,7 +129,6 @@ func TestBytesBase64(t *testing.T) {
132129 require .NoErrorf (t , err ,
133130 "got error trying to fetch the 'bytes' flag: %v" , err ,
134131 )
135-
136132 require .Equalf (t , tc .expected , base64 .StdEncoding .EncodeToString (bytesBase64 ),
137133 "expected %q, got '%X'" , tc .expected , bytesBase64 ,
138134 )
0 commit comments