Skip to content

Commit

Permalink
chore: add conformance test coverage for typed function signature (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge authored Jun 26, 2023
1 parent 1e6a7be commit b454f0c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/conformance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ jobs:
-buildpacks=false \
-start-delay=5 \
-cmd="go run testdata/conformance/cmd/declarative/main.go"
- name: Run Typed conformance tests using declarative API
run: |
FUNCTION_TARGET=declarativeTyped client \
-type=http \
-declarative-type=typed \
-buildpacks=false \
-start-delay=5 \
-cmd="go run testdata/conformance/cmd/declarative/main.go"
- name: Run CloudEvent conformance tests using declarative API
run: |
FUNCTION_TARGET=declarativeCloudEvent client \
Expand Down
12 changes: 12 additions & 0 deletions testdata/conformance/function/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
func init() {
functions.HTTP("declarativeHTTP", HTTP)
functions.HTTP("concurrentHTTP", concurrentHTTP)
functions.Typed("declarativeTyped", Typed)
functions.CloudEvent("declarativeCloudEvent", CloudEvent)
}

Expand Down Expand Up @@ -68,3 +69,14 @@ func CloudEvent(ctx context.Context, ce cloudevents.Event) error {

return nil
}

// Typed is a typed function that dumps the request JSON into the "payload" field of the response i.e. the request {"message":"foo"} becomes {"payload":{"message":"foo"}}}
func Typed(req interface{}) (ConformanceResponse, error) {
return ConformanceResponse{
Payload: req,
}, nil
}

type ConformanceResponse struct {
Payload interface{} `json:"payload"`
}
3 changes: 3 additions & 0 deletions testdata/conformance/run_conformance_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ echo "Done installing client$CLIENT_VERSION"
print_header "HTTP CONFORMANCE TESTS"
client -buildpacks=false -type=http -cmd='go run cmd/http/main.go' -start-delay 1 -validate-mapping=true

print_header "TYPED CONFORMANCE TESTS"
FUNCTION_TARGET=declarativeTyped client -buildpacks=false -type=http -declarative-type=typed -cmd='go run cmd/declarative/main.go' -start-delay 1

print_header "BACKGROUND EVENT CONFORMANCE TESTS"
client -buildpacks=false -type=legacyevent -cmd='go run cmd/legacyevent/main.go' -start-delay 1 -validate-mapping=true

Expand Down

0 comments on commit b454f0c

Please sign in to comment.