Skip to content

Commit

Permalink
feat(backup_test): add TestBackupCorrectAPIIntegration
Browse files Browse the repository at this point in the history
This is a simple test for checking whether the correct API
is used during the backup.
  • Loading branch information
Michal-Leszczynski committed Dec 17, 2024
1 parent a5c0294 commit 7022961
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions pkg/service/backup/service_backup_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2639,3 +2639,74 @@ func TestBackupSkipSchema(t *testing.T) {
}
}
}

func TestBackupCorrectAPIIntegration(t *testing.T) {
// This test validates that the correct API is used
// for uploading snapshot dirs (Rclone or Scylla).
const (
testBucket = "backuptest-api"
testKeyspace = "backuptest_api"
)

var (
location = s3Location(testBucket)
session = CreateScyllaManagerDBSession(t)
h = newBackupTestHelperWithUser(t, session, defaultConfig(), location, nil, "", "")
ctx = context.Background()
clusterSession = CreateSessionAndDropAllKeyspaces(t, h.Client)
)

ni, err := h.Client.AnyNodeInfo(context.Background())
if err != nil {
t.Fatal(err)
}

// Choose expected API - Rclone or Scylla depending on node version
ensuredPath := "/agent/rclone/operations/movedir"
blockedPath := "/storage_service/backup"
if ok, err := ni.SupportsScyllaBackupRestoreAPI(); err != nil {
t.Fatal(err)
} else if ok {
ensuredPath, blockedPath = blockedPath, ensuredPath
}

Printf("Expect that %q API will be used for backup, while %q API won't be used at all", ensuredPath, blockedPath)
encounteredEnsured := atomic.NewBool(false)
encounteredBlocked := atomic.NewBool(false)
h.Hrt.SetInterceptor(httpx.RoundTripperFunc(func(req *http.Request) (*http.Response, error) {
if strings.HasPrefix(req.URL.Path, ensuredPath) {
encounteredEnsured.Store(true)
}
if strings.HasPrefix(req.URL.Path, blockedPath) {
encounteredBlocked.Store(true)
}
return nil, nil
}))

WriteData(t, clusterSession, testKeyspace, 1)

props := map[string]any{
"location": []Location{location},
"keyspace": []string{testKeyspace},
}
rawProps, err := json.Marshal(props)
if err != nil {
t.Fatal(errors.Wrap(err, "create raw properties"))
}
target, err := h.service.GetTarget(ctx, h.ClusterID, rawProps)
if err != nil {
t.Fatal(errors.Wrap(err, "create target"))
}

err = h.service.Backup(ctx, h.ClusterID, h.TaskID, h.RunID, target)
if err != nil {
t.Fatal(err)
}

if !encounteredEnsured.Load() {
t.Fatalf("Expected SM to use %q API", ensuredPath)
}
if encounteredBlocked.Load() {
t.Fatalf("Expected SM not to use %q API", blockedPath)
}
}

0 comments on commit 7022961

Please sign in to comment.