-
Notifications
You must be signed in to change notification settings - Fork 2
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
9202f22
commit 01b6a50
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,10 @@ | ||
version: 1.0 | ||
provider: | ||
name: openfaas | ||
gateway: http://127.0.0.1:31112 | ||
functions: | ||
first-func: | ||
lang: golang-mod | ||
handler: ./first-func | ||
image: martinheinz/first-func:latest | ||
|
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,20 @@ | ||
package function | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/openfaas-incubator/go-function-sdk" | ||
) | ||
|
||
// Handle a function invocation | ||
func Handle(req handler.Request) (handler.Response, error) { | ||
var err error | ||
|
||
message := fmt.Sprintf("Hello world, input was: %s", string(req.Body)) | ||
|
||
return handler.Response{ | ||
Body: []byte(message), | ||
StatusCode: http.StatusOK, | ||
}, err | ||
} |
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,17 @@ | ||
package function | ||
|
||
import ( | ||
"github.com/openfaas-incubator/go-function-sdk" | ||
"github.com/stretchr/testify/assert" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestHandleReturnsCorrectResponse(t *testing.T) { | ||
expected := handler.Response{Body: []byte("Hello world, input was: John"), StatusCode: http.StatusOK} | ||
response, err := Handle(handler.Request{Body: []byte("John"), Method: "GET"}) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, response.StatusCode, expected.StatusCode) | ||
assert.Equal(t, response.Body, expected.Body) | ||
} |