github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/pkg/task/common_test.go (about) 1 // Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0. 2 3 package task 4 5 import ( 6 "fmt" 7 8 "github.com/pingcap/tidb/config" 9 10 . "github.com/pingcap/check" 11 "github.com/spf13/pflag" 12 ) 13 14 var _ = Suite(&testCommonSuite{}) 15 16 type testCommonSuite struct{} 17 18 type fakeValue string 19 20 func (f fakeValue) String() string { 21 return string(f) 22 } 23 24 func (f fakeValue) Set(string) error { 25 panic("implement me") 26 } 27 28 func (f fakeValue) Type() string { 29 panic("implement me") 30 } 31 32 func (*testCommonSuite) TestUrlNoQuery(c *C) { 33 flag := &pflag.Flag{ 34 Name: flagStorage, 35 Value: fakeValue("s3://some/what?secret=a123456789&key=987654321"), 36 } 37 38 field := flagToZapField(flag) 39 c.Assert(field.Key, Equals, flagStorage) 40 c.Assert(field.Interface.(fmt.Stringer).String(), Equals, "s3://some/what") 41 } 42 43 func (s *testCommonSuite) TestTiDBConfigUnchanged(c *C) { 44 cfg := config.GetGlobalConfig() 45 restoreConfig := enableTiDBConfig() 46 c.Assert(cfg, Not(DeepEquals), config.GetGlobalConfig()) 47 restoreConfig() 48 c.Assert(cfg, DeepEquals, config.GetGlobalConfig()) 49 } 50 51 func (s *testCommonSuite) TestStripingPDURL(c *C) { 52 nor1, err := normalizePDURL("https://pd:5432", true) 53 c.Assert(err, IsNil) 54 c.Assert(nor1, Equals, "pd:5432") 55 _, err = normalizePDURL("https://pd.pingcap.com", false) 56 c.Assert(err, ErrorMatches, ".*pd url starts with https while TLS disabled.*") 57 _, err = normalizePDURL("http://127.0.0.1:2379", true) 58 c.Assert(err, ErrorMatches, ".*pd url starts with http while TLS enabled.*") 59 nor, err := normalizePDURL("http://127.0.0.1", false) 60 c.Assert(nor, Equals, "127.0.0.1") 61 c.Assert(err, IsNil) 62 noChange, err := normalizePDURL("127.0.0.1:2379", false) 63 c.Assert(err, IsNil) 64 c.Assert(noChange, Equals, "127.0.0.1:2379") 65 }