Skip to content

Commit ad2048c

Browse files
Local testing example (#149)
* local testing example for go * add python example * add go doc * add local testing note in readme
1 parent f435212 commit ad2048c

File tree

6 files changed

+45
-0
lines changed

6 files changed

+45
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Serverless Framework handles everything from creating namespaces to function/cod
5959
- [Events](#events)
6060
- [Custom domains](#custom-domains)
6161
- [Deployment methods](#deployment-methods)
62+
- [Local testing](#local-testing)
6263
- [Managing containers](#managing-containers)
6364
- [Logs](#logs)
6465
- [Offline testing](#offline-testing)
@@ -435,6 +436,14 @@ This can be controlled using the `singleSource` option. By default its value is
435436

436437
If `singleSource` is set to `true`, functions and containers not defined in your serverless configuration file will be removed the next time you run the `serverless deploy` command.
437438

439+
### Local testing
440+
441+
`serverless invoke local` is **not supported** directly but instead we provide additional packages to install close to your handler.
442+
443+
Documentation is available through runtimes frameworks for :
444+
* [Go](https://github.com/scaleway/serverless-functions-go)
445+
* [Python](https://github.com/scaleway/serverless-functions-python)
446+
438447
### Managing containers
439448

440449
>**Requirements:**

examples/go/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@ The `handler name` must be composed of the folder name and the handler function
4040
If your code depends on private dependencies, you will need to run `go mod vendor` before deploying your function.
4141

4242
See [Official Go Vendoring reference](https://go.dev/ref/mod#go-mod-vendor).
43+
44+
## Local testing
45+
46+
This examples use the [Go Framework](https://github.com/scaleway/serverless-functions-go) for local testing.
47+
To call you handler locally run `go run cmd/main.go`.

examples/go/cmd/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
import (
4+
scw "myhandler"
5+
6+
"github.com/scaleway/serverless-functions-go/local"
7+
)
8+
9+
func main() {
10+
// Replace "Handle" with your function handler name if necessary
11+
local.ServeHandler(scw.Handle, local.WithPort(8080))
12+
}

examples/go/go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
module myhandler
22

33
go 1.18
4+
5+
require github.com/scaleway/serverless-functions-go v0.1.0
6+
7+
require github.com/google/uuid v1.3.0 // indirect

examples/go/go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
3+
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
4+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5+
github.com/scaleway/serverless-functions-go v0.1.0 h1:U967AmTujugxzzvLIWUNoB+/5hLmsys0Xe7n4L38XPA=
6+
github.com/scaleway/serverless-functions-go v0.1.0/go.mod h1:SKb5XA5bONwJkecQElrKLYOVrg/5kmcaduB440HQbIg=
7+
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
8+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

examples/python3/handler.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@ def handle(event, context):
1111
"Content-Type": ["text/plain"],
1212
}
1313
}
14+
15+
# run 'pip install scaleway_functions_python' if necessary
16+
if __name__ == "__main__":
17+
# The import is conditional so that you do not need
18+
# to package the library when deploying on Scaleway Functions.
19+
from scaleway_functions_python import local
20+
local.serve_handler(handle, port=8080)

0 commit comments

Comments
 (0)