@@ -4,7 +4,6 @@ package backup_test
44
55import (
66 "context"
7- "fmt"
87 "math"
98 "testing"
109
@@ -17,34 +16,41 @@ import (
1716 "github.com/pingcap/tidb/pkg/testkit"
1817 filter "github.com/pingcap/tidb/pkg/util/table-filter"
1918 "github.com/stretchr/testify/require"
19+ "github.com/tikv/client-go/v2/tikv"
2020)
2121
2222// TestBackupSchemaMergeOptionRuleIDFormat tests the rule ID format generation
2323func TestBackupSchemaMergeOptionRuleIDFormat (t * testing.T ) {
24+ codec := tikv .NewCodecV1 (tikv .ModeTxn )
25+
2426 t .Run ("normal table rule ID format" , func (t * testing.T ) {
2527 dbName := "test"
2628 tableName := "t1"
27- expectedRuleID := fmt . Sprintf ( label .TableIDFormat , label . IDPrefix , dbName , tableName )
29+ expectedRuleID := label .NewRuleID ( codec , dbName , tableName , "" )
2830 require .Equal (t , "schema/test/t1" , expectedRuleID )
2931 })
3032
3133 t .Run ("partition table rule ID format" , func (t * testing.T ) {
3234 dbName := "test"
3335 tableName := "pt1"
3436 partitionName := "p0"
35- expectedRuleID := fmt . Sprintf ( label .PartitionIDFormat , label . IDPrefix , dbName , tableName , partitionName )
37+ expectedRuleID := label .NewRuleID ( codec , dbName , tableName , partitionName )
3638 require .Equal (t , "schema/test/pt1/p0" , expectedRuleID )
3739 })
3840
3941 t .Run ("multiple partitions rule ID format" , func (t * testing.T ) {
4042 dbName := "test"
4143 tableName := "pt2"
4244 partitions := []string {"p0" , "p1" , "p2" }
45+ expected := []string {
46+ "schema/test/pt2/p0" ,
47+ "schema/test/pt2/p1" ,
48+ "schema/test/pt2/p2" ,
49+ }
4350
44- for _ , partName := range partitions {
45- ruleID := fmt .Sprintf (label .PartitionIDFormat , label .IDPrefix , dbName , tableName , partName )
46- expected := fmt .Sprintf ("schema/%s/%s/%s" , dbName , tableName , partName )
47- require .Equal (t , expected , ruleID , "partition %s rule ID should match" , partName )
51+ for i , partName := range partitions {
52+ ruleID := label .NewRuleID (codec , dbName , tableName , partName )
53+ require .Equal (t , expected [i ], ruleID , "partition %s rule ID should match" , partName )
4854 }
4955 })
5056
@@ -56,13 +62,13 @@ func TestBackupSchemaMergeOptionRuleIDFormat(t *testing.T) {
5662 // Simulate DDL behavior: uses .L (lowercase)
5763 // DDL would use: schema.Name.L, meta.Name.L, spec.PartitionNames[0].L
5864 // For "TestDB"/"TestTable"/"Partition0", .L would be: "testdb"/"testtable"/"partition0"
59- ddlRuleID := fmt . Sprintf ( label .TableIDFormat , label . IDPrefix , "testdb" , "testtable" )
60- ddlPartitionRuleID := fmt . Sprintf ( label .PartitionIDFormat , label . IDPrefix , "testdb" , "testtable" , "partition0" )
65+ ddlRuleID := label .NewRuleID ( codec , "testdb" , "testtable" , " " )
66+ ddlPartitionRuleID := label .NewRuleID ( codec , "testdb" , "testtable" , "partition0" )
6167
6268 // BR should also use .L (lowercase) - simulate BR behavior
6369 // In real code: table.DB.Name.L, table.Info.Name.L, def.Name.L
64- brRuleID := fmt . Sprintf ( label .TableIDFormat , label . IDPrefix , "testdb" , "testtable" )
65- brPartitionRuleID := fmt . Sprintf ( label .PartitionIDFormat , label . IDPrefix , "testdb" , "testtable" , "partition0" )
70+ brRuleID := label .NewRuleID ( codec , "testdb" , "testtable" , " " )
71+ brPartitionRuleID := label .NewRuleID ( codec , "testdb" , "testtable" , "partition0" )
6672
6773 // Both should generate the same rule ID
6874 require .Equal (t , ddlRuleID , brRuleID , "DDL and BR should generate same table rule ID" )
0 commit comments