-
Notifications
You must be signed in to change notification settings - Fork 41
Implement Backups & Restore #342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cd46032
implement initial backup and restore actions and types
austin-denoble 8b5b1ab
add validation for backup/restore methods, fix a few bugs around acce…
austin-denoble 808b311
add doc comments for backup and restore methods
austin-denoble 16f4d4f
add doc comments for new types and interfaces
austin-denoble 652a17b
bump amount of total time we retry on flaky integration tests, reduce…
austin-denoble 7c49f1f
add backsup to README
austin-denoble 1946cef
add unit test coverage for all backup / restore operations
austin-denoble 9826255
clean up doc comments
austin-denoble 6a91d7d
add retries to namespaces delete test
austin-denoble File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { createBackup } from '../createBackup'; | ||
import { ManageIndexesApi } from '../../pinecone-generated-ts-fetch/db_control'; | ||
import type { | ||
BackupModel, | ||
CreateBackupOperationRequest, | ||
} from '../../pinecone-generated-ts-fetch/db_control'; | ||
import { PineconeArgumentError } from '../../errors'; | ||
|
||
const setupCreateBackupResponse = ( | ||
createBackupResponse = {} as BackupModel, | ||
isCreateBackupSuccess = true | ||
) => { | ||
const fakeCreateBackup: ( | ||
req: CreateBackupOperationRequest | ||
) => Promise<BackupModel> = jest | ||
.fn() | ||
.mockImplementation(() => | ||
isCreateBackupSuccess | ||
? Promise.resolve(createBackupResponse) | ||
: Promise.reject(createBackupResponse) | ||
); | ||
|
||
const MIA = { | ||
createBackup: fakeCreateBackup, | ||
} as ManageIndexesApi; | ||
|
||
return MIA; | ||
}; | ||
|
||
describe('createBackup', () => { | ||
test('calls the openapi create backup endpoint, passing name and description', async () => { | ||
const MIA = setupCreateBackupResponse(); | ||
const returned = await createBackup(MIA)({ | ||
indexName: 'index-name', | ||
name: 'backup-name', | ||
description: 'backup-description', | ||
}); | ||
expect(returned).toEqual({} as BackupModel); | ||
expect(MIA.createBackup).toHaveBeenCalledWith({ | ||
indexName: 'index-name', | ||
createBackupRequest: { | ||
name: 'backup-name', | ||
description: 'backup-description', | ||
}, | ||
}); | ||
}); | ||
|
||
test('throws an error if indexName is not provided', async () => { | ||
const MIA = setupCreateBackupResponse(); | ||
await expect( | ||
createBackup(MIA)({ | ||
indexName: '', | ||
name: 'backup-name', | ||
description: 'backup-description', | ||
}) | ||
).rejects.toThrow( | ||
new PineconeArgumentError( | ||
'You must pass a non-empty string for `indexName` in order to create a backup' | ||
) | ||
); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { createIndexFromBackup } from '../createIndexFromBackup'; | ||
import { ManageIndexesApi } from '../../pinecone-generated-ts-fetch/db_control'; | ||
import type { | ||
BackupModel, | ||
CreateIndexFromBackupOperationRequest, | ||
CreateIndexFromBackupResponse, | ||
} from '../../pinecone-generated-ts-fetch/db_control'; | ||
import { PineconeArgumentError } from '../../errors'; | ||
|
||
const setupCreateIndexFromBackupResponse = ( | ||
createIndexFromBackupResponse = {} as BackupModel, | ||
isCreateIndexFromBackupSuccess = true | ||
) => { | ||
const fakeCreateIndexFromBackup: ( | ||
req: CreateIndexFromBackupOperationRequest | ||
) => Promise<CreateIndexFromBackupResponse> = jest | ||
.fn() | ||
.mockImplementation(() => | ||
isCreateIndexFromBackupSuccess | ||
? Promise.resolve(createIndexFromBackupResponse) | ||
: Promise.reject(createIndexFromBackupResponse) | ||
); | ||
|
||
const MIA = { | ||
createIndexFromBackup: fakeCreateIndexFromBackup, | ||
} as ManageIndexesApi; | ||
|
||
return MIA; | ||
}; | ||
|
||
describe('createIndexFromBackup', () => { | ||
test('calls the openapi create indexn from backup endpoint, passing backupId, name, tags, and deletionProtection', async () => { | ||
const MIA = setupCreateIndexFromBackupResponse(); | ||
const returned = await createIndexFromBackup(MIA)({ | ||
backupId: '12345-ajfielkas-123123', | ||
name: 'my-restored-index', | ||
tags: { test: 'test-tag' }, | ||
deletionProtection: 'enabled', | ||
}); | ||
expect(returned).toEqual({} as CreateIndexFromBackupResponse); | ||
expect(MIA.createIndexFromBackup).toHaveBeenCalledWith({ | ||
backupId: '12345-ajfielkas-123123', | ||
createIndexFromBackupRequest: { | ||
name: 'my-restored-index', | ||
tags: { test: 'test-tag' }, | ||
deletionProtection: 'enabled', | ||
}, | ||
}); | ||
}); | ||
|
||
test('throws an error if backupId or name are not provided', async () => { | ||
const MIA = setupCreateIndexFromBackupResponse(); | ||
await expect( | ||
createIndexFromBackup(MIA)({ | ||
backupId: '', | ||
name: 'my-restored-index', | ||
}) | ||
).rejects.toThrow( | ||
new PineconeArgumentError( | ||
'You must pass a non-empty string for `backupId` in order to create an index from backup' | ||
) | ||
); | ||
await expect( | ||
createIndexFromBackup(MIA)({ | ||
backupId: '123-123-123-123', | ||
name: '', | ||
}) | ||
).rejects.toThrow( | ||
new PineconeArgumentError( | ||
'You must pass a non-empty string for `name` in order to create an index from backup' | ||
) | ||
); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as before, isn't indexName a required field since its a path parameter?