-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Index-based adaptor for integrations (#1381)
* Update comment for json adaptor construction Signed-off-by: Simeon Widdis <[email protected]> * Stub index data adaptor class Signed-off-by: Simeon Widdis <[email protected]> * Add initial impl for findIntegrationVersions Signed-off-by: Simeon Widdis <[email protected]> * Fill in simple getDirectoryType implementation Signed-off-by: Simeon Widdis <[email protected]> * Implement index adaptor as wrapper for json adaptor Signed-off-by: Simeon Widdis <[email protected]> * Add integration template type for index Signed-off-by: Simeon Widdis <[email protected]> * Fix lints for server/routes Signed-off-by: Simeon Widdis <[email protected]> * Fix integrations_manager lints Signed-off-by: Simeon Widdis <[email protected]> * Refactor template manager to support multiple readers at once Signed-off-by: Simeon Widdis <[email protected]> * Rename FileSystemCatalogDataAdaptor -> FileSystemDataAdaptor Signed-off-by: Simeon Widdis <[email protected]> * Add IndexReader to existing Manager logic Signed-off-by: Simeon Widdis <[email protected]> * Fix plugin label type Signed-off-by: Simeon Widdis <[email protected]> * Add tests for index adaptor Signed-off-by: Simeon Widdis <[email protected]> * Add object management to integration objects Signed-off-by: Simeon Widdis <[email protected]> * Fix bug with version parsing for numeric integration names Signed-off-by: Simeon Widdis <[email protected]> * Prioritize dynamic integrations over defaults Signed-off-by: Simeon Widdis <[email protected]> --------- Signed-off-by: Simeon Widdis <[email protected]>
- Loading branch information
Showing
15 changed files
with
368 additions
and
96 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
105 changes: 105 additions & 0 deletions
105
server/adaptors/integrations/repository/__test__/index_data_adaptor.test.ts
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,105 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { IntegrationReader } from '../integration_reader'; | ||
import { JsonCatalogDataAdaptor } from '../json_data_adaptor'; | ||
import { TEST_INTEGRATION_CONFIG } from '../../../../../test/constants'; | ||
import { savedObjectsClientMock } from '../../../../../../../src/core/server/mocks'; | ||
import { IndexDataAdaptor } from '../index_data_adaptor'; | ||
import { SavedObjectsClientContract } from '../../../../../../../src/core/server'; | ||
|
||
// Simplified catalog for integration searching -- Do not use for full deserialization tests. | ||
const TEST_CATALOG_NO_SERIALIZATION: SerializedIntegration[] = [ | ||
{ | ||
...(TEST_INTEGRATION_CONFIG as SerializedIntegration), | ||
name: 'sample1', | ||
}, | ||
{ | ||
...(TEST_INTEGRATION_CONFIG as SerializedIntegration), | ||
name: 'sample2', | ||
}, | ||
{ | ||
...(TEST_INTEGRATION_CONFIG as SerializedIntegration), | ||
name: 'sample2', | ||
version: '2.1.0', | ||
}, | ||
]; | ||
|
||
// Copy of json_data_adaptor.test.ts with new reader type | ||
// Since implementation at time of writing is to defer to json adaptor | ||
describe('Index Data Adaptor', () => { | ||
let mockClient: SavedObjectsClientContract; | ||
|
||
beforeEach(() => { | ||
mockClient = savedObjectsClientMock.create(); | ||
mockClient.find = jest.fn().mockResolvedValue({ | ||
saved_objects: TEST_CATALOG_NO_SERIALIZATION.map((item) => ({ | ||
attributes: item, | ||
})), | ||
}); | ||
}); | ||
|
||
it('Should correctly identify repository type', async () => { | ||
const adaptor = new IndexDataAdaptor(mockClient); | ||
await expect(adaptor.getDirectoryType()).resolves.toBe('repository'); | ||
}); | ||
|
||
it('Should correctly identify integration type after filtering', async () => { | ||
const adaptor = new JsonCatalogDataAdaptor(TEST_CATALOG_NO_SERIALIZATION); | ||
const joined = await adaptor.join('sample1'); | ||
await expect(joined.getDirectoryType()).resolves.toBe('integration'); | ||
}); | ||
|
||
it('Should correctly retrieve integration versions', async () => { | ||
const adaptor = new IndexDataAdaptor(mockClient); | ||
const versions = await adaptor.findIntegrationVersions('sample2'); | ||
expect((versions as { value: string[] }).value).toHaveLength(2); | ||
}); | ||
|
||
it('Should correctly supply latest integration version for IntegrationReader', async () => { | ||
const adaptor = new IndexDataAdaptor(mockClient); | ||
const reader = new IntegrationReader('sample2', adaptor.join('sample2')); | ||
const version = await reader.getLatestVersion(); | ||
expect(version).toBe('2.1.0'); | ||
}); | ||
|
||
it('Should find integration names', async () => { | ||
const adaptor = new IndexDataAdaptor(mockClient); | ||
const integResult = await adaptor.findIntegrations(); | ||
const integs = (integResult as { value: string[] }).value; | ||
integs.sort(); | ||
|
||
expect(integs).toEqual(['sample1', 'sample2']); | ||
}); | ||
|
||
it('Should reject any attempts to read a file with a type', async () => { | ||
const adaptor = new IndexDataAdaptor(mockClient); | ||
const result = await adaptor.readFile('logs-1.0.0.json', 'schemas'); | ||
await expect(result.error?.message).toBe( | ||
'JSON adaptor does not support subtypes (isConfigLocalized: true)' | ||
); | ||
}); | ||
|
||
it('Should reject any attempts to read a raw file', async () => { | ||
const adaptor = new JsonCatalogDataAdaptor(TEST_CATALOG_NO_SERIALIZATION); | ||
const result = await adaptor.readFileRaw('logo.svg', 'static'); | ||
await expect(result.error?.message).toBe( | ||
'JSON adaptor does not support raw files (isConfigLocalized: true)' | ||
); | ||
}); | ||
|
||
it('Should reject nested directory searching', async () => { | ||
const adaptor = new JsonCatalogDataAdaptor(TEST_CATALOG_NO_SERIALIZATION); | ||
const result = await adaptor.findIntegrations('sample1'); | ||
await expect(result.error?.message).toBe( | ||
'Finding integrations for custom dirs not supported for JSONreader' | ||
); | ||
}); | ||
|
||
it('Should report unknown directory type if integration list is empty', async () => { | ||
const adaptor = new JsonCatalogDataAdaptor([]); | ||
await expect(adaptor.getDirectoryType()).resolves.toBe('unknown'); | ||
}); | ||
}); |
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
Oops, something went wrong.