🎉 add google go

This commit is contained in:
toshi0607 2019-01-20 11:42:57 +09:00
parent 9359ceaaa3
commit b58ec6aec7
10 changed files with 145 additions and 0 deletions

View File

@ -102,6 +102,10 @@ services:
image: node:6.9.1
volumes:
- ./tmp/serverless-integration-test-google-nodejs:/app
google-nodejs:
image: golang:1.11
volumes:
- ./tmp/serverless-integration-test-google-go:/app
spotinst-nodejs:
image: node:4.8
volumes:

View File

@ -41,6 +41,7 @@ To see a list of available templates run `serverless create --help`
Most commonly used templates:
- google-nodejs
- google-go
## Examples

View File

@ -42,6 +42,7 @@ const validTemplates = [
'fn-nodejs',
'fn-go',
'google-nodejs',
'google-go',
'kubeless-python',
'kubeless-nodejs',
'openwhisk-java-maven',

View File

@ -567,6 +567,20 @@ describe('Create', () => {
});
});
it('should generate scaffolding for "google-go" template', () => {
process.chdir(tmpDir);
create.options.template = 'google-go';
return create.create().then(() => {
const dirContent = fs.readdirSync(tmpDir);
expect(dirContent).to.include('fn.go');
expect(dirContent).to.include('fn_test.go');
expect(dirContent).to.include('serverless.yml');
expect(dirContent).to.include('Makefile');
expect(dirContent).to.include('.gitignore');
});
});
it('should generate scaffolding for "kubeless-python" template', () => {
process.chdir(tmpDir);
create.options.template = 'kubeless-python';

View File

@ -0,0 +1,12 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

View File

@ -0,0 +1,10 @@
.PHONY: gomodgen deploy delete
gomodgen:
GO111MODULE=on go mod init
deploy:
gcloud functions deploy hello --entry-point Hello --runtime go111 --trigger-http
delete:
gcloud functions delete hello --entry-point Hello --runtime go111 --trigger-http

View File

@ -0,0 +1,14 @@
package hello
import (
"fmt"
"net/http"
)
func Hello(w http.ResponseWriter, r *http.Request) {
name := r.URL.Query().Get("name")
if name == "" {
name = "someone"
}
fmt.Fprintf(w, "Hello, %s!", name)
}

View File

@ -0,0 +1,44 @@
package hello
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
func TestHello(t *testing.T) {
tests := map[string]struct {
name string
wantStatus int
wantString string
}{
"name specified": {"toshi0607", http.StatusOK, "Hello, toshi0607!"},
"name not specified": {"", http.StatusOK, "Hello, someone!"},
}
for name, te := range tests {
t.Run(name, func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/", nil)
q := r.URL.Query()
q.Add("name", te.name)
r.URL.RawQuery = q.Encode()
Hello(w, r)
rw := w.Result()
defer rw.Body.Close()
if s := rw.StatusCode; s != te.wantStatus {
t.Fatalf("got: %d, want: %d", s, te.wantStatus)
}
b, err := ioutil.ReadAll(rw.Body)
if err != nil {
t.Fatal("failed to read res body")
}
if s := string(b); s != te.wantString {
t.Fatalf("got: %s, want: %s", s, te.wantString)
}
})
}
}

View File

@ -0,0 +1,44 @@
service: gcf-go111 # NOTE: Don't put the word "google" in here
provider:
name: google
runtime: go111
project: my-project
# the path to the credentials file needs to be absolute
credentials: ~/.gcloud/keyfile.json
plugins:
- serverless-google-cloudfunctions
# needs more granular excluding in production as only the serverless provider npm
# package should be excluded (and not the whole node_modules directory)
package:
exclude:
- .gitignore
- .git/**
functions:
first:
handler: http
events:
- http: path
# NOTE: the following uses an "event" event (pubSub event in this case).
# Please create the corresponding resources in the Google Cloud
# before deploying this service through Serverless
#second:
# handler: event
# events:
# - event:
# eventType: providers/cloud.pubsub/eventTypes/topic.publish
# resource: projects/*/topics/my-topic
# you can define resources, templates etc. the same way you would in a
# Google Cloud deployment configuration
#resources:
# resources:
# - type: storage.v1.bucket
# name: my-serverless-service-bucket
# imports:
# - path: my_template.jinja

View File

@ -30,6 +30,7 @@ integration-test aws-nodejs-typescript
integration-test aws-alexa-typescript
integration-test aws-nodejs-ecma-script
integration-test google-nodejs
integration-test google-go
integration-test spotinst-nodejs
integration-test spotinst-python
integration-test spotinst-ruby