Skip to content

Commit

Permalink
Add test for invoke headers
Browse files Browse the repository at this point in the history
**What**
- Remove CI flow for Swarm because the project i snow archived
- Add check for the X-Call-Id header when invoking a function
- Add check for the X-Start-Time header when ivoking a function

Signed-off-by: Lucas Roesler <[email protected]>
  • Loading branch information
LucasRoesler authored and alexellis committed Feb 14, 2021
1 parent 6591b75 commit 2d4a282
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 31 deletions.
26 changes: 0 additions & 26 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,6 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
version: v1.29
test-swarm:
strategy:
matrix:
go-version: [ 1.13.x ]
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@master
with:
fetch-depth: 1
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: create swarm cluster
run: ./contrib/create_swarm_cluster.sh
- name: deploy stack
run: ./contrib/deploy_stack.sh
- name: wait 15 seconds
run: sleep 15
- name: test swarm
run: make test-swarm
env:
OPENFAAS_URL: http://${{ env.IP }}:8080/
- name: clean swarm cluster
run: ./contrib/clean_swarm_cluster.sh
test-kubernetes:
strategy:
matrix:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
functions/build
functions/template
.vscode/
12 changes: 11 additions & 1 deletion tests/invoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,22 @@ func Test_Invoke_With_Supported_Verbs(t *testing.T) {
for _, v := range verbs {
t.Run(v.verb, func(t *testing.T) {

bytesOut := invokeWithVerb(t, v.verb, functionRequest.FunctionName, emptyQueryString, http.StatusOK)
bytesOut, res := invokeWithVerb(t, v.verb, functionRequest.FunctionName, emptyQueryString, http.StatusOK)

out := string(bytesOut)
if !v.match(out) {
t.Fatalf("want: %s, got: %s", fmt.Sprintf("Http_Method=%s", v.verb), out)
}

callID := res.Header.Get("X-Call-Id")
if callID == "" {
t.Fatal("expect non-empty X-Call-Id header")
}

startTime := res.Header.Get("X-Start-Time")
if startTime == "" {
t.Fatal("expect non-empty X-Start-Time header")
}
})
}
}
Expand Down
9 changes: 5 additions & 4 deletions tests/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (

func invoke(t *testing.T, name string, query string, expectedStatusCode ...int) []byte {
t.Helper()
return invokeWithVerb(t, http.MethodPost, name, query, expectedStatusCode...)
content, _ := invokeWithVerb(t, http.MethodPost, name, query, expectedStatusCode...)
return content
}

func invokeWithVerb(t *testing.T, verb string, name string, query string, expectedStatusCode ...int) []byte {
func invokeWithVerb(t *testing.T, verb string, name string, query string, expectedStatusCode ...int) ([]byte, *http.Response) {
t.Helper()

attempts := 30 // i.e. 30x2s = 1m
Expand All @@ -31,7 +32,7 @@ func invokeWithVerb(t *testing.T, verb string, name string, query string, expect
if res.StatusCode == code {
// success, we can stop now
t.Logf("[%d/%d] Got correct response: %v - %s", i+1, attempts, res.StatusCode, uri)
return bytesOut
return bytesOut, res
}
}

Expand All @@ -51,5 +52,5 @@ func invokeWithVerb(t *testing.T, verb string, name string, query string, expect
t.Logf("Failing after: %d attempts", attempts)
t.Fatalf("invoke failed with: %s", bytesOut)

return nil
return nil, nil
}

0 comments on commit 2d4a282

Please sign in to comment.