-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
- Loading branch information
Showing
13 changed files
with
167 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
## Admins | ||
|
||
| Admin | GitHub ID | Affiliation | | ||
| --------------- | --------------------------------------- | ----------- | | ||
| Henri Yandell | [hyandell](https://github.com/hyandell) | Amazon | | ||
| Admin | GitHub ID | Affiliation | | ||
| ------------- | --------------------------------------- | ----------- | | ||
| Henri Yandell | [hyandell](https://github.com/hyandell) | Amazon | | ||
|
||
[This document](https://github.com/opensearch-project/.github/blob/main/ADMINS.md) explains what admins do in this repo. and how they should be doing it. If you're interested in becoming a maintainer, see [MAINTAINERS](MAINTAINERS.md). If you're interested in contributing, see [CONTRIBUTING](CONTRIBUTING.md). |
This file contains 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 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
## Contributing to this Project | ||
|
||
OpenSearch is a community project that is built and maintained by people just like **you**. | ||
OpenSearch is a community project that is built and maintained by people just like **you**. | ||
[This document](https://github.com/opensearch-project/.github/blob/main/CONTRIBUTING.md) explains how you can contribute to this and related projects. |
This file contains 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 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 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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
roots: ['<rootDir>/test'], | ||
testMatch: ['**/*.test.ts'], | ||
roots: ['<rootDir>/test'], // Points to 'test' directory where your test files live | ||
testMatch: ['**/*.test.ts'], // Match test files ending with `.test.ts` | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest' | ||
} | ||
'^.+\\.tsx?$': 'ts-jest', | ||
}, | ||
}; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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,107 @@ | ||
import { STSClient, AssumeRoleCommand } from '@aws-sdk/client-sts'; | ||
import { Client as OpenSearchClient } from '@opensearch-project/opensearch'; | ||
import { OpensearchClient } from '../../src/utility/opensearchclient'; // Adjust import path as needed | ||
|
||
jest.mock('@aws-sdk/client-sts'); | ||
jest.mock('@opensearch-project/opensearch'); | ||
jest.mock('@opensearch-project/opensearch/lib/aws/index', () => ({ | ||
AwsSigv4Signer: jest.fn().mockReturnValue({}), | ||
})); | ||
|
||
describe('OpensearchClient', () => { | ||
const mockRoleArn = 'arn:aws:iam::123456789012:role/MyRole'; | ||
const mockRegion = 'us-east-1'; | ||
const mockOpenSearchUrl = 'https://my-opensearch-cluster.example.com'; | ||
const mockCredentials = { | ||
AccessKeyId: 'mockAccessKeyId', | ||
SecretAccessKey: 'mockSecretAccessKey', | ||
SessionToken: 'mockSessionToken', | ||
}; | ||
|
||
beforeAll(() => { | ||
process.env.ROLE_ARN = mockRoleArn; | ||
process.env.REGION = mockRegion; | ||
process.env.OPENSEARCH_URL = mockOpenSearchUrl; | ||
}); | ||
|
||
afterAll(() => { | ||
delete process.env.ROLE_ARN; | ||
delete process.env.REGION; | ||
delete process.env.OPENSEARCH_URL; | ||
}); | ||
|
||
// Ensure the STSClient mock is shared across all tests | ||
beforeEach(() => { | ||
(STSClient as jest.Mock).mockImplementation(() => ({ | ||
send: jest.fn().mockResolvedValue({ | ||
Credentials: mockCredentials, | ||
}), | ||
})); | ||
}); | ||
|
||
describe('getClient', () => { | ||
it('should return an OpenSearch client with valid credentials', async () => { | ||
const opensearchClient = new OpensearchClient(); | ||
const client = await opensearchClient.getClient(); | ||
|
||
expect(STSClient).toHaveBeenCalledWith({ region: mockRegion }); | ||
expect(AssumeRoleCommand).toHaveBeenCalledWith({ | ||
RoleArn: mockRoleArn, | ||
RoleSessionName: 'githubWorkflowRunsMonitorSession', | ||
}); | ||
expect(client).toBeInstanceOf(OpenSearchClient); | ||
}); | ||
|
||
it('should throw an error if credentials are undefined', async () => { | ||
// Override the mock for this test case | ||
(STSClient as jest.Mock).mockImplementation(() => ({ | ||
send: jest.fn().mockResolvedValue({ | ||
Credentials: undefined, | ||
}), | ||
})); | ||
|
||
const opensearchClient = new OpensearchClient(); | ||
|
||
await expect(opensearchClient.getClient()).rejects.toThrow( | ||
'Failed to assume role: credentials are undefined.' | ||
); | ||
}); | ||
}); | ||
|
||
describe('bulkIndex', () => { | ||
let consoleErrorSpy: jest.SpyInstance; | ||
|
||
beforeEach(() => { | ||
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
}); | ||
|
||
afterEach(() => { | ||
consoleErrorSpy.mockRestore(); | ||
}); | ||
|
||
it('should throw an error if bulk indexing fails', async () => { | ||
const mockClient = { | ||
bulk: jest.fn().mockResolvedValue({ | ||
body: { | ||
errors: true, | ||
items: [ | ||
{ | ||
index: { error: { type: 'some_error', reason: 'Some error occurred' } }, | ||
}, | ||
], | ||
}, | ||
}), | ||
}; | ||
|
||
(OpenSearchClient as jest.Mock).mockImplementation(() => mockClient); | ||
|
||
const opensearchClient = new OpensearchClient(); | ||
const documents = [{ id: 1, name: 'Document 1' }]; | ||
const index = 'test-index'; | ||
|
||
await expect(opensearchClient.bulkIndex(index, documents)).rejects.toThrow( | ||
'Bulk indexing errors: [{"type":"some_error","reason":"Some error occurred"}]' | ||
); | ||
}); | ||
}); | ||
}); |