github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/pkg/storage/local_test.go (about) 1 // Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0. 2 3 package storage 4 5 import ( 6 "context" 7 "os" 8 "path/filepath" 9 "runtime" 10 11 . "github.com/pingcap/check" 12 ) 13 14 type testLocalSuite struct{} 15 16 var _ = Suite(&testLocalSuite{}) 17 18 func (r *testStorageSuite) TestWalkDirWithSoftLinkFile(c *C) { 19 if runtime.GOOS == "windows" { 20 // skip the test on windows. typically windows users don't have symlink permission. 21 return 22 } 23 24 dir1 := c.MkDir() 25 name1 := "test.warehouse.0.sql" 26 path1 := filepath.Join(dir1, name1) 27 f1, err := os.Create(path1) 28 c.Assert(err, IsNil) 29 30 data := "/* whatever pragmas */;" + 31 "INSERT INTO `namespaced`.`table` (columns, more, columns) VALUES (1,-2, 3),\n(4,5., 6);" + 32 "INSERT `namespaced`.`table` (x,y,z) VALUES (7,8,9);" + 33 "insert another_table values (10,11e1,12, '(13)', '(', 14, ')');" 34 _, err = f1.Write([]byte(data)) 35 c.Assert(err, IsNil) 36 err = f1.Close() 37 c.Assert(err, IsNil) 38 39 dir2 := c.MkDir() 40 name2 := "test.warehouse.1.sql" 41 f2, err := os.Create(filepath.Join(dir2, name2)) 42 c.Assert(err, IsNil) 43 _, err = f2.Write([]byte(data)) 44 c.Assert(err, IsNil) 45 err = f2.Close() 46 c.Assert(err, IsNil) 47 48 err = os.Symlink(path1, filepath.Join(dir2, name1)) 49 c.Assert(err, IsNil) 50 51 sb, err := ParseBackend("file://"+filepath.ToSlash(dir2), &BackendOptions{}) 52 c.Assert(err, IsNil) 53 54 store, err := Create(context.TODO(), sb, true) 55 c.Assert(err, IsNil) 56 57 i := 0 58 names := []string{name1, name2} 59 err = store.WalkDir(context.TODO(), &WalkOption{}, func(path string, size int64) error { 60 c.Assert(path, Equals, names[i]) 61 c.Assert(size, Equals, int64(len(data))) 62 i++ 63 64 return nil 65 }) 66 c.Assert(err, IsNil) 67 c.Assert(i, Equals, 2) 68 }