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