This repository has been archived by the owner on Jul 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2a30ca
commit 2321c08
Showing
5 changed files
with
111 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { invoke } from '../src/index'; | ||
import { join } from 'path'; | ||
import * as assert from 'assert'; | ||
import { remove } from 'fs-extra'; | ||
describe('/test/apigw.test.ts', () => { | ||
it('invoke', async () => { | ||
const baseDir = join(__dirname, 'fixtures/http'); | ||
await remove(join(baseDir, './.faas_debug_tmp')); | ||
const result: any = await invoke({ | ||
functionDir: baseDir, | ||
functionName: 'http', | ||
trigger: 'apigw', | ||
data: [ | ||
{ | ||
headers: { | ||
'Content-Type': 'text/json' | ||
}, | ||
method: 'POST', | ||
query: { | ||
q: 'testq' | ||
}, | ||
pathParameters: { | ||
id: 'id' | ||
}, | ||
path: '/test', | ||
body: { | ||
name: 'test' | ||
} | ||
} | ||
] | ||
}); | ||
const resultBody = JSON.parse(result.body); | ||
assert(resultBody.headers['Content-Type'] === 'text/json' && resultBody.method === 'POST' && resultBody.path === '/test' && resultBody.body.name === 'test' && resultBody.pathParameters.id === 'id'); | ||
}); | ||
}); |
7 changes: 4 additions & 3 deletions
7
packages/faas-cli-plugin-invoke/test/fixtures/http/src/index.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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import { FaaSContext, func, inject, provide } from '@midwayjs/faas'; | ||
import { func, inject, provide } from '@midwayjs/faas'; | ||
|
||
@provide() | ||
@func('http.handler') | ||
export class HelloHttpService { | ||
|
||
@inject() | ||
ctx: FaaSContext; // context | ||
ctx; // context | ||
|
||
async handler() { | ||
return { | ||
headers: this.ctx.request.headers, | ||
method: this.ctx.request.method, | ||
path: this.ctx.request.path, | ||
body: this.ctx.request.body | ||
body: this.ctx.request.body, | ||
pathParameters: this.ctx.request.pathParameters | ||
} | ||
} | ||
} |
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