Skip to content

Commit 5f437f3

Browse files
Copilottarzanek
andauthored
Add TestValidateProperties to confirm keyspace-mapping is optional
Agent-Logs-Url: https://github.com/scylladb/scylla-manager/sessions/d07997b2-e3cb-41b2-bc3b-3e3aeffd12fd Co-authored-by: tarzanek <504773+tarzanek@users.noreply.github.com>
1 parent 323085b commit 5f437f3

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

pkg/service/restore/worker_test.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
gocmp "github.com/google/go-cmp/cmp"
8+
"github.com/scylladb/scylla-manager/backupspec"
89
"github.com/scylladb/scylla-manager/v3/pkg/scyllaclient"
910
)
1011

@@ -170,6 +171,92 @@ func TestHostsByDC(t *testing.T) {
170171
}
171172
}
172173

174+
func TestValidateProperties(t *testing.T) {
175+
validLoc, err := backupspec.NewLocation("s3:my-bucket")
176+
if err != nil {
177+
t.Fatal(err)
178+
}
179+
180+
testCases := []struct {
181+
name string
182+
target Target
183+
expectedErr bool
184+
}{
185+
{
186+
name: "restore tables without keyspace mapping passes validation",
187+
target: Target{
188+
Location: []backupspec.Location{validLoc},
189+
SnapshotTag: "sm_20240101000000UTC",
190+
RestoreTables: true,
191+
Transfers: 0,
192+
Method: MethodRclone,
193+
},
194+
expectedErr: false,
195+
},
196+
{
197+
name: "restore tables with nil keyspace mapping passes validation",
198+
target: Target{
199+
Location: []backupspec.Location{validLoc},
200+
SnapshotTag: "sm_20240101000000UTC",
201+
RestoreTables: true,
202+
Transfers: 0,
203+
Method: MethodRclone,
204+
KeyspaceMappings: nil,
205+
},
206+
expectedErr: false,
207+
},
208+
{
209+
name: "restore tables with empty keyspace mapping passes validation",
210+
target: Target{
211+
Location: []backupspec.Location{validLoc},
212+
SnapshotTag: "sm_20240101000000UTC",
213+
RestoreTables: true,
214+
Transfers: 0,
215+
Method: MethodRclone,
216+
KeyspaceMappings: map[string]string{},
217+
},
218+
expectedErr: false,
219+
},
220+
{
221+
name: "restore schema without keyspace mapping passes validation",
222+
target: Target{
223+
Location: []backupspec.Location{validLoc},
224+
SnapshotTag: "sm_20240101000000UTC",
225+
RestoreSchema: true,
226+
Transfers: 0,
227+
Method: MethodRclone,
228+
},
229+
expectedErr: false,
230+
},
231+
{
232+
name: "restore schema with keyspace mapping is forbidden",
233+
target: Target{
234+
Location: []backupspec.Location{validLoc},
235+
SnapshotTag: "sm_20240101000000UTC",
236+
RestoreSchema: true,
237+
Transfers: 0,
238+
Method: MethodRclone,
239+
KeyspaceMappings: map[string]string{
240+
"ks_old": "ks_new",
241+
},
242+
},
243+
expectedErr: true,
244+
},
245+
}
246+
247+
for _, tc := range testCases {
248+
t.Run(tc.name, func(t *testing.T) {
249+
err := tc.target.validateProperties()
250+
if tc.expectedErr && err == nil {
251+
t.Fatalf("Expected err, but got nil")
252+
}
253+
if !tc.expectedErr && err != nil {
254+
t.Fatalf("Unexpected err: %v", err)
255+
}
256+
})
257+
}
258+
}
259+
173260
func TestValidateKeyspaceMappings(t *testing.T) {
174261
testCases := []struct {
175262
name string

0 commit comments

Comments
 (0)