|
5 | 5 | "testing" |
6 | 6 |
|
7 | 7 | gocmp "github.com/google/go-cmp/cmp" |
| 8 | + "github.com/scylladb/scylla-manager/backupspec" |
8 | 9 | "github.com/scylladb/scylla-manager/v3/pkg/scyllaclient" |
9 | 10 | ) |
10 | 11 |
|
@@ -170,6 +171,92 @@ func TestHostsByDC(t *testing.T) { |
170 | 171 | } |
171 | 172 | } |
172 | 173 |
|
| 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 | + |
173 | 260 | func TestValidateKeyspaceMappings(t *testing.T) { |
174 | 261 | testCases := []struct { |
175 | 262 | name string |
|
0 commit comments