-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add selectable regions to object storage wizard #581
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
10 commits
Select commit
Hold shift + click to select a range
40c7631
fix: obj post body
j-zimnowoda f525fd1
feat: add unit tests for obj wizard
ferruhcihan cff4797
feat: add linode api package
ferruhcihan 7802c60
feat: add object storage wizard unit tests
ferruhcihan da9aabd
feat: update obj wizard flow
ferruhcihan ad5931d
fix: lint
ferruhcihan 2012574
fix: objStorageRegions
ferruhcihan 6cfef9c
fix: obj wizard
ferruhcihan 03284e7
fix: rename clusterId variable to lkeClusterId
ferruhcihan dc07149
feat: update obj wizard comments
ferruhcihan 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,157 @@ | ||
| import { ObjectStorageKey } from '@linode/api-v4' | ||
| import { expect } from 'chai' | ||
| import proxyquire from 'proxyquire' | ||
| import sinon from 'sinon' | ||
| import { OtomiError } from 'src/error' | ||
|
|
||
| describe('ObjectStorageClient', () => { | ||
| let ObjectStorageClient: any | ||
| let setTokenStub: sinon.SinonStub | ||
| let getKubernetesClusterStub: sinon.SinonStub | ||
| let createObjectStorageKeysStub: sinon.SinonStub | ||
| let createBucketStub: sinon.SinonStub | ||
| let client: any | ||
| const clusterId = 12345 | ||
|
|
||
| beforeEach(() => { | ||
| setTokenStub = sinon.stub() | ||
| getKubernetesClusterStub = sinon.stub() | ||
| createObjectStorageKeysStub = sinon.stub() | ||
| createBucketStub = sinon.stub() | ||
|
|
||
| // Use proxyquire to mock the module imports | ||
| const module = proxyquire('./wizardUtils.ts', { | ||
| '@linode/api-v4': { | ||
| setToken: setTokenStub, | ||
| getKubernetesCluster: getKubernetesClusterStub, | ||
| createObjectStorageKeys: createObjectStorageKeysStub, | ||
| createBucket: createBucketStub, | ||
| }, | ||
| }) | ||
|
|
||
| ObjectStorageClient = module.ObjectStorageClient | ||
| client = new ObjectStorageClient('test-token') | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| sinon.restore() | ||
| }) | ||
|
|
||
| describe('constructor', () => { | ||
| it('should set token when initialized', () => { | ||
| expect(setTokenStub.calledOnceWith('test-token')).to.be.true | ||
| }) | ||
| }) | ||
|
|
||
| describe('createObjectStorageBucket', () => { | ||
| const label = 'test-bucket' | ||
| const region = 'us-east' | ||
|
|
||
| it('should successfully create bucket', async () => { | ||
| const mockResponse = { label: 'test-bucket' } | ||
| createBucketStub.resolves(mockResponse) | ||
|
|
||
| const result = await client.createObjectStorageBucket(label, region) | ||
|
|
||
| expect( | ||
| createBucketStub.calledOnceWith({ | ||
| label, | ||
| region, | ||
| }), | ||
| ).to.be.true | ||
| expect(result).to.equal('test-bucket') | ||
| }) | ||
|
|
||
| it('should throw OtomiError when bucket creation fails', async () => { | ||
| const mockError = { | ||
| response: { | ||
| status: 401, | ||
| data: { errors: [{ reason: 'Your OAuth token is not authorized to use this endpoint' }] }, | ||
| }, | ||
| } | ||
| createBucketStub.rejects(mockError) | ||
|
|
||
| try { | ||
| await client.createObjectStorageBucket(label, region) | ||
| expect.fail('Should have thrown an error') | ||
| } catch (error) { | ||
| expect(error).to.be.instanceOf(OtomiError) | ||
| expect(error.publicMessage).to.equal('Your OAuth token is not authorized to use this endpoint') | ||
| expect(error.code).to.equal(401) | ||
| } | ||
| }) | ||
|
|
||
| it('should throw OtomiError with default message when no specific error info', async () => { | ||
| const mockError = { | ||
| response: { | ||
| status: 500, | ||
| }, | ||
| } | ||
| createBucketStub.rejects(mockError) | ||
|
|
||
| try { | ||
| await client.createObjectStorageBucket(label, region) | ||
| expect.fail('Should have thrown an error') | ||
| } catch (error) { | ||
| expect(error).to.be.instanceOf(OtomiError) | ||
| expect(error.publicMessage).to.equal('Error creating object storage bucket') | ||
| expect(error.code).to.equal(500) | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| describe('createObjectStorageKey', () => { | ||
| const region = 'us-east' | ||
| const bucketNames = ['bucket1', 'bucket2'] | ||
| let clock: sinon.SinonFakeTimers | ||
|
|
||
| beforeEach(() => { | ||
| const fixedDate = new Date('2024-01-01T12:00:00.000Z') | ||
| clock = sinon.useFakeTimers(fixedDate.getTime()) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| clock.restore() | ||
| }) | ||
|
|
||
| it('should successfully create object storage keys', async () => { | ||
| const mockResponse: Pick<ObjectStorageKey, 'access_key' | 'secret_key' | 'regions'> = { | ||
| access_key: 'test-access-key', | ||
| secret_key: 'test-secret-key', | ||
| regions: [{ id: 'us-east', s3_endpoint: 'us-east-1.linodeobjects.com' }], | ||
| } | ||
| createObjectStorageKeysStub.resolves(mockResponse) | ||
| const result = await client.createObjectStorageKey(clusterId, region, bucketNames) | ||
|
|
||
| expect(createObjectStorageKeysStub.calledOnce).to.be.true | ||
| expect(createObjectStorageKeysStub.firstCall.args[0]).to.deep.equal({ | ||
| label: `lke${clusterId}-key-1704110400000`, | ||
| regions: [region], | ||
| bucket_access: [ | ||
| { bucket_name: 'bucket1', permissions: 'read_write', region }, | ||
| { bucket_name: 'bucket2', permissions: 'read_write', region }, | ||
| ], | ||
| }) | ||
| expect(result).to.deep.equal(mockResponse) | ||
| }) | ||
|
|
||
| it('should throw OtomiError when keys creation fails', async () => { | ||
| const mockError = { | ||
| response: { | ||
| data: { errors: [{ reason: 'Your OAuth token is not authorized to use this endpoint' }] }, | ||
| status: 401, | ||
| }, | ||
| } | ||
| createObjectStorageKeysStub.rejects(mockError) | ||
|
|
||
| try { | ||
| await client.createObjectStorageKey(clusterId, region, bucketNames) | ||
| expect.fail('Should have thrown an error') | ||
| } catch (error) { | ||
| expect(error).to.be.instanceOf(OtomiError) | ||
| expect(error.publicMessage).to.equal('Your OAuth token is not authorized to use this endpoint') | ||
| expect(error.code).to.equal(401) | ||
| } | ||
| }) | ||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.