Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
D3Hunter committed Mar 31, 2023
1 parent e12a12d commit 9ed6ca3
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 107 deletions.
84 changes: 42 additions & 42 deletions br/pkg/lightning/importer/get_pre_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@ type colDef struct {

type tableDef []*colDef

func tableDefsToMockDataMap(dbTableDefs map[string]map[string]tableDef) map[string]*mock.MockDBSourceData {
dbMockDataMap := make(map[string]*mock.MockDBSourceData)
func tableDefsToMockDataMap(dbTableDefs map[string]map[string]tableDef) map[string]*mock.DBSourceData {
dbMockDataMap := make(map[string]*mock.DBSourceData)
for dbName, tblDefMap := range dbTableDefs {
tblMockDataMap := make(map[string]*mock.MockTableSourceData)
tblMockDataMap := make(map[string]*mock.TableSourceData)
for tblName, colDefs := range tblDefMap {
colDefStrs := make([]string, len(colDefs))
for i, colDef := range colDefs {
colDefStrs[i] = fmt.Sprintf("%s %s", colDef.ColName, colDef.Def)
}
createSQL := fmt.Sprintf("CREATE TABLE %s.%s (%s);", dbName, tblName, strings.Join(colDefStrs, ", "))
tblMockDataMap[tblName] = &mock.MockTableSourceData{
tblMockDataMap[tblName] = &mock.TableSourceData{
DBName: dbName,
TableName: tblName,
SchemaFile: &mock.MockSourceFile{
SchemaFile: &mock.SourceFile{
FileName: fmt.Sprintf("/%s/%s/%s.schema.sql", dbName, tblName, tblName),
Data: []byte(createSQL),
},
}
}
dbMockDataMap[dbName] = &mock.MockDBSourceData{
dbMockDataMap[dbName] = &mock.DBSourceData{
Name: dbName,
Tables: tblMockDataMap,
}
Expand Down Expand Up @@ -223,10 +223,10 @@ func TestGetPreInfoGetAllTableStructures(t *testing.T) {
testMockDataMap := tableDefsToMockDataMap(dbTableDefs)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
mockSrc, err := mock.NewMockImportSource(testMockDataMap)
mockSrc, err := mock.NewImportSource(testMockDataMap)
require.Nil(t, err)

mockTarget := mock.NewMockTargetInfo()
mockTarget := mock.NewTargetInfo()

cfg := config.NewConfig()
cfg.TikvImporter.Backend = config.BackendLocal
Expand Down Expand Up @@ -367,32 +367,32 @@ INSERT INTO db01.tbl01 (ival, sval) VALUES (444, 'ddd');`
ExpectColumns: []string{"id", "name"},
},
}
tblMockSourceData := &mock.MockTableSourceData{
tblMockSourceData := &mock.TableSourceData{
DBName: "db01",
TableName: "tbl01",
SchemaFile: &mock.MockSourceFile{
SchemaFile: &mock.SourceFile{
FileName: "/db01/tbl01/tbl01.schema.sql",
Data: []byte("CREATE TABLE db01.tbl01(id INTEGER PRIMARY KEY AUTO_INCREMENT, ival INTEGER, sval VARCHAR(64));"),
},
DataFiles: []*mock.MockSourceFile{},
DataFiles: []*mock.SourceFile{},
}
for _, testInfo := range testDataInfos {
tblMockSourceData.DataFiles = append(tblMockSourceData.DataFiles, &mock.MockSourceFile{
tblMockSourceData.DataFiles = append(tblMockSourceData.DataFiles, &mock.SourceFile{
FileName: testInfo.FileName,
Data: testInfo.Data,
})
}
mockDataMap := map[string]*mock.MockDBSourceData{
mockDataMap := map[string]*mock.DBSourceData{
"db01": {
Name: "db01",
Tables: map[string]*mock.MockTableSourceData{
Tables: map[string]*mock.TableSourceData{
"tbl01": tblMockSourceData,
},
},
}
mockSrc, err := mock.NewMockImportSource(mockDataMap)
mockSrc, err := mock.NewImportSource(mockDataMap)
require.Nil(t, err)
mockTarget := mock.NewMockTargetInfo()
mockTarget := mock.NewTargetInfo()
cfg := config.NewConfig()
cfg.TikvImporter.Backend = config.BackendLocal
ig, err := NewPreImportInfoGetter(cfg, mockSrc.GetAllDBFileMetas(), mockSrc.GetStorage(), mockTarget, nil, nil)
Expand Down Expand Up @@ -478,32 +478,32 @@ INSERT INTO db01.tbl01 (ival, sval) VALUES (444, 'ddd');`)
tbl01SchemaBytes := []byte("CREATE TABLE db01.tbl01(id INTEGER PRIMARY KEY AUTO_INCREMENT, ival INTEGER, sval VARCHAR(64));")
tbl01SchemaBytesCompressed := compressGz(t, tbl01SchemaBytes)

tblMockSourceData := &mock.MockTableSourceData{
tblMockSourceData := &mock.TableSourceData{
DBName: "db01",
TableName: "tbl01",
SchemaFile: &mock.MockSourceFile{
SchemaFile: &mock.SourceFile{
FileName: "/db01/tbl01/tbl01.schema.sql.gz",
Data: tbl01SchemaBytesCompressed,
},
DataFiles: []*mock.MockSourceFile{},
DataFiles: []*mock.SourceFile{},
}
for _, testInfo := range testDataInfos {
tblMockSourceData.DataFiles = append(tblMockSourceData.DataFiles, &mock.MockSourceFile{
tblMockSourceData.DataFiles = append(tblMockSourceData.DataFiles, &mock.SourceFile{
FileName: testInfo.FileName,
Data: testInfo.Data,
})
}
mockDataMap := map[string]*mock.MockDBSourceData{
mockDataMap := map[string]*mock.DBSourceData{
"db01": {
Name: "db01",
Tables: map[string]*mock.MockTableSourceData{
Tables: map[string]*mock.TableSourceData{
"tbl01": tblMockSourceData,
},
},
}
mockSrc, err := mock.NewMockImportSource(mockDataMap)
mockSrc, err := mock.NewImportSource(mockDataMap)
require.Nil(t, err)
mockTarget := mock.NewMockTargetInfo()
mockTarget := mock.NewTargetInfo()
cfg := config.NewConfig()
cfg.TikvImporter.Backend = config.BackendLocal
ig, err := NewPreImportInfoGetter(cfg, mockSrc.GetAllDBFileMetas(), mockSrc.GetStorage(), mockTarget, nil, nil)
Expand Down Expand Up @@ -532,18 +532,18 @@ func TestGetPreInfoSampleSource(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
dataFileName := "/db01/tbl01/tbl01.data.001.csv"
mockDataMap := map[string]*mock.MockDBSourceData{
mockDataMap := map[string]*mock.DBSourceData{
"db01": {
Name: "db01",
Tables: map[string]*mock.MockTableSourceData{
Tables: map[string]*mock.TableSourceData{
"tbl01": {
DBName: "db01",
TableName: "tbl01",
SchemaFile: &mock.MockSourceFile{
SchemaFile: &mock.SourceFile{
FileName: "/db01/tbl01/tbl01.schema.sql",
Data: []byte("CREATE TABLE db01.tbl01 (id INTEGER PRIMARY KEY AUTO_INCREMENT, ival INTEGER, sval VARCHAR(64));"),
},
DataFiles: []*mock.MockSourceFile{
DataFiles: []*mock.SourceFile{
{
FileName: dataFileName,
Data: []byte(nil),
Expand All @@ -553,9 +553,9 @@ func TestGetPreInfoSampleSource(t *testing.T) {
},
},
}
mockSrc, err := mock.NewMockImportSource(mockDataMap)
mockSrc, err := mock.NewImportSource(mockDataMap)
require.Nil(t, err)
mockTarget := mock.NewMockTargetInfo()
mockTarget := mock.NewTargetInfo()
cfg := config.NewConfig()
cfg.TikvImporter.Backend = config.BackendLocal
ig, err := NewPreImportInfoGetter(cfg, mockSrc.GetAllDBFileMetas(), mockSrc.GetStorage(), mockTarget, nil, nil, ropts.WithIgnoreDBNotExist(true))
Expand Down Expand Up @@ -619,18 +619,18 @@ func TestGetPreInfoSampleSourceCompressed(t *testing.T) {
dataFileName := "/db01/tbl01/tbl01.data.001.csv.gz"
schemaFileData := []byte("CREATE TABLE db01.tbl01 (id INTEGER PRIMARY KEY AUTO_INCREMENT, ival INTEGER, sval VARCHAR(64));")
schemaFileDataCompressed := compressGz(t, schemaFileData)
mockDataMap := map[string]*mock.MockDBSourceData{
mockDataMap := map[string]*mock.DBSourceData{
"db01": {
Name: "db01",
Tables: map[string]*mock.MockTableSourceData{
Tables: map[string]*mock.TableSourceData{
"tbl01": {
DBName: "db01",
TableName: "tbl01",
SchemaFile: &mock.MockSourceFile{
SchemaFile: &mock.SourceFile{
FileName: "/db01/tbl01/tbl01.schema.sql.gz",
Data: schemaFileDataCompressed,
},
DataFiles: []*mock.MockSourceFile{
DataFiles: []*mock.SourceFile{
{
FileName: dataFileName,
Data: []byte(nil),
Expand All @@ -640,9 +640,9 @@ func TestGetPreInfoSampleSourceCompressed(t *testing.T) {
},
},
}
mockSrc, err := mock.NewMockImportSource(mockDataMap)
mockSrc, err := mock.NewImportSource(mockDataMap)
require.Nil(t, err)
mockTarget := mock.NewMockTargetInfo()
mockTarget := mock.NewTargetInfo()
cfg := config.NewConfig()
cfg.TikvImporter.Backend = config.BackendLocal
ig, err := NewPreImportInfoGetter(cfg, mockSrc.GetAllDBFileMetas(), mockSrc.GetStorage(), mockTarget, nil, nil, ropts.WithIgnoreDBNotExist(true))
Expand Down Expand Up @@ -716,18 +716,18 @@ func TestGetPreInfoEstimateSourceSize(t *testing.T) {
2,222,"bbb"
`,
)
mockDataMap := map[string]*mock.MockDBSourceData{
mockDataMap := map[string]*mock.DBSourceData{
"db01": {
Name: "db01",
Tables: map[string]*mock.MockTableSourceData{
Tables: map[string]*mock.TableSourceData{
"tbl01": {
DBName: "db01",
TableName: "tbl01",
SchemaFile: &mock.MockSourceFile{
SchemaFile: &mock.SourceFile{
FileName: "/db01/tbl01/tbl01.schema.sql",
Data: []byte("CREATE TABLE db01.tbl01 (id INTEGER PRIMARY KEY AUTO_INCREMENT, ival INTEGER, sval VARCHAR(64));"),
},
DataFiles: []*mock.MockSourceFile{
DataFiles: []*mock.SourceFile{
{
FileName: dataFileName,
Data: testData,
Expand All @@ -737,9 +737,9 @@ func TestGetPreInfoEstimateSourceSize(t *testing.T) {
},
},
}
mockSrc, err := mock.NewMockImportSource(mockDataMap)
mockSrc, err := mock.NewImportSource(mockDataMap)
require.Nil(t, err)
mockTarget := mock.NewMockTargetInfo()
mockTarget := mock.NewTargetInfo()
cfg := config.NewConfig()
cfg.TikvImporter.Backend = config.BackendLocal
ig, err := NewPreImportInfoGetter(cfg, mockSrc.GetAllDBFileMetas(), mockSrc.GetStorage(), mockTarget, nil, nil, ropts.WithIgnoreDBNotExist(true))
Expand Down
Loading

0 comments on commit 9ed6ca3

Please sign in to comment.