mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
chore(server): separate elasticsearch to run independently (#12299)
close CLOUD-217 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a dedicated test job for Elasticsearch, running only Elasticsearch-specific tests during CI. - **Chores** - Enhanced server test workflows with explicit setup steps and automated coverage uploads. - Improved test suite structure for Elasticsearch provider to enable conditional and asynchronous test execution based on environment variables. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -2,38 +2,52 @@ import { randomUUID } from 'node:crypto';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
import test from 'ava';
|
||||
import _test from 'ava';
|
||||
import { omit, pick } from 'lodash-es';
|
||||
|
||||
import { createModule } from '../../../../__tests__/create-module';
|
||||
import {
|
||||
createModule,
|
||||
TestingModule,
|
||||
} from '../../../../__tests__/create-module';
|
||||
import { Mockers } from '../../../../__tests__/mocks';
|
||||
import { ConfigModule } from '../../../../base/config';
|
||||
import { User, Workspace } from '../../../../models';
|
||||
import { IndexerModule } from '../../';
|
||||
import { SearchProviderType } from '../../config';
|
||||
import { AggregateQueryDSL, ElasticsearchProvider } from '../../providers';
|
||||
import { blockMapping, docMapping, SearchTable } from '../../tables';
|
||||
|
||||
const module = await createModule({
|
||||
imports: [
|
||||
IndexerModule,
|
||||
ConfigModule.override({
|
||||
indexer: {
|
||||
provider: {
|
||||
type: SearchProviderType.Elasticsearch,
|
||||
endpoint: 'http://localhost:9200',
|
||||
username: 'elastic',
|
||||
password: 'affine',
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
providers: [ElasticsearchProvider],
|
||||
});
|
||||
const searchProvider = module.get(ElasticsearchProvider);
|
||||
const user = await module.create(Mockers.User);
|
||||
const workspace = await module.create(Mockers.Workspace);
|
||||
const test =
|
||||
process.env.AFFINE_INDEXER_SEARCH_PROVIDER === 'elasticsearch'
|
||||
? _test
|
||||
: _test.skip;
|
||||
|
||||
let module: TestingModule;
|
||||
let searchProvider: ElasticsearchProvider;
|
||||
let user: User;
|
||||
let workspace: Workspace;
|
||||
|
||||
_test.before(async () => {
|
||||
module = await createModule({
|
||||
imports: [
|
||||
IndexerModule,
|
||||
ConfigModule.override({
|
||||
indexer: {
|
||||
provider: {
|
||||
type: SearchProviderType.Elasticsearch,
|
||||
endpoint: 'http://localhost:9200',
|
||||
username: 'elastic',
|
||||
password: 'affine',
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
providers: [ElasticsearchProvider],
|
||||
});
|
||||
searchProvider = module.get(ElasticsearchProvider);
|
||||
user = await module.create(Mockers.User);
|
||||
workspace = await module.create(Mockers.Workspace);
|
||||
|
||||
test.before(async () => {
|
||||
await searchProvider.createTable(
|
||||
SearchTable.block,
|
||||
JSON.stringify(blockMapping)
|
||||
@@ -159,7 +173,7 @@ test.before(async () => {
|
||||
});
|
||||
});
|
||||
|
||||
test.after.always(async () => {
|
||||
_test.after.always(async () => {
|
||||
await searchProvider.deleteByQuery(
|
||||
SearchTable.block,
|
||||
{
|
||||
@@ -182,6 +196,7 @@ test.after.always(async () => {
|
||||
refresh: true,
|
||||
}
|
||||
);
|
||||
|
||||
await module.close();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user