Skip to content

Commit

Permalink
fix: fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll committed Jan 1, 2025
1 parent 44c1fb0 commit a37795a
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 62 deletions.
31 changes: 31 additions & 0 deletions samples/serverless-insight-rds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: 0.0.1

provider:
name: aliyun
region: cn-chengdu


service: insight-db-poc

tags:
owner: geek-fun

databases:
# insight_es_db:
# name: insight-poc-es
# type: ELASTICSEARCH_SERVERLESS
# version: '7.10'
# engine_mode: SEARCH
# cu: 1
# storage_size: 20
# security:
# basic_auth:
# password: 'U34I6InQ8elseTgqTWT2t2oFXpoqFg'
insight_poc_db:
name: insight-poc-rds
type: RDS_PGSQL_SERVERLESS
version: PGSQL_16
security:
basic_auth:
password: 'U34I6InQ8elseTgqTWT2t2oFXpoqFg'

31 changes: 31 additions & 0 deletions samples/si-aliyun-es.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: 0.0.1

provider:
name: aliyun
region: cn-chengdu


service: insight-db-poc

tags:
owner: geek-fun

databases:
# insight_es_db:
# name: insight-poc-es
# type: ELASTICSEARCH_SERVERLESS
# version: '7.10'
# engine_mode: SEARCH
# cu: 1
# storage_size: 20
# security:
# basic_auth:
# password: 'U34I6InQ8elseTgqTWT2t2oFXpoqFg'
insight_poc_db:
name: insight-poc-rds
type: RDS_PGSQL_SERVERLESS
version: PGSQL_16
security:
basic_auth:
password: 'U34I6InQ8elseTgqTWT2t2oFXpoqFg'

70 changes: 70 additions & 0 deletions samples/si-fc-aliyun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
version: 0.0.1
provider:
name: aliyun
region: cn-chengdu

vars:
region: cn-hangzhou
testv: testVarValue
handler: index.handler

stages:
default:
region: ${vars.region}
node_env: default
dev:
region: ${vars.region}
node_env: development
prod:
region: cn-shanghai

service: insight-poc

tags:
owner: geek-fun

functions:
insight_poc_fn:
name: insight-poc-fn
runtime: nodejs18
handler: ${vars.handler}
code: tests/fixtures/artifacts/artifact.zip
memory: 512
timeout: 10
environment:
NODE_ENV: ${stages.node_env}
TEST_VAR: ${vars.testv}
TEST_VAR_EXTRA: abcds-${vars.testv}-andyou

databases:
insight_poc_db:
name: insight-poc-db
type: RDS_POSTGRESQL_SERVERLESS
version: '17.0'
security:
basic_auth:
password: 'U34I6InQ8elseTgqTWT2t2oFXpoqFg'
# insight_es_db:
# name: insight-poc-es
# type: ELASTICSEARCH_SERVERLESS
# version: 7.10
# engine_mode: SEARCH
# security:
# basic_auth:
# password: 123456
# cu: 1
# storage_size: 20

events:
gateway_event:
type: API_GATEWAY
name: insight-poc-gateway
triggers:
- method: GET
path: /api/hello
backend: ${functions.insight_poc_fn}
# custom_domain:
# domain_name: test.com
# certificate_name: test
# certificate_private_key: test
# certificate_body: test
60 changes: 60 additions & 0 deletions samples/si-fc-huawei.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
version: 0.0.1
provider:
name: huawei
region: cn-north-4

vars:
testv: testVarValue
handler: index.handler

stages:
default:
node_env: default
dev:
region: ${vars.region}
node_env: development
prod:
node_env: prod
service: insight-poc

tags:
owner: geek-fun

functions:
insight_poc_fn:
name: insight-poc-fn
runtime: nodejs18
handler: ${vars.handler}
code: tests/fixtures/artifacts/artifact.zip
memory: 512
timeout: 10
environment:
NODE_ENV: ${stages.node_env}
TEST_VAR: ${vars.testv}
TEST_VAR_EXTRA: abcds-${vars.testv}-andyou

#databases:
# insight_es_db:
# name: insight-poc-es
# type: ELASTICSEARCH_SERVERLESS
# version: 7.10
# engine_mode: SEARCH
# security:
# basic_auth:
# password: 123456
# cu: 1
# storage_size: 20

events:
gateway_event:
type: API_GATEWAY
name: insight-poc-gateway
triggers:
- method: GET
path: /api/hello
backend: ${functions.insight_poc_fn}
# custom_domain:
# domain_name: test.com
# certificate_name: test
# certificate_private_key: test
# certificate_body: test
1 change: 0 additions & 1 deletion src/parser/databaseParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const parseDatabase = (databases?: {
name: database.name,
type: database.type as DatabaseEnum,
version: database.version as DatabaseVersionEnum,
engineMode: database.engine_mode,
security: {
basicAuth: {
password: get(database, 'security.basic_auth.password'),
Expand Down
35 changes: 24 additions & 11 deletions src/stack/rosStack/database.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import * as ros from '@alicloud/ros-cdk-core';
import * as rds from '@alicloud/ros-cdk-rds';
import { replaceReference } from '../../common';
import {
ActionContext,
DatabaseDomain,
DatabaseEngineMode,
DatabaseEnum,
DatabaseVersionEnum,
} from '../../types';
import { ActionContext, DatabaseDomain, DatabaseEnum, DatabaseVersionEnum } from '../../types';
import { isEmpty } from 'lodash';
import * as esServerless from '@alicloud/ros-cdk-elasticsearchserverless';

Expand Down Expand Up @@ -132,6 +126,24 @@ const rdsEngineMap = new Map<
dbInstanceClass: 'mssql.mem2.serverless.s2',
},
],
[
`${DatabaseEnum.ELASTICSEARCH_SERVERLESS}-${DatabaseVersionEnum['ES_SEARCH_7.10']}`,
{
engine: 'Elasticsearch',
version: '7.10',
category: 'STANDARD',
dbInstanceClass: '',
},
],
[
`${DatabaseEnum.ELASTICSEARCH_SERVERLESS}-${DatabaseVersionEnum['ES_TIME_SERIES_7.10']}`,
{
engine: 'Elasticsearch',
version: '7.10',
category: 'TRIAL',
dbInstanceClass: '',
},
],
]);

