Skip to content

Commit 2d4a282

Browse files
LucasRoesleralexellis
authored andcommitted
Add test for invoke headers
**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]>
1 parent 6591b75 commit 2d4a282

File tree

4 files changed

+17
-31
lines changed

4 files changed

+17
-31
lines changed

.github/workflows/test.yaml

-26
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,6 @@ jobs:
2828
uses: golangci/golangci-lint-action@v2
2929
with:
3030
version: v1.29
31-
test-swarm:
32-
strategy:
33-
matrix:
34-
go-version: [ 1.13.x ]
35-
os: [ ubuntu-latest ]
36-
runs-on: ${{ matrix.os }}
37-
steps:
38-
- uses: actions/checkout@master
39-
with:
40-
fetch-depth: 1
41-
- name: Install Go
42-
uses: actions/setup-go@v2
43-
with:
44-
go-version: ${{ matrix.go-version }}
45-
- name: create swarm cluster
46-
run: ./contrib/create_swarm_cluster.sh
47-
- name: deploy stack
48-
run: ./contrib/deploy_stack.sh
49-
- name: wait 15 seconds
50-
run: sleep 15
51-
- name: test swarm
52-
run: make test-swarm
53-
env:
54-
OPENFAAS_URL: http://${{ env.IP }}:8080/
55-
- name: clean swarm cluster
56-
run: ./contrib/clean_swarm_cluster.sh
5731
test-kubernetes:
5832
strategy:
5933
matrix:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
functions/build
33
functions/template
4+
.vscode/

tests/invoke_test.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,22 @@ func Test_Invoke_With_Supported_Verbs(t *testing.T) {
4646
for _, v := range verbs {
4747
t.Run(v.verb, func(t *testing.T) {
4848

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

5151
out := string(bytesOut)
5252
if !v.match(out) {
5353
t.Fatalf("want: %s, got: %s", fmt.Sprintf("Http_Method=%s", v.verb), out)
5454
}
55+
56+
callID := res.Header.Get("X-Call-Id")
57+
if callID == "" {
58+
t.Fatal("expect non-empty X-Call-Id header")
59+
}
60+
61+
startTime := res.Header.Get("X-Start-Time")
62+
if startTime == "" {
63+
t.Fatal("expect non-empty X-Start-Time header")
64+
}
5565
})
5666
}
5767
}

tests/verify_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import (
99

1010
func invoke(t *testing.T, name string, query string, expectedStatusCode ...int) []byte {
1111
t.Helper()
12-
return invokeWithVerb(t, http.MethodPost, name, query, expectedStatusCode...)
12+
content, _ := invokeWithVerb(t, http.MethodPost, name, query, expectedStatusCode...)
13+
return content
1314
}
1415

15-
func invokeWithVerb(t *testing.T, verb string, name string, query string, expectedStatusCode ...int) []byte {
16+
func invokeWithVerb(t *testing.T, verb string, name string, query string, expectedStatusCode ...int) ([]byte, *http.Response) {
1617
t.Helper()
1718

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

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

54-
return nil
55+
return nil, nil
5556
}

0 commit comments

Comments
 (0)