From 2818f70b532b3d8c6de5ea11a999917831984791 Mon Sep 17 00:00:00 2001 From: Denis Makogon Date: Sat, 24 Mar 2018 12:41:00 +0200 Subject: [PATCH 1/2] Add timezone database copy for go run image - the size of the images will grow for 355Kb --- langs/go.go | 2 ++ langs/python.go | 2 +- test.sh | 7 +++++++ test/go_location_loader/Gopkg.lock | 18 ++++++++++++++++++ test/go_location_loader/Gopkg.toml | 8 ++++++++ test/go_location_loader/func.go | 25 +++++++++++++++++++++++++ test/go_location_loader/func.yaml | 5 +++++ test/go_location_loader/test.json | 12 ++++++++++++ 8 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 test/go_location_loader/Gopkg.lock create mode 100644 test/go_location_loader/Gopkg.toml create mode 100644 test/go_location_loader/func.go create mode 100644 test/go_location_loader/func.yaml create mode 100644 test/go_location_loader/test.json diff --git a/langs/go.go b/langs/go.go index ba894258..016f1371 100644 --- a/langs/go.go +++ b/langs/go.go @@ -65,6 +65,8 @@ func (h *GoLangHelper) DockerfileBuildCmds() []string { func (h *GoLangHelper) DockerfileCopyCmds() []string { return []string{ + "COPY --from=build-stage /usr/local/go/lib/time/zoneinfo.zip " + + "/usr/local/go/lib/time/zoneinfo.zip", "COPY --from=build-stage /go/src/func/func /function/", } } diff --git a/langs/python.go b/langs/python.go index d993a348..8dd46bc9 100644 --- a/langs/python.go +++ b/langs/python.go @@ -55,7 +55,7 @@ func (h *PythonLangHelper) Runtime() string { } func (h *PythonLangHelper) LangStrings() []string { - return []string{"python","python3.6"} + return []string{"python", "python3.6"} } func (h *PythonLangHelper) Extensions() []string { diff --git a/test.sh b/test.sh index 6f41245e..e492ff29 100755 --- a/test.sh +++ b/test.sh @@ -107,3 +107,10 @@ $fn -v build $fn -v build $fn run $fn test + +# Test Golang time.LoadLocation +cd $WORK_DIR +cp -r ${CUR_DIR}/test/go_location_loader $WORK_DIR/go_location_loader +cd $WORK_DIR/go_location_loader +$fn -v run +$fn -v test diff --git a/test/go_location_loader/Gopkg.lock b/test/go_location_loader/Gopkg.lock new file mode 100644 index 00000000..10d882f4 --- /dev/null +++ b/test/go_location_loader/Gopkg.lock @@ -0,0 +1,18 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + branch = "master" + name = "github.com/fnproject/fdk-go" + packages = [ + ".", + "utils" + ] + revision = "0ae900cf56643afe316fcc87323c5845da0531c1" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "c55f0d3da5ec2e9e5c9a7c563702e4cf28513fa1aaea1c18664ca2cb7d726f89" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/test/go_location_loader/Gopkg.toml b/test/go_location_loader/Gopkg.toml new file mode 100644 index 00000000..c330ebe9 --- /dev/null +++ b/test/go_location_loader/Gopkg.toml @@ -0,0 +1,8 @@ + +[[constraint]] + branch = "master" + name = "github.com/fnproject/fdk-go" + +[prune] + go-tests = true + unused-packages = true diff --git a/test/go_location_loader/func.go b/test/go_location_loader/func.go new file mode 100644 index 00000000..ac458dd9 --- /dev/null +++ b/test/go_location_loader/func.go @@ -0,0 +1,25 @@ +package main + +import ( + "context" + "io" + "time" + + "encoding/json" + "github.com/fnproject/fdk-go" +) + +func main() { + fdk.Handle(fdk.HandlerFunc(myHandler)) +} + +func myHandler(_ context.Context, _ io.Reader, out io.Writer) { + tz, err := time.LoadLocation("America/New_York") + if err != nil { + fdk.WriteStatus(out, 500) + out.Write([]byte(err.Error())) + return + } + fdk.WriteStatus(out, 200) + json.NewEncoder(out).Encode(tz.String()) +} diff --git a/test/go_location_loader/func.yaml b/test/go_location_loader/func.yaml new file mode 100644 index 00000000..c33e560f --- /dev/null +++ b/test/go_location_loader/func.yaml @@ -0,0 +1,5 @@ +name: load_timezone +version: 0.0.1 +runtime: go +entrypoint: ./func +format: json diff --git a/test/go_location_loader/test.json b/test/go_location_loader/test.json new file mode 100644 index 00000000..0e91551b --- /dev/null +++ b/test/go_location_loader/test.json @@ -0,0 +1,12 @@ +{ + "tests": [ + { + "input": { + "body": {} + }, + "output": { + "body": "America/New_York" + } + } + ] +} From a274d5283eb83d3b3a27a7ec06104934836dd1c2 Mon Sep 17 00:00:00 2001 From: Denis Makogon Date: Sat, 24 Mar 2018 12:48:56 +0200 Subject: [PATCH 2/2] Fix the test packages definiton --- test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.sh b/test.sh index e492ff29..800d024f 100755 --- a/test.sh +++ b/test.sh @@ -23,7 +23,7 @@ $fn --version export FN_API_URL="http://localhost:8080" -go test $(go list ./... | grep -v /vendor/ | grep -v /tests) +go test $(go list ./... | grep -v /vendor/ | grep -v /test) # Our test directory OS=$(uname -s)