66package restore_test
77
88import (
9+ "cmp"
910 "context"
1011 "encoding/json"
1112 "fmt"
@@ -21,6 +22,7 @@ import (
2122
2223 "github.com/aws/aws-sdk-go-v2/aws"
2324 "github.com/aws/aws-sdk-go-v2/service/dynamodb"
25+ "github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
2426 "github.com/pkg/errors"
2527 "github.com/scylladb/gocqlx/v2/qb"
2628 "github.com/scylladb/scylla-manager/backupspec"
@@ -136,8 +138,19 @@ func TestRestoreSchemaRoundtripIntegration(t *testing.T) {
136138 ExecStmt (t , h .srcCluster .rootSession , fmt .Sprintf (tabStmt , cqlKs , cqlTab , tabOpt ))
137139
138140 Print ("Prepare alternator schema" )
139- altTab := "roundtrip_Tab_le-With1.da_sh2-aNd.d33ot.-"
140- CreateInterestingAlternatorSchema (t , h .srcCluster .altClient , altTab )
141+ altTab1 := "roundtrip_1_" + AlternatorProblematicTableChars
142+ altTab2 := "roundtrip_2_" + AlternatorProblematicTableChars
143+ altGSI1 := "gsi_1_" + AlternatorProblematicTableChars
144+ altGSI2 := "gsi_2_" + AlternatorProblematicTableChars
145+ altTag := "tag"
146+ altTTLAttr := "ttl_attr"
147+ CreateAlternatorTable (t , h .srcCluster .altClient , 2 , altTab1 , altTab2 )
148+ CreateAlternatorGSI (t , h .srcCluster .altClient , altTab1 , altGSI1 , altGSI2 )
149+ CreateAlternatorGSI (t , h .srcCluster .altClient , altTab2 , altGSI1 , altGSI2 )
150+ TagAlternatorTable (t , h .srcCluster .altClient , altTab1 , altTag )
151+ TagAlternatorTable (t , h .srcCluster .altClient , altTab2 , altTag )
152+ UpdateAlternatorTableTTL (t , h .srcCluster .altClient , altTab1 , altTTLAttr , true )
153+ UpdateAlternatorTableTTL (t , h .srcCluster .altClient , altTab2 , altTTLAttr , true )
141154
142155 Print ("Save src CQL schema" )
143156 srcCQLSchema , err := query .DescribeSchemaWithInternals (h .srcCluster .rootSession )
@@ -160,7 +173,11 @@ func TestRestoreSchemaRoundtripIntegration(t *testing.T) {
160173 ExecStmt (t , h .srcCluster .rootSession , "DROP KEYSPACE " + cqlKs )
161174
162175 Print ("Drop backed-up src cluster alternator schema" )
163- _ , err = h .srcCluster .altClient .DeleteTable (context .Background (), & dynamodb.DeleteTableInput {TableName : aws .String (altTab )})
176+ _ , err = h .srcCluster .altClient .DeleteTable (context .Background (), & dynamodb.DeleteTableInput {TableName : aws .String (altTab1 )})
177+ if err != nil {
178+ t .Fatal (err )
179+ }
180+ _ , err = h .srcCluster .altClient .DeleteTable (context .Background (), & dynamodb.DeleteTableInput {TableName : aws .String (altTab2 )})
164181 if err != nil {
165182 t .Fatal (err )
166183 }
@@ -215,7 +232,7 @@ func TestRestoreSchemaRoundtripIntegration(t *testing.T) {
215232 continue
216233 }
217234 // Don't validate alternator schema CQL statements
218- if row .Keyspace == fmt . Sprintf ( "%q" , "alternator_" + altTab ) {
235+ if strings . HasPrefix ( row .Keyspace , "\" alternator_" ) {
219236 continue
220237 }
221238 m1 [row ] = struct {}{}
@@ -230,12 +247,12 @@ func TestRestoreSchemaRoundtripIntegration(t *testing.T) {
230247 t .Fatalf ("Src CQL schema: %v, is missing created objects: %v" , m1 , objWithOpt )
231248 }
232249 for _ , row := range dstCQLSchemaSrcBackup {
233- if row .Keyspace != "" && row . Keyspace != fmt . Sprintf ( "%q" , "alternator_" + altTab ) {
250+ if row .Keyspace != "" && ! strings . HasPrefix ( row . Keyspace , "\" alternator_" ) {
234251 m2 [row ] = struct {}{}
235252 }
236253 }
237254 for _ , row := range srcCQLSchemaDstBackup {
238- if row .Keyspace != "" && row . Keyspace != fmt . Sprintf ( "%q" , "alternator_" + altTab ) {
255+ if row .Keyspace != "" && ! strings . HasPrefix ( row . Keyspace , "\" alternator_" ) {
239256 m3 [row ] = struct {}{}
240257 }
241258 }
@@ -249,6 +266,10 @@ func TestRestoreSchemaRoundtripIntegration(t *testing.T) {
249266
250267 Print ("Validate alternator schema" )
251268 sanitizeAltSchema := func (schema backupspec.AlternatorSchema ) {
269+ // Sort so that we can compare raw json encoding later
270+ slices .SortFunc (schema .Tables , func (a , b backupspec.AlternatorTableSchema ) int {
271+ return cmp .Compare (* a .Describe .TableName , * b .Describe .TableName )
272+ })
252273 for i := range schema .Tables {
253274 // Set TTL to nil as we don't restore it
254275 schema .Tables [i ].TTL = nil
@@ -259,6 +280,12 @@ func TestRestoreSchemaRoundtripIntegration(t *testing.T) {
259280 schema .Tables [i ].Describe .ProvisionedThroughput .LastIncreaseDateTime = nil
260281 // Set table ID to ni as it is expected to differ
261282 schema .Tables [i ].Describe .TableId = nil
283+ slices .SortFunc (schema .Tables [i ].Describe .GlobalSecondaryIndexes , func (a , b types.GlobalSecondaryIndexDescription ) int {
284+ return cmp .Compare (* a .IndexName , * b .IndexName )
285+ })
286+ slices .SortFunc (schema .Tables [i ].Describe .LocalSecondaryIndexes , func (a , b types.LocalSecondaryIndexDescription ) int {
287+ return cmp .Compare (* a .IndexName , * b .IndexName )
288+ })
262289 }
263290 }
264291 sanitizeAltSchema (srcAltSchema )
0 commit comments