1- const { Backend, CreateStatus, RestoreStatus } = require ( "." ) ;
21const weaviate = require ( "../index" ) ;
32const { createTestFoodSchemaAndData, cleanupTestFood, PIZZA_CLASS_NAME , SOUP_CLASS_NAME } = require ( "../utils/testData" ) ;
43
54const DOCKER_COMPOSE_BACKUPS_DIR = "/tmp/backups" ;
65
76describe ( "create and restore backup with waiting" , ( ) => {
8- const BACKEND = Backend . FILESYSTEM ;
9- const BACKUP_ID = "backup-id-" + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER )
7+ const BACKEND = weaviate . backup . Backend . FILESYSTEM ;
8+ const BACKUP_ID = randomBackupId ( )
109
1110 const client = weaviate . client ( {
1211 scheme : "http" ,
@@ -30,7 +29,7 @@ describe("create and restore backup with waiting", () => {
3029 expect ( createResponse . classes ) . toContain ( PIZZA_CLASS_NAME ) ;
3130 expect ( createResponse . path ) . toBe ( `${ DOCKER_COMPOSE_BACKUPS_DIR } /${ BACKUP_ID } ` ) ;
3231 expect ( createResponse . backend ) . toBe ( BACKEND ) ;
33- expect ( createResponse . status ) . toBe ( CreateStatus . SUCCESS ) ;
32+ expect ( createResponse . status ) . toBe ( weaviate . backup . CreateStatus . SUCCESS ) ;
3433 expect ( createResponse . error ) . toBeUndefined ( ) ;
3534 } )
3635 . catch ( err => fail ( "should not fail on create backup: " + err ) ) ;
@@ -47,7 +46,7 @@ describe("create and restore backup with waiting", () => {
4746 expect ( createStatusResponse . id ) . toBe ( BACKUP_ID ) ;
4847 expect ( createStatusResponse . path ) . toBe ( `${ DOCKER_COMPOSE_BACKUPS_DIR } /${ BACKUP_ID } ` ) ;
4948 expect ( createStatusResponse . backend ) . toBe ( BACKEND ) ;
50- expect ( createStatusResponse . status ) . toBe ( CreateStatus . SUCCESS ) ;
49+ expect ( createStatusResponse . status ) . toBe ( weaviate . backup . CreateStatus . SUCCESS ) ;
5150 expect ( createStatusResponse . error ) . toBeUndefined ( ) ;
5251 } )
5352 . catch ( err => fail ( "should not fail on create status: " + err ) ) ;
@@ -73,7 +72,7 @@ describe("create and restore backup with waiting", () => {
7372 expect ( restoreResponse . classes ) . toContain ( PIZZA_CLASS_NAME ) ;
7473 expect ( restoreResponse . path ) . toBe ( `${ DOCKER_COMPOSE_BACKUPS_DIR } /${ BACKUP_ID } ` ) ;
7574 expect ( restoreResponse . backend ) . toBe ( BACKEND ) ;
76- expect ( restoreResponse . status ) . toBe ( RestoreStatus . SUCCESS ) ;
75+ expect ( restoreResponse . status ) . toBe ( weaviate . backup . RestoreStatus . SUCCESS ) ;
7776 expect ( restoreResponse . error ) . toBeUndefined ( ) ;
7877 } )
7978 . catch ( err => fail ( "should not fail on restore backup: " + err ) ) ;
@@ -90,7 +89,7 @@ describe("create and restore backup with waiting", () => {
9089 expect ( restoreStatusResponse . id ) . toBe ( BACKUP_ID ) ;
9190 expect ( restoreStatusResponse . path ) . toBe ( `${ DOCKER_COMPOSE_BACKUPS_DIR } /${ BACKUP_ID } ` ) ;
9291 expect ( restoreStatusResponse . backend ) . toBe ( BACKEND ) ;
93- expect ( restoreStatusResponse . status ) . toBe ( RestoreStatus . SUCCESS ) ;
92+ expect ( restoreStatusResponse . status ) . toBe ( weaviate . backup . RestoreStatus . SUCCESS ) ;
9493 expect ( restoreStatusResponse . error ) . toBeUndefined ( ) ;
9594 } )
9695 . catch ( err => fail ( "should not fail on restore status: " + err ) ) ;
@@ -100,8 +99,8 @@ describe("create and restore backup with waiting", () => {
10099} ) ;
101100
102101describe ( "create and restore backup without waiting" , ( ) => {
103- const BACKEND = Backend . FILESYSTEM ;
104- const BACKUP_ID = "backup-id-" + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER )
102+ const BACKEND = weaviate . backup . Backend . FILESYSTEM ;
103+ const BACKUP_ID = randomBackupId ( )
105104
106105 const client = weaviate . client ( {
107106 scheme : "http" ,
@@ -124,7 +123,7 @@ describe("create and restore backup without waiting", () => {
124123 expect ( createResponse . classes ) . toContain ( PIZZA_CLASS_NAME ) ;
125124 expect ( createResponse . path ) . toBe ( `${ DOCKER_COMPOSE_BACKUPS_DIR } /${ BACKUP_ID } ` ) ;
126125 expect ( createResponse . backend ) . toBe ( BACKEND ) ;
127- expect ( createResponse . status ) . toBe ( CreateStatus . STARTED ) ;
126+ expect ( createResponse . status ) . toBe ( weaviate . backup . CreateStatus . STARTED ) ;
128127 expect ( createResponse . error ) . toBeUndefined ( ) ;
129128 } )
130129 . catch ( err => fail ( "should not fail on create backup: " + err ) ) ;
@@ -138,7 +137,7 @@ describe("create and restore backup without waiting", () => {
138137 const loop = ( ) => {
139138 statusGetter . do ( )
140139 . then ( createStatusResponse => {
141- if ( createStatusResponse . status == CreateStatus . SUCCESS || createStatusResponse . status == CreateStatus . FAILED ) {
140+ if ( createStatusResponse . status == weaviate . backup . CreateStatus . SUCCESS || createStatusResponse . status == weaviate . backup . CreateStatus . FAILED ) {
142141 resolve ( createStatusResponse ) ;
143142 } else {
144143 setTimeout ( loop , 100 ) ;
@@ -152,7 +151,7 @@ describe("create and restore backup without waiting", () => {
152151 expect ( createStatusResponse . id ) . toBe ( BACKUP_ID ) ;
153152 expect ( createStatusResponse . path ) . toBe ( `${ DOCKER_COMPOSE_BACKUPS_DIR } /${ BACKUP_ID } ` ) ;
154153 expect ( createStatusResponse . backend ) . toBe ( BACKEND ) ;
155- expect ( createStatusResponse . status ) . toBe ( CreateStatus . SUCCESS ) ;
154+ expect ( createStatusResponse . status ) . toBe ( weaviate . backup . CreateStatus . SUCCESS ) ;
156155 expect ( createStatusResponse . error ) . toBeUndefined ( ) ;
157156 } )
158157 . catch ( err => fail ( "should not fail on create status: " + err ) )
@@ -179,7 +178,7 @@ describe("create and restore backup without waiting", () => {
179178 expect ( restoreResponse . classes ) . toContain ( PIZZA_CLASS_NAME ) ;
180179 expect ( restoreResponse . path ) . toBe ( `${ DOCKER_COMPOSE_BACKUPS_DIR } /${ BACKUP_ID } ` ) ;
181180 expect ( restoreResponse . backend ) . toBe ( BACKEND ) ;
182- expect ( restoreResponse . status ) . toBe ( RestoreStatus . STARTED ) ;
181+ expect ( restoreResponse . status ) . toBe ( weaviate . backup . RestoreStatus . STARTED ) ;
183182 expect ( restoreResponse . error ) . toBeUndefined ( ) ;
184183 } )
185184 . catch ( err => fail ( "should not fail on restore backup: " + err ) ) ;
@@ -193,7 +192,7 @@ describe("create and restore backup without waiting", () => {
193192 const loop = ( ) => {
194193 statusGetter . do ( )
195194 . then ( restoreStatusResponse => {
196- if ( restoreStatusResponse . status == RestoreStatus . SUCCESS || restoreStatusResponse . status == RestoreStatus . FAILED ) {
195+ if ( restoreStatusResponse . status == weaviate . backup . RestoreStatus . SUCCESS || restoreStatusResponse . status == weaviate . backup . RestoreStatus . FAILED ) {
197196 resolve ( restoreStatusResponse ) ;
198197 } else {
199198 setTimeout ( loop , 100 ) ;
@@ -207,7 +206,7 @@ describe("create and restore backup without waiting", () => {
207206 expect ( restoreStatusResponse . id ) . toBe ( BACKUP_ID ) ;
208207 expect ( restoreStatusResponse . path ) . toBe ( `${ DOCKER_COMPOSE_BACKUPS_DIR } /${ BACKUP_ID } ` ) ;
209208 expect ( restoreStatusResponse . backend ) . toBe ( BACKEND ) ;
210- expect ( restoreStatusResponse . status ) . toBe ( RestoreStatus . SUCCESS ) ;
209+ expect ( restoreStatusResponse . status ) . toBe ( weaviate . backup . RestoreStatus . SUCCESS ) ;
211210 expect ( restoreStatusResponse . error ) . toBeUndefined ( ) ;
212211 } )
213212 . catch ( err => fail ( "should not fail on restore backup: " + err ) ) ;
@@ -219,8 +218,8 @@ describe("create and restore backup without waiting", () => {
219218} ) ;
220219
221220describe ( "create and restore 1 of 2 classes" , ( ) => {
222- const BACKEND = Backend . FILESYSTEM ;
223- const BACKUP_ID = "backup-id-" + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER )
221+ const BACKEND = weaviate . backup . Backend . FILESYSTEM ;
222+ const BACKUP_ID = randomBackupId ( )
224223
225224 const client = weaviate . client ( {
226225 scheme : "http" ,
@@ -247,7 +246,7 @@ describe("create and restore 1 of 2 classes", () => {
247246 expect ( createResponse . classes ) . toContain ( SOUP_CLASS_NAME ) ;
248247 expect ( createResponse . path ) . toBe ( `${ DOCKER_COMPOSE_BACKUPS_DIR } /${ BACKUP_ID } ` ) ;
249248 expect ( createResponse . backend ) . toBe ( BACKEND ) ;
250- expect ( createResponse . status ) . toBe ( CreateStatus . SUCCESS ) ;
249+ expect ( createResponse . status ) . toBe ( weaviate . backup . CreateStatus . SUCCESS ) ;
251250 expect ( createResponse . error ) . toBeUndefined ( ) ;
252251 } )
253252 . catch ( err => fail ( "should not fail on create backup: " + err ) ) ;
@@ -267,7 +266,7 @@ describe("create and restore 1 of 2 classes", () => {
267266 expect ( createStatusResponse . id ) . toBe ( BACKUP_ID ) ;
268267 expect ( createStatusResponse . path ) . toBe ( `${ DOCKER_COMPOSE_BACKUPS_DIR } /${ BACKUP_ID } ` ) ;
269268 expect ( createStatusResponse . backend ) . toBe ( BACKEND ) ;
270- expect ( createStatusResponse . status ) . toBe ( CreateStatus . SUCCESS ) ;
269+ expect ( createStatusResponse . status ) . toBe ( weaviate . backup . CreateStatus . SUCCESS ) ;
271270 expect ( createStatusResponse . error ) . toBeUndefined ( ) ;
272271 } )
273272 . catch ( err => fail ( "should not fail on create status: " + err ) ) ;
@@ -293,7 +292,7 @@ describe("create and restore 1 of 2 classes", () => {
293292 expect ( restoreResponse . classes ) . toContain ( PIZZA_CLASS_NAME ) ;
294293 expect ( restoreResponse . path ) . toBe ( `${ DOCKER_COMPOSE_BACKUPS_DIR } /${ BACKUP_ID } ` ) ;
295294 expect ( restoreResponse . backend ) . toBe ( BACKEND ) ;
296- expect ( restoreResponse . status ) . toBe ( RestoreStatus . SUCCESS ) ;
295+ expect ( restoreResponse . status ) . toBe ( weaviate . backup . RestoreStatus . SUCCESS ) ;
297296 expect ( restoreResponse . error ) . toBeUndefined ( ) ;
298297 } )
299298 . catch ( err => fail ( "should not fail on restore backup: " + err ) ) ;
@@ -313,7 +312,7 @@ describe("create and restore 1 of 2 classes", () => {
313312 expect ( restoreStatusResponse . id ) . toBe ( BACKUP_ID ) ;
314313 expect ( restoreStatusResponse . path ) . toBe ( `${ DOCKER_COMPOSE_BACKUPS_DIR } /${ BACKUP_ID } ` ) ;
315314 expect ( restoreStatusResponse . backend ) . toBe ( BACKEND ) ;
316- expect ( restoreStatusResponse . status ) . toBe ( RestoreStatus . SUCCESS ) ;
315+ expect ( restoreStatusResponse . status ) . toBe ( weaviate . backup . RestoreStatus . SUCCESS ) ;
317316 expect ( restoreStatusResponse . error ) . toBeUndefined ( ) ;
318317 } )
319318 . catch ( err => fail ( "should not fail on restore status: " + err ) ) ;
@@ -324,7 +323,7 @@ describe("create and restore 1 of 2 classes", () => {
324323
325324describe ( "fail creating backup on not existing backend" , ( ) => {
326325 const BACKEND = "not-existing-backend" ;
327- const BACKUP_ID = "backup-id-" + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER )
326+ const BACKUP_ID = randomBackupId ( )
328327
329328 const client = weaviate . client ( {
330329 scheme : "http" ,
@@ -351,7 +350,7 @@ describe("fail creating backup on not existing backend", () => {
351350
352351describe ( "fail checking create status on not existing backend" , ( ) => {
353352 const BACKEND = "not-existing-backend" ;
354- const BACKUP_ID = "backup-id-" + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER )
353+ const BACKUP_ID = randomBackupId ( )
355354
356355 const client = weaviate . client ( {
357356 scheme : "http" ,
@@ -378,7 +377,7 @@ describe("fail checking create status on not existing backend", () => {
378377describe ( "fail restoring backup on not existing backend" , ( ) => {
379378 const CLASS_NAME = "not-existing-class" ;
380379 const BACKEND = "not-existing-backend" ;
381- const BACKUP_ID = "backup-id-" + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER )
380+ const BACKUP_ID = randomBackupId ( )
382381
383382 const client = weaviate . client ( {
384383 scheme : "http" ,
@@ -405,8 +404,8 @@ describe("fail restoring backup on not existing backend", () => {
405404
406405describe ( "fail creating backup for not existing class" , ( ) => {
407406 const CLASS_NAME = "not-existing-class" ;
408- const BACKEND = Backend . FILESYSTEM ;
409- const BACKUP_ID = "backup-id-" + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER )
407+ const BACKEND = weaviate . backup . Backend . FILESYSTEM ;
408+ const BACKUP_ID = randomBackupId ( )
410409
411410 const client = weaviate . client ( {
412411 scheme : "http" ,
@@ -432,8 +431,8 @@ describe("fail creating backup for not existing class", () => {
432431} ) ;
433432
434433describe ( "fail restoring backup for existing class" , ( ) => {
435- const BACKEND = Backend . FILESYSTEM ;
436- const BACKUP_ID = "backup-id-" + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER )
434+ const BACKEND = weaviate . backup . Backend . FILESYSTEM ;
435+ const BACKUP_ID = randomBackupId ( )
437436
438437 const client = weaviate . client ( {
439438 scheme : "http" ,
@@ -469,8 +468,8 @@ describe("fail restoring backup for existing class", () => {
469468} ) ;
470469
471470describe ( "fail creating existing backup" , ( ) => {
472- const BACKEND = Backend . FILESYSTEM ;
473- const BACKUP_ID = "backup-id-" + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER )
471+ const BACKEND = weaviate . backup . Backend . FILESYSTEM ;
472+ const BACKUP_ID = randomBackupId ( )
474473
475474 const client = weaviate . client ( {
476475 scheme : "http" ,
@@ -506,8 +505,8 @@ describe("fail creating existing backup", () => {
506505} ) ;
507506
508507describe ( "fail checking create status for not existing backup" , ( ) => {
509- const BACKEND = Backend . FILESYSTEM ;
510- const BACKUP_ID = "backup-id-" + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER )
508+ const BACKEND = weaviate . backup . Backend . FILESYSTEM ;
509+ const BACKUP_ID = randomBackupId ( )
511510
512511 const client = weaviate . client ( {
513512 scheme : "http" ,
@@ -532,8 +531,8 @@ describe("fail checking create status for not existing backup", () => {
532531} ) ;
533532
534533describe ( "fail restoring not existing backup" , ( ) => {
535- const BACKEND = Backend . FILESYSTEM ;
536- const BACKUP_ID = "backup-id-" + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER )
534+ const BACKEND = weaviate . backup . Backend . FILESYSTEM ;
535+ const BACKUP_ID = randomBackupId ( )
537536
538537 const client = weaviate . client ( {
539538 scheme : "http" ,
@@ -559,8 +558,8 @@ describe("fail restoring not existing backup", () => {
559558} ) ;
560559
561560describe ( "fail checking restore status for not started restore" , ( ) => {
562- const BACKEND = Backend . FILESYSTEM ;
563- const BACKUP_ID = "backup-id-" + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER )
561+ const BACKEND = weaviate . backup . Backend . FILESYSTEM ;
562+ const BACKUP_ID = randomBackupId ( )
564563
565564 const client = weaviate . client ( {
566565 scheme : "http" ,
@@ -596,8 +595,8 @@ describe("fail checking restore status for not started restore", () => {
596595} ) ;
597596
598597describe ( "fail creating backup for both include and exclude classes" , ( ) => {
599- const BACKEND = Backend . FILESYSTEM ;
600- const BACKUP_ID = "backup-id-" + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER )
598+ const BACKEND = weaviate . backup . Backend . FILESYSTEM ;
599+ const BACKUP_ID = randomBackupId ( )
601600
602601 const client = weaviate . client ( {
603602 scheme : "http" ,
@@ -626,8 +625,8 @@ describe("fail creating backup for both include and exclude classes", () => {
626625} ) ;
627626
628627describe ( "fail restoring backup for both include and exclude classes" , ( ) => {
629- const BACKEND = Backend . FILESYSTEM ;
630- const BACKUP_ID = "backup-id-" + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER )
628+ const BACKEND = weaviate . backup . Backend . FILESYSTEM ;
629+ const BACKUP_ID = randomBackupId ( )
631630
632631 const client = weaviate . client ( {
633632 scheme : "http" ,
@@ -672,8 +671,8 @@ describe("fail restoring backup for both include and exclude classes", () => {
672671} ) ;
673672
674673// describe("get all exising backups", () => {
675- // const BACKEND = Backend.FILESYSTEM;
676- // const BACKUP_ID = "backup-id-" + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER )
674+ // const BACKEND = weaviate.backup. Backend.FILESYSTEM;
675+ // const BACKUP_ID = randomBackupId( )
677676// const BACKUP_ID_PIZZA = BACKUP_ID + "-pizza";
678677// const BACKUP_ID_SOUP = BACKUP_ID + "-soup";
679678
@@ -738,3 +737,7 @@ function assertThatAllFoodObjectsExist(client, className, number) {
738737 . then ( data => expect ( data . data . Get [ className ] . length ) . toBe ( number ) )
739738 . catch ( err => fail ( number + " objects should exist: " + err ) ) ;
740739}
740+
741+ function randomBackupId ( ) {
742+ return "backup-id-" + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER )
743+ }
0 commit comments