Skip to content

Commit

Permalink
feat: add support for conformance testing 'typed' declarative functio…
Browse files Browse the repository at this point in the history
…n signature (#121)

* feat: add support for conformance testing 'typed' declarative function signature

* expose 'typed' conformance test in github action workflows

* Add typed conformance test example to README.md
  • Loading branch information
garethgeorge committed Jun 23, 2023
1 parent 0a94dc6 commit 2f5f319
Show file tree
Hide file tree
Showing 14 changed files with 4,238 additions and 4,423 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 12,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 14.x
node-version: 18.x
- name: Build Action
run: cd action && npm i && npm run all
- name: Check if there's a diff
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 17,10 @@ Frameworks to the Functions Framework contract.
parameters to JSON in the format:
`{"data": ...data..., "context": ...context...}`
and write the resulting string.
- The `typed` function should accept a JSON request object and should echo
the request object back in the "payload" field of the response. I.e. if
the request is `{"a":"b"}` the response should be `{"payload":{"a":
"b"}}`.

1. Build the test client:

Expand Down Expand Up @@ -58,6 62,15 @@ Frameworks to the Functions Framework contract.
-type=legacyevent \
-buildpacks=false
```
- **Ruby __typed http__** function Example:

```sh
$HOME/functions-framework-conformance/client/client \
-cmd="bundle exec functions-framework-ruby --source test/conformance/app.rb --target typed_func --signature-type http" \
--type=http \
--declarative-type=typed \
-buildpacks=false
```

If there are validation errors, an error will be logged in the output, causing your conformance test to fail.

Expand All @@ -68,7 81,8 @@ Frameworks to the Functions Framework contract.
| Configuration flag | Type | Default | Description |
| --- | --- | --- | --- |
| `-cmd` | string | `"''"` | A string with the command to run a Functions Framework server at `localhost:8080`. Must be wrapped in quotes. Ignored if `-buildpacks=true`. |
| `-type` | string | `"http"` | Type of function to validate (must be `"http"`, `"cloudevent"`, or `"legacyevent"`). |
| `-type` | string | `"http"` | The function signature to use (must be `"http"`, `"cloudevent"`, or `"legacyevent"`). |
| `-declarative-type` | string | `""` | The declarative signature type of the function (must be 'http', 'cloudevent', 'legacyevent', or 'typed'), default matches -type |
| `-validate-mapping` | boolean | `true` | Whether to validate mapping from legacy->cloud events and vice versa (as applicable). |
| `-output-file` | string | `"function_output.json"` | Name of file output by function. |
| `-buildpacks` | boolean | `true` | Whether to use the current release of buildpacks to run the validation. If `true`, `-cmd` is ignored and `--builder-*` flags must be set. |
Expand Down
5 changes: 4 additions & 1 deletion action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 8,11 @@ inputs:
description: 'output file from function'
default: 'function_output.json'
functionType:
description: 'type of function'
description: 'invocation signature type of function'
default: 'http'
declarativeType:
description: 'declarative type of the function as defined in code i.e. a typed declarative function uses the http invocation type'
default: ''
validateMapping:
description: 'whether to validate mapping from legacy->cloud event and vice versa'
default: true
Expand Down
Loading

0 comments on commit 2f5f319

Please sign in to comment.