Skip to content

Commit d5da106

Browse files
authored
Merge branch 'main' into feat/overwriteAlias
2 parents 4668ab4 + 8762b65 commit d5da106

File tree

4 files changed

+44
-91
lines changed

4 files changed

+44
-91
lines changed

src/backup/backupGetter.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/backup/journey.test.ts

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -950,56 +950,6 @@ describe('fails restoring backup with invalid compression config', () => {
950950
it('cleans up', () => cleanupTestFood(client));
951951
});
952952

953-
// describe("get all exising backups", () => {
954-
// const BACKEND: Backend = 'filesystem';
955-
// const BACKUP_ID = randomBackupId()
956-
// const BACKUP_ID_PIZZA = BACKUP_ID + "-pizza";
957-
// const BACKUP_ID_SOUP = BACKUP_ID + "-soup";
958-
959-
// const client = weaviate.client({
960-
// scheme: "http",
961-
// host: "localhost:8080",
962-
// });
963-
964-
// it("sets up", () => createTestFoodSchemaAndData(client));
965-
966-
// it("creates backup pizza", () => {
967-
// return client.backup.creator()
968-
// .withIncludeClassNames(PIZZA_CLASS_NAME)
969-
// .withBackend(BACKEND)
970-
// .withBackupId(BACKUP_ID_PIZZA)
971-
// .withWaitForCompletion(true)
972-
// .do()
973-
// .catch((err: any) => {throw new Error("should not fail on create backup: " + err)});
974-
// });
975-
976-
// it("creates backup soup", () => {
977-
// return client.backup.creator()
978-
// .withIncludeClassNames(SOUP_CLASS_NAME)
979-
// .withBackend(BACKEND)
980-
// .withBackupId(BACKUP_ID_SOUP)
981-
// .withWaitForCompletion(true)
982-
// .do()
983-
// .catch((err: any) => {throw new Error("should not fail on create backup: " + err)});
984-
// });
985-
986-
// it("get all", () => {
987-
// return client.backup.getter()
988-
// .withBackend(BACKEND)
989-
// .do()
990-
// .then(allResponse => {
991-
// expect(allResponse).toHaveLength(2);
992-
// expect(allResponse).toEqual(expect.arrayContaining([
993-
// expect.objectContaining({id: BACKUP_ID_PIZZA}),
994-
// expect.objectContaining({id: BACKUP_ID_SOUP}),
995-
// ]));
996-
// })
997-
// .catch((err: any) => {throw new Error("should not fail on getting all: " + err)});
998-
// });
999-
1000-
// it("cleans up", () => cleanupTestFood(client));
1001-
// });
1002-
1003953
function assertThatAllPizzasExist(client: WeaviateClient) {
1004954
return assertThatAllFoodObjectsExist(client, 'Pizza', 4);
1005955
}

src/collections/backup/client.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
BackupStatusReturn,
3131
} from './types.js';
3232

33-
export const backup = (connection: Connection) => {
33+
export const backup = (connection: Connection): Backup => {
3434
const parseStatus = (res: BackupCreateStatusResponse | BackupRestoreResponse): BackupStatusReturn => {
3535
if (res.id === undefined) {
3636
throw new WeaviateUnexpectedResponseError('Backup ID is undefined in response');
@@ -205,6 +205,9 @@ export const backup = (connection: Connection) => {
205205
}
206206
: parseResponse(res);
207207
},
208+
list: (backend: Backend): Promise<BackupReturn[]> => {
209+
return connection.get<BackupReturn[]>(`/backups/${backend}`);
210+
},
208211
};
209212
};
210213

@@ -254,4 +257,11 @@ export interface Backup {
254257
* @throws {WeaviateBackupCanceled} If the backup restoration is canceled.
255258
*/
256259
restore(args: BackupArgs<BackupConfigRestore>): Promise<BackupReturn>;
260+
261+
/** List existing backups (completed and in-progress) created in a given backend.
262+
*
263+
* @param {Backend} backend Backend whence to list backups.
264+
* @returns {Promise<BackupReturn[]>} The response from Weaviate.
265+
* */
266+
list(backend: Backend): Promise<BackupReturn[]>;
257267
}

src/collections/backup/integration.test.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-non-null-assertion */
22
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
33
/* eslint-disable no-await-in-loop */
4-
import { requireAtLeast } from '../../../test/version';
4+
import { requireAtLeast } from '../../../test/version.js';
55
import { Backend } from '../../backup/index.js';
66
import { WeaviateBackupFailed } from '../../errors.js';
77
import weaviate, { Collection, WeaviateClient } from '../../index.js';
@@ -200,6 +200,35 @@ describe('Integration testing of backups', () => {
200200
});
201201
});
202202

203-
function randomBackupId() {
204-
return 'backup-id-' + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
205-
}
203+
requireAtLeast(1, 32, 0).it('get all exising backups', async () => {
204+
await clientPromise.then(async (client) => {
205+
await client.collections.create({ name: 'TestListBackups' }).then((col) => col.data.insert());
206+
207+
const wantBackups: string[] = [];
208+
for (let i = 0; i < 3; i++) {
209+
wantBackups.push(
210+
await client.backup
211+
.create({
212+
backupId: randomBackupId(),
213+
backend: 'filesystem',
214+
includeCollections: ['TestListBackups'],
215+
waitForCompletion: true,
216+
})
217+
.then((res) => res.id)
218+
);
219+
}
220+
221+
const gotBackups: string[] = await client.backup
222+
.list('filesystem')
223+
.then((res) => res.map((bu) => bu.id));
224+
225+
// There may be other backups created in other tests;
226+
expect(gotBackups.length).toBeGreaterThanOrEqual(wantBackups.length);
227+
expect(gotBackups).toEqual(expect.arrayContaining(wantBackups));
228+
});
229+
});
230+
231+
function randomBackupId() {
232+
return 'backup-id-' + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
233+
}
234+
});

0 commit comments

Comments
 (0)