CloudMigrations: Limit frontend query to get latest snapshots (#93639)

* latest param to endpoint and adapt frontend query

* change to sort param

* api

* remove description
This commit is contained in:
Dana Axinte
2024-10-01 09:28:25 +01:00
committed by GitHub
parent 8b6cbae96b
commit 1a31abe254
9 changed files with 90 additions and 12 deletions
@@ -3,7 +3,6 @@ package cloudmigrationimpl
import (
"context"
"encoding/base64"
"slices"
"strconv"
"testing"
@@ -241,9 +240,46 @@ func TestGetSnapshotList(t *testing.T) {
for _, snapshot := range snapshots {
ids = append(ids, snapshot.UID)
}
slices.Sort(ids)
// There are 3 snapshots in the db but only 2 of them belong to this specific session.
assert.Equal(t, []string{"poiuy", "lkjhg"}, ids)
})
t.Run("returns only one snapshot that belongs to a session", func(t *testing.T) {
snapshots, err := s.GetSnapshotList(ctx, cloudmigration.ListSnapshotsQuery{SessionUID: sessionUID, Page: 1, Limit: 1})
require.NoError(t, err)
assert.Len(t, snapshots, 1)
})
t.Run("return no snapshots if limit is set to 0", func(t *testing.T) {
snapshots, err := s.GetSnapshotList(ctx, cloudmigration.ListSnapshotsQuery{SessionUID: sessionUID, Page: 1, Limit: 0})
require.NoError(t, err)
assert.Empty(t, snapshots)
})
t.Run("returns paginated snapshot that belongs to a session", func(t *testing.T) {
snapshots, err := s.GetSnapshotList(ctx, cloudmigration.ListSnapshotsQuery{SessionUID: sessionUID, Page: 2, Limit: 1})
require.NoError(t, err)
ids := make([]string, 0)
for _, snapshot := range snapshots {
ids = append(ids, snapshot.UID)
}
// Return paginated snapshot of the 2 belonging to this specific session
assert.Equal(t, []string{"lkjhg"}, ids)
})
t.Run("returns desc sorted list of snapshots that belong to a session", func(t *testing.T) {
snapshots, err := s.GetSnapshotList(ctx, cloudmigration.ListSnapshotsQuery{SessionUID: sessionUID, Page: 1, Limit: 100, Sort: "latest"})
require.NoError(t, err)
ids := make([]string, 0)
for _, snapshot := range snapshots {
ids = append(ids, snapshot.UID)
}
// Return desc sorted snapshots belonging to this specific session
assert.Equal(t, []string{"lkjhg", "poiuy"}, ids)
})
@@ -345,7 +381,7 @@ func setUpTest(t *testing.T) (*sqlstore.SQLStore, *sqlStore) {
cloud_migration_snapshot (session_uid, uid, created, updated, finished, status)
VALUES
('qwerty', 'poiuy', '2024-03-25 15:30:36.000', '2024-03-27 15:30:43.000', '2024-03-27 15:30:43.000', "finished"),
('qwerty', 'lkjhg', '2024-03-25 15:30:36.000', '2024-03-27 15:30:43.000', '2024-03-27 15:30:43.000', "finished"),
('qwerty', 'lkjhg', '2024-03-26 15:30:36.000', '2024-03-27 15:30:43.000', '2024-03-27 15:30:43.000', "finished"),
('zxcvbn', 'mnbvvc', '2024-03-25 15:30:36.000', '2024-03-27 15:30:43.000', '2024-03-27 15:30:43.000', "finished");
`,
)