@@ -32,13 +32,50 @@ func (f fakeValue) Type() string {
32
32
}
33
33
34
34
func TestUrlNoQuery (t * testing.T ) {
35
- flag := & pflag.Flag {
36
- Name : flagStorage ,
37
- Value : fakeValue ("s3://some/what?secret=a123456789&key=987654321" ),
35
+ testCases := []struct {
36
+ inputName string
37
+ expectedName string
38
+ inputValue string
39
+ expectedValue string
40
+ }{
41
+ {
42
+ inputName : flagSendCreds ,
43
+ expectedName : "send-credentials-to-tikv" ,
44
+ inputValue : "true" ,
45
+ expectedValue : "true" ,
46
+ },
47
+ {
48
+ inputName : flagStorage ,
49
+ expectedName : "storage" ,
50
+ inputValue : "s3://some/what?secret=a123456789&key=987654321" ,
51
+ expectedValue : "s3://some/what" ,
52
+ },
53
+ {
54
+ inputName : FlagStreamFullBackupStorage ,
55
+ expectedName : "full-backup-storage" ,
56
+ inputValue : "s3://bucket/prefix/?access-key=1&secret-key=2" ,
57
+ expectedValue : "s3://bucket/prefix/" ,
58
+ },
59
+ {
60
+ inputName : flagCipherKey ,
61
+ expectedName : "crypter.key" ,
62
+ inputValue : "537570657253656372657456616C7565" ,
63
+ expectedValue : "<redacted>" ,
64
+ },
65
+ }
66
+
67
+ for _ , tc := range testCases {
68
+ flag := pflag.Flag {
69
+ Name : tc .inputName ,
70
+ Value : fakeValue (tc .inputValue ),
71
+ }
72
+ field := flagToZapField (& flag )
73
+ require .Equal (t , tc .expectedName , field .Key , `test-case [%s="%s"]` , tc .expectedName , tc .expectedValue )
74
+ if stringer , ok := field .Interface .(fmt.Stringer ); ok {
75
+ field .String = stringer .String ()
76
+ }
77
+ require .Equal (t , tc .expectedValue , field .String , `test-case [%s="%s"]` , tc .expectedName , tc .expectedValue )
38
78
}
39
- field := flagToZapField (flag )
40
- require .Equal (t , flagStorage , field .Key )
41
- require .Equal (t , "s3://some/what" , field .Interface .(fmt.Stringer ).String ())
42
79
}
43
80
44
81
func TestTiDBConfigUnchanged (t * testing.T ) {
0 commit comments