Skip to content

Commit

Permalink
fix: missing ossType parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
luoyjx committed Aug 3, 2020
1 parent 3924200 commit ac226c1
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
97 changes: 97 additions & 0 deletions __tests__/config-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import * as fs from 'fs';
import * as path from 'path';
import { loadConfig, loadConfigWithEnvs } from '../src/config';
import { StorageEngine } from '../src/types';

describe('receiver test cases', () => {
beforeAll(() => {
const cwd = process.cwd();
fs.writeFileSync(
path.join(cwd, './.fc-config.json'),
JSON.stringify({
EnvironmentVariables: {
OSS_ID: 'your oss id',
OSS_SECRET: 'your oss secret',
OSS_BUCKET: 'fc-task',
OSS_ENDPOINT: 'oss-cn-beijing.aliyuncs.com',
},
aws: {
accessKeyId: 'your aws id',
secretAccessKey: 'your aws secret',
bucket: 'fc-task',
region: 'cn-north-1',
endpoint: 'http://your-endpoint:8080',
s3ForcePathStyle: true,
},
})
);
});

describe('load config', () => {
it('should load config ok', async () => {
const config = loadConfig();
expect(config.aws.accessKeyId).toEqual('your aws id');
expect(config.aws.secretAccessKey).toEqual('your aws secret');
expect(config.aws.region).toEqual('cn-north-1');
expect(config.aws.bucket).toEqual('fc-task');
expect(config.aws.endpoint).toEqual('http://your-endpoint:8080');
expect(config.aws.s3ForcePathStyle).toBeTruthy();

expect(config.EnvironmentVariables).toMatchObject({
OSS_ID: 'your oss id',
OSS_SECRET: 'your oss secret',
OSS_BUCKET: 'fc-task',
OSS_ENDPOINT: 'oss-cn-beijing.aliyuncs.com',
});
});

it('should load config with env ok', async () => {
process.env.OSS_ID = 'some oss id';
process.env.OSS_SECRET = 'some oss key secret';
process.env.OSS_BUCKET = 'some oss bucket name';
process.env.OSS_ENDPOINT = 'some oss endpoint';

process.env.AWS_S3_ID = 'some aws id';
process.env.AWS_S3_SECRET = 'some aws secret';
process.env.AWS_S3_BUCKET_FC_TASK = 'some aws bucket name';
process.env.AWS_S3_REGION = 'some region';
process.env.AWS_S3_ENDPOINT = 'some endpoint';
process.env.AWS_S3_FORCE_PATH_STYLE = 'true';

const configOSS = loadConfigWithEnvs(StorageEngine.ALIYUN_OSS);
const configAWS = loadConfigWithEnvs(StorageEngine.AWS_S3);

expect(configOSS.oss).toMatchObject({
accessKeyId: 'some oss id',
accessKeySecret: 'some oss key secret',
bucket: 'some oss bucket name',
endpoint: 'some oss endpoint',
});

expect(configAWS.aws).toMatchObject({
accessKeyId: 'some aws id',
secretAccessKey: 'some aws secret',
bucket: 'some aws bucket name',
region: 'some region',
endpoint: 'some endpoint',
s3ForcePathStyle: true,
});

delete process.env.OSS_ID;
delete process.env.OSS_SECRET;
delete process.env.OSS_BUCKET;
delete process.env.OSS_ENDPOINT;
delete process.env.AWS_S3_ID;
delete process.env.AWS_S3_SECRET;
delete process.env.AWS_S3_BUCKET_FC_TASK;
delete process.env.AWS_S3_REGION;
delete process.env.AWS_S3_ENDPOINT;
delete process.env.AWS_S3_FORCE_PATH_STYLE;
});
});

afterAll(() => {
const cwd = process.cwd();
fs.unlinkSync(path.join(cwd, './.fc-config.json'));
});
});
2 changes: 1 addition & 1 deletion src/bufferSupport/receiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function initReceiver(
) => Promise<{ headers?: any; body: any; storeType?: string }>;
reply: replyFunc;
} {
const fcConfig = loadConfigWithEnvs();
const fcConfig = loadConfigWithEnvs(ossType);
const storageOptions = fcConfig[ossType] || ({} as any);
const storageClient = getClientByType(ossType, storageOptions);

Expand Down

0 comments on commit ac226c1

Please sign in to comment.