export const resolveDatabases = (
Expand All @@ -143,13 +155,16 @@ export const resolveDatabases = (
return undefined;
}
databases!.forEach((db) => {
const { engine, version, category, dbInstanceClass } =
rdsEngineMap.get(`${db.type}-${db.version}`) ?? {};

if ([DatabaseEnum.ELASTICSEARCH_SERVERLESS].includes(db.type)) {
new esServerless.App(
scope,
replaceReference(db.key, context),
{
appName: replaceReference(db.name, context),
appVersion: db.version,
appVersion: version,
authentication: {
basicAuth: [
{
Expand All @@ -160,7 +175,7 @@ export const resolveDatabases = (
quotaInfo: {
cu: db.cu.min,
storage: db.storage.min,
appType: db.engineMode === DatabaseEngineMode.TIMESERIES ? 'TRIAL' : 'STANDARD',
appType: category as string,
},
// network: [
// {
Expand All @@ -185,8 +200,6 @@ export const resolveDatabases = (
DatabaseEnum.RDS_MSSQL_SERVERLESS,
].includes(db.type)
) {
const { engine, version, category, dbInstanceClass } =
rdsEngineMap.get(`${db.type}-${db.version}`) ?? {};
new rds.DBInstance(

Check warning on line 203 in src/stack/rosStack/database.ts

View check run for this annotation

Codecov / codecov/patch

src/stack/rosStack/database.ts#L203

Added line #L203 was not covered by tests
scope,
replaceReference(db.key, context),
Expand Down
9 changes: 2 additions & 7 deletions src/types/domains/database.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
export enum DatabaseEngineMode {
SEARCH = 'SEARCH',
TIMESERIES = 'TIMESERIES',
}

export const enum DatabaseEnum {
ELASTICSEARCH_SERVERLESS = 'ELASTICSEARCH_SERVERLESS',
RDS_MYSQL_SERVERLESS = 'RDS_MYSQL_SERVERLESS',
Expand All @@ -24,13 +19,14 @@ export const enum DatabaseVersionEnum {
MSSQL_HA_2016 = 'MSSQL_HA_2016',
MSSQL_HA_2017 = 'MSSQL_HA_2017',
MSSQL_HA_2019 = 'MSSQL_HA_2019',
'ES_SEARCH_7.10' = 'ES_SEARCH_7.10',
'ES_TIME_SERIES_7.10' = 'ES_TIME_SERIES_7.10',
}

export type DatabaseRaw = {
name: string;
type: DatabaseEnum;
version: string;
engine_mode: DatabaseEngineMode;
security: {
basic_auth: {
password: string;
Expand All @@ -53,7 +49,6 @@ export type DatabaseDomain = {
name: string;
type: DatabaseEnum;
version: DatabaseVersionEnum;
engineMode: string;
security: {
basicAuth: {
password: string;
Expand Down
3 changes: 2 additions & 1 deletion src/validator/databaseSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ export const databaseSchema = {
'MSSQL_HA_2016',
'MSSQL_HA_2017',
'MSSQL_HA_2019',
'ES_SEARCH_7.10',
'ES_TIME_SERIES_7.10',
],
},
engine_mode: { type: 'string', enum: ['SEARCH', 'TIMESERIES'] },
cu: {
type: 'object',
properties: {
Expand Down
5 changes: 2 additions & 3 deletions tests/fixtures/deployFixture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DatabaseEnum, ServerlessIac } from '../../src/types';
import { DatabaseEnum, DatabaseVersionEnum, ServerlessIac } from '../../src/types';
import { cloneDeep, set } from 'lodash';
import { ProviderEnum } from '../../src/common';

Expand Down Expand Up @@ -1204,8 +1204,7 @@ export const esServerlessMinimumIac: ServerlessIac = {
key: 'insight_es_db_test',
name: 'insight-poc-es-test',
type: DatabaseEnum.ELASTICSEARCH_SERVERLESS,
version: '7.10',
engineMode: 'SEARCH',
version: DatabaseVersionEnum['ES_SEARCH_7.10'],
security: {
basicAuth: {
password: 'test-password',
Expand Down
26 changes: 10 additions & 16 deletions tests/fixtures/serverless-insight-es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,21 @@ provider:
region: cn-chengdu


service: insight-db-poc
service: insight-es-poc

tags:
owner: geek-fun

databases:
# insight_es_db:
# name: insight-poc-es
# type: ELASTICSEARCH_SERVERLESS
# version: '7.10'
# engine_mode: SEARCH
# cu: 1
# storage_size: 20
# security:
# basic_auth:
# password: 'U34I6InQ8elseTgqTWT2t2oFXpoqFg'
insight_poc_db:
name: insight-poc-rds
type: RDS_PGSQL_SERVERLESS
version: PGSQL_16
insight_es_db:
name: insight-poc-es
type: ELASTICSEARCH_SERVERLESS
version: ES_SEARCH_7.10
cu:
min: 1
max: 6
storage:
min: 20
security:
basic_auth:
password: 'U34I6InQ8elseTgqTWT2t2oFXpoqFg'

Loading

0 comments on commit a37795a

Please sign in to comment.