mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Add go fmt
This commit is contained in:
committed by
Reed Allman
parent
9a7141967c
commit
81e39b210d
@@ -52,6 +52,11 @@ build_job_fn:
|
||||
- cd fn
|
||||
- go build -o fn-alpine
|
||||
|
||||
formatting:
|
||||
stage: build
|
||||
script:
|
||||
- ./go-fmt.sh
|
||||
|
||||
test_job:
|
||||
stage: test
|
||||
script:
|
||||
|
||||
@@ -19,11 +19,11 @@ import (
|
||||
)
|
||||
|
||||
type BoltDatastore struct {
|
||||
routesBucket []byte
|
||||
appsBucket []byte
|
||||
logsBucket []byte
|
||||
extrasBucket []byte
|
||||
callsBucket []byte
|
||||
routesBucket []byte
|
||||
appsBucket []byte
|
||||
logsBucket []byte
|
||||
extrasBucket []byte
|
||||
callsBucket []byte
|
||||
db *bolt.DB
|
||||
log logrus.FieldLogger
|
||||
}
|
||||
@@ -69,11 +69,11 @@ func New(url *url.URL) (models.Datastore, error) {
|
||||
}
|
||||
|
||||
ds := &BoltDatastore{
|
||||
routesBucket: routesBucketName,
|
||||
appsBucket: appsBucketName,
|
||||
logsBucket: logsBucketName,
|
||||
extrasBucket: extrasBucketName,
|
||||
callsBucket: callsBucketName,
|
||||
routesBucket: routesBucketName,
|
||||
appsBucket: appsBucketName,
|
||||
logsBucket: logsBucketName,
|
||||
extrasBucket: extrasBucketName,
|
||||
callsBucket: callsBucketName,
|
||||
db: db,
|
||||
log: log,
|
||||
}
|
||||
@@ -82,7 +82,6 @@ func New(url *url.URL) (models.Datastore, error) {
|
||||
return datastoreutil.NewValidator(ds), nil
|
||||
}
|
||||
|
||||
|
||||
func (ds *BoltDatastore) InsertTask(ctx context.Context, task *models.Task) error {
|
||||
var fnCall *models.FnCall
|
||||
taskID := []byte(task.ID)
|
||||
@@ -126,7 +125,6 @@ func (ds *BoltDatastore) GetTasks(ctx context.Context, filter *models.CallFilter
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
func (ds *BoltDatastore) GetTask(ctx context.Context, callID string) (*models.FnCall, error) {
|
||||
var res *models.FnCall
|
||||
err := ds.db.View(func(tx *bolt.Tx) error {
|
||||
@@ -147,7 +145,6 @@ func (ds *BoltDatastore) GetTask(ctx context.Context, callID string) (*models.Fn
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
func (ds *BoltDatastore) InsertApp(ctx context.Context, app *models.App) (*models.App, error) {
|
||||
appname := []byte(app.Name)
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ func setLogBuffer() *bytes.Buffer {
|
||||
return &buf
|
||||
}
|
||||
|
||||
|
||||
func Test(t *testing.T, ds models.Datastore) {
|
||||
buf := setLogBuffer()
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ type mock struct {
|
||||
Apps models.Apps
|
||||
Routes models.Routes
|
||||
Calls models.FnCalls
|
||||
data map[string][]byte
|
||||
data map[string][]byte
|
||||
}
|
||||
|
||||
func NewMock() models.Datastore {
|
||||
|
||||
@@ -8,4 +8,4 @@ import (
|
||||
|
||||
func TestDatastore(t *testing.T) {
|
||||
datastoretest.Test(t, NewMock())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ const callsTableCreate = `CREATE TABLE IF NOT EXISTS calls (
|
||||
|
||||
const callSelector = `SELECT id, created_at, started_at, completed_at, status, app_name, path FROM calls`
|
||||
|
||||
|
||||
type PostgresDatastore struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
@@ -14,15 +14,13 @@ import (
|
||||
"gitlab-odx.oracle.com/odx/functions/api/models"
|
||||
)
|
||||
|
||||
|
||||
type BoltLogDatastore struct {
|
||||
callLogsBucket []byte
|
||||
db *bolt.DB
|
||||
log logrus.FieldLogger
|
||||
datastore models.Datastore
|
||||
db *bolt.DB
|
||||
log logrus.FieldLogger
|
||||
datastore models.Datastore
|
||||
}
|
||||
|
||||
|
||||
func NewBolt(url *url.URL) (models.FnLog, error) {
|
||||
dir := filepath.Dir(url.Path)
|
||||
log := logrus.WithFields(logrus.Fields{"logdb": url.Scheme, "dir": dir})
|
||||
@@ -60,8 +58,8 @@ func NewBolt(url *url.URL) (models.FnLog, error) {
|
||||
|
||||
fnl := &BoltLogDatastore{
|
||||
callLogsBucket: callLogsBucketName,
|
||||
db: db,
|
||||
log: log,
|
||||
db: db,
|
||||
log: log,
|
||||
}
|
||||
log.WithFields(logrus.Fields{"prefix": bucketPrefix, "file": url.Path}).Debug("BoltDB initialized")
|
||||
|
||||
@@ -71,7 +69,7 @@ func NewBolt(url *url.URL) (models.FnLog, error) {
|
||||
func (fnl *BoltLogDatastore) InsertLog(ctx context.Context, callID string, callLog string) error {
|
||||
log := &models.FnCallLog{
|
||||
CallID: callID,
|
||||
Log: callLog,
|
||||
Log: callLog,
|
||||
}
|
||||
id := []byte(callID)
|
||||
err := fnl.db.Update(
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
const tmpLogDb = "/tmp/func_test_log.db"
|
||||
const tmpDatastore = "/tmp/func_test_datastore.db"
|
||||
|
||||
|
||||
func TestDatastore(t *testing.T) {
|
||||
os.Remove(tmpLogDb)
|
||||
os.Remove(tmpDatastore)
|
||||
|
||||
@@ -2,9 +2,9 @@ package logs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"github.com/Sirupsen/logrus"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/models"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func New(dbURL string) (models.FnLog, error) {
|
||||
|
||||
@@ -2,13 +2,13 @@ package logs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/models"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/models"
|
||||
)
|
||||
|
||||
type mock struct {
|
||||
Logs map[string]*models.FnCallLog
|
||||
ds models.Datastore
|
||||
ds models.Datastore
|
||||
}
|
||||
|
||||
func NewMock() models.FnLog {
|
||||
@@ -28,7 +28,7 @@ func (m *mock) SetDatastore(ctx context.Context, ds models.Datastore) {
|
||||
}
|
||||
|
||||
func (m *mock) InsertLog(ctx context.Context, callID string, callLog string) error {
|
||||
m.Logs[callID] = &models.FnCallLog{CallID: callID, Log:callLog}
|
||||
m.Logs[callID] = &models.FnCallLog{CallID: callID, Log: callLog}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package testing
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitlab-odx.oracle.com/odx/functions/api/models"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/id"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/models"
|
||||
)
|
||||
|
||||
|
||||
var testApp = &models.App{
|
||||
Name: "Test",
|
||||
}
|
||||
@@ -63,7 +62,7 @@ func Test(t *testing.T, fnl models.FnLog, ds models.Datastore) {
|
||||
}
|
||||
logEntry, err := fnl.GetLog(ctx, task.ID)
|
||||
if !strings.Contains(logEntry.Log, logText) {
|
||||
t.Fatalf("Test GetLog(ctx, task.ID, logText): unexpected error, log mismatch. " +
|
||||
t.Fatalf("Test GetLog(ctx, task.ID, logText): unexpected error, log mismatch. "+
|
||||
"Expected: `%v`. Got `%v`.", logText, logEntry.Log)
|
||||
}
|
||||
})
|
||||
@@ -80,7 +79,7 @@ func Test(t *testing.T, fnl models.FnLog, ds models.Datastore) {
|
||||
}
|
||||
logEntry, err := fnl.GetLog(ctx, task.ID)
|
||||
if !strings.Contains(logEntry.Log, logText) {
|
||||
t.Fatalf("Test GetLog(ctx, task.ID, logText): unexpected error, log mismatch. " +
|
||||
t.Fatalf("Test GetLog(ctx, task.ID, logText): unexpected error, log mismatch. "+
|
||||
"Expected: `%v`. Got `%v`.", logText, logEntry.Log)
|
||||
}
|
||||
err = fnl.DeleteLog(ctx, task.ID)
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
)
|
||||
|
||||
type FnLog interface {
|
||||
|
||||
InsertLog(ctx context.Context, callID string, callLog string) error
|
||||
GetLog(ctx context.Context, callID string) (*models.FnCallLog, error)
|
||||
DeleteLog(ctx context.Context, callID string) error
|
||||
@@ -21,7 +20,6 @@ func NewValidator(fnl FnLog) models.FnLog {
|
||||
return &validator{fnl}
|
||||
}
|
||||
|
||||
|
||||
func (v *validator) InsertLog(ctx context.Context, callID string, callLog string) error {
|
||||
return v.fnl.InsertLog(ctx, callID, callLog)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
)
|
||||
|
||||
type FnLog interface {
|
||||
|
||||
InsertLog(ctx context.Context, callID string, callLog string) error
|
||||
GetLog(ctx context.Context, callID string) (*FnCallLog, error)
|
||||
DeleteLog(ctx context.Context, callID string) error
|
||||
|
||||
@@ -4,8 +4,8 @@ package models
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
apierrors "errors"
|
||||
"encoding/json"
|
||||
apierrors "errors"
|
||||
|
||||
strfmt "github.com/go-openapi/strfmt"
|
||||
|
||||
@@ -30,9 +30,9 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrCallNotFound = apierrors.New("Call not found")
|
||||
ErrCallLogNotFound = apierrors.New("Call log not found")
|
||||
ErrCallLogRemoving = apierrors.New("Could not remove call log")
|
||||
ErrCallNotFound = apierrors.New("Call not found")
|
||||
ErrCallLogNotFound = apierrors.New("Call log not found")
|
||||
ErrCallLogRemoving = apierrors.New("Could not remove call log")
|
||||
)
|
||||
|
||||
type FnCall struct {
|
||||
@@ -46,10 +46,9 @@ type FnCall struct {
|
||||
|
||||
type FnCallLog struct {
|
||||
CallID string `json:"call_id"`
|
||||
Log string `json:"log"`
|
||||
Log string `json:"log"`
|
||||
}
|
||||
|
||||
|
||||
func (fnCall *FnCall) FromTask(task *Task) *FnCall {
|
||||
return &FnCall{
|
||||
CreatedAt: task.CreatedAt,
|
||||
|
||||
@@ -16,11 +16,11 @@ import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/datastore"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/logs"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/models"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/mqs"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/runner/drivers"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/runner/task"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/logs"
|
||||
)
|
||||
|
||||
func setLogBuffer() *bytes.Buffer {
|
||||
|
||||
@@ -94,14 +94,14 @@ func TestDecimate(t *testing.T) {
|
||||
|
||||
func TestParseImage(t *testing.T) {
|
||||
cases := map[string][]string{
|
||||
"funcy/hello": {"", "funcy/hello", "latest"},
|
||||
"funcy/hello:v1": {"", "funcy/hello", "v1"},
|
||||
"funcy/hello": {"", "funcy/hello", "latest"},
|
||||
"funcy/hello:v1": {"", "funcy/hello", "v1"},
|
||||
"my.registry/hello": {"my.registry", "hello", "latest"},
|
||||
"my.registry/hello:v1": {"my.registry", "hello", "v1"},
|
||||
"mongo": {"", "library/mongo", "latest"},
|
||||
"mongo:v1": {"", "library/mongo", "v1"},
|
||||
"quay.com/funcy/hello": {"quay.com", "funcy/hello", "latest"},
|
||||
"quay.com:8080/funcy/hello:v2": {"quay.com:8080", "funcy/hello", "v2"},
|
||||
"quay.com/funcy/hello": {"quay.com", "funcy/hello", "latest"},
|
||||
"quay.com:8080/funcy/hello:v2": {"quay.com:8080", "funcy/hello", "v2"},
|
||||
"localhost.localdomain:5000/samalba/hipache:latest": {"localhost.localdomain:5000", "samalba/hipache", "latest"},
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/datastore"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/logs"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/models"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/mqs"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/logs"
|
||||
)
|
||||
|
||||
func setLogBuffer() *bytes.Buffer {
|
||||
@@ -36,16 +36,16 @@ func TestAppCreate(t *testing.T) {
|
||||
expectedError error
|
||||
}{
|
||||
// errors
|
||||
{datastore.NewMock(), logs.NewMock(),"/v1/apps", ``, http.StatusBadRequest, models.ErrInvalidJSON},
|
||||
{datastore.NewMock(), logs.NewMock(),"/v1/apps", `{}`, http.StatusBadRequest, models.ErrAppsMissingNew},
|
||||
{datastore.NewMock(), logs.NewMock(),"/v1/apps", `{ "name": "Test" }`, http.StatusBadRequest, models.ErrAppsMissingNew},
|
||||
{datastore.NewMock(), logs.NewMock(),"/v1/apps", `{ "app": { "name": "" } }`, http.StatusInternalServerError, models.ErrAppsValidationMissingName},
|
||||
{datastore.NewMock(), logs.NewMock(),"/v1/apps", `{ "app": { "name": "1234567890123456789012345678901" } }`, http.StatusInternalServerError, models.ErrAppsValidationTooLongName},
|
||||
{datastore.NewMock(), logs.NewMock(),"/v1/apps", `{ "app": { "name": "&&%@!#$#@$" } }`, http.StatusInternalServerError, models.ErrAppsValidationInvalidName},
|
||||
{datastore.NewMock(), logs.NewMock(),"/v1/apps", `{ "app": { "name": "&&%@!#$#@$" } }`, http.StatusInternalServerError, models.ErrAppsValidationInvalidName},
|
||||
{datastore.NewMock(), logs.NewMock(), "/v1/apps", ``, http.StatusBadRequest, models.ErrInvalidJSON},
|
||||
{datastore.NewMock(), logs.NewMock(), "/v1/apps", `{}`, http.StatusBadRequest, models.ErrAppsMissingNew},
|
||||
{datastore.NewMock(), logs.NewMock(), "/v1/apps", `{ "name": "Test" }`, http.StatusBadRequest, models.ErrAppsMissingNew},
|
||||
{datastore.NewMock(), logs.NewMock(), "/v1/apps", `{ "app": { "name": "" } }`, http.StatusInternalServerError, models.ErrAppsValidationMissingName},
|
||||
{datastore.NewMock(), logs.NewMock(), "/v1/apps", `{ "app": { "name": "1234567890123456789012345678901" } }`, http.StatusInternalServerError, models.ErrAppsValidationTooLongName},
|
||||
{datastore.NewMock(), logs.NewMock(), "/v1/apps", `{ "app": { "name": "&&%@!#$#@$" } }`, http.StatusInternalServerError, models.ErrAppsValidationInvalidName},
|
||||
{datastore.NewMock(), logs.NewMock(), "/v1/apps", `{ "app": { "name": "&&%@!#$#@$" } }`, http.StatusInternalServerError, models.ErrAppsValidationInvalidName},
|
||||
|
||||
// success
|
||||
{datastore.NewMock(), logs.NewMock(),"/v1/apps", `{ "app": { "name": "teste" } }`, http.StatusOK, nil},
|
||||
{datastore.NewMock(), logs.NewMock(), "/v1/apps", `{ "app": { "name": "teste" } }`, http.StatusOK, nil},
|
||||
} {
|
||||
rnr, cancel := testRunner(t)
|
||||
srv := testServer(test.mock, &mqs.Mock{}, test.logDB, rnr)
|
||||
@@ -84,12 +84,12 @@ func TestAppDelete(t *testing.T) {
|
||||
expectedCode int
|
||||
expectedError error
|
||||
}{
|
||||
{datastore.NewMock(), logs.NewMock(),"/v1/apps/myapp", "", http.StatusNotFound, nil},
|
||||
{datastore.NewMock(), logs.NewMock(), "/v1/apps/myapp", "", http.StatusNotFound, nil},
|
||||
{datastore.NewMockInit(
|
||||
[]*models.App{{
|
||||
Name: "myapp",
|
||||
}}, nil, nil, nil,
|
||||
), logs.NewMock(),"/v1/apps/myapp", "", http.StatusOK, nil},
|
||||
), logs.NewMock(), "/v1/apps/myapp", "", http.StatusOK, nil},
|
||||
} {
|
||||
rnr, cancel := testRunner(t)
|
||||
srv := testServer(test.ds, &mqs.Mock{}, test.logDB, rnr)
|
||||
@@ -201,21 +201,21 @@ func TestAppUpdate(t *testing.T) {
|
||||
expectedError error
|
||||
}{
|
||||
// errors
|
||||
{datastore.NewMock(), logs.NewMock(),"/v1/apps/myapp", ``, http.StatusBadRequest, models.ErrInvalidJSON},
|
||||
{datastore.NewMock(), logs.NewMock(), "/v1/apps/myapp", ``, http.StatusBadRequest, models.ErrInvalidJSON},
|
||||
|
||||
// success
|
||||
{datastore.NewMockInit(
|
||||
[]*models.App{{
|
||||
Name: "myapp",
|
||||
}}, nil, nil, nil,
|
||||
), logs.NewMock(),"/v1/apps/myapp", `{ "app": { "config": { "test": "1" } } }`, http.StatusOK, nil},
|
||||
), logs.NewMock(), "/v1/apps/myapp", `{ "app": { "config": { "test": "1" } } }`, http.StatusOK, nil},
|
||||
|
||||
// Addresses #380
|
||||
{datastore.NewMockInit(
|
||||
[]*models.App{{
|
||||
Name: "myapp",
|
||||
}}, nil, nil, nil,
|
||||
), logs.NewMock(),"/v1/apps/myapp", `{ "app": { "name": "othername" } }`, http.StatusBadRequest, nil},
|
||||
), logs.NewMock(), "/v1/apps/myapp", `{ "app": { "name": "othername" } }`, http.StatusBadRequest, nil},
|
||||
} {
|
||||
rnr, cancel := testRunner(t)
|
||||
srv := testServer(test.mock, &mqs.Mock{}, test.logDB, rnr)
|
||||
|
||||
@@ -35,7 +35,7 @@ func (s *Server) handleCallList(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
filter := models.CallFilter{AppName:appName, Path:appRoute}
|
||||
filter := models.CallFilter{AppName: appName, Path: appRoute}
|
||||
|
||||
calls, err := s.Datastore.GetTasks(ctx, &filter)
|
||||
if err != nil {
|
||||
|
||||
@@ -27,7 +27,6 @@ func (s *Server) handleCallLogGet(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, fnCallLogResponse{"Successfully loaded call", callObj})
|
||||
}
|
||||
|
||||
|
||||
func (s *Server) handleCallLogDelete(c *gin.Context) {
|
||||
ctx := c.MustGet("ctx").(context.Context)
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ func (s *Server) handleRouteDelete(c *gin.Context) {
|
||||
handleErrorResponse(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if err := s.Datastore.RemoveRoute(ctx, appName, routePath); err != nil {
|
||||
handleErrorResponse(c, err)
|
||||
return
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
"testing"
|
||||
|
||||
"gitlab-odx.oracle.com/odx/functions/api/datastore"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/logs"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/models"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/mqs"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/runner"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/logs"
|
||||
)
|
||||
|
||||
func testRunner(t *testing.T) (*runner.Runner, context.CancelFunc) {
|
||||
@@ -129,11 +129,9 @@ func TestRouteRunnerExecution(t *testing.T) {
|
||||
}, nil, nil,
|
||||
)
|
||||
|
||||
|
||||
fnl := logs.NewMock()
|
||||
srv := testServer(ds, &mqs.Mock{}, fnl, rnr)
|
||||
|
||||
|
||||
for i, test := range []struct {
|
||||
path string
|
||||
body string
|
||||
@@ -187,7 +185,7 @@ func TestRouteRunnerTimeout(t *testing.T) {
|
||||
)
|
||||
fnl := logs.NewMock()
|
||||
srv := testServer(ds, &mqs.Mock{}, fnl, rnr)
|
||||
|
||||
|
||||
for i, test := range []struct {
|
||||
path string
|
||||
body string
|
||||
|
||||
@@ -13,17 +13,16 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/datastore"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/logs"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/models"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/mqs"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/runner"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/server/internal/routecache"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/logs"
|
||||
)
|
||||
|
||||
var tmpDatastoreBolt = "/tmp/func_test_bolt_datastore.db"
|
||||
var tmpLogBolt = "/tmp/func_test_bolt_log.db"
|
||||
|
||||
|
||||
func testServer(ds models.Datastore, mq models.MessageQueue, logDB models.FnLog, rnr *runner.Runner) *Server {
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -94,7 +93,7 @@ func prepareBolt(ctx context.Context, t *testing.T) (models.Datastore, models.Fn
|
||||
if err != nil {
|
||||
t.Fatalf("Error when creating log store: %s", err)
|
||||
}
|
||||
return ds,logDB, func() {
|
||||
return ds, logDB, func() {
|
||||
os.Remove(tmpDatastoreBolt)
|
||||
os.Remove(tmpLogBolt)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func main() {
|
||||
log.Fatal(errors.Wrap(err, "failed to read stdin"))
|
||||
}
|
||||
|
||||
db, err := sql.Open("postgres", "postgres://postgres@" + server + "?sslmode=disable")
|
||||
db, err := sql.Open("postgres", "postgres://postgres@"+server+"?sslmode=disable")
|
||||
if err != nil {
|
||||
log.Println("Failed to connect to postgres server")
|
||||
log.Fatal(err)
|
||||
@@ -96,7 +96,7 @@ func selectCommand(req []byte, db *sql.DB) (string, error) {
|
||||
func insertCommand(req []byte, db *sql.DB) error {
|
||||
q := "INSERT INTO " + table + " SELECT * FROM json_populate_record(null::" + table + ", $1)"
|
||||
_, err := db.Exec(q, req)
|
||||
if err != nil {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to execute insert query")
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
)
|
||||
|
||||
const lBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
@@ -13,7 +13,6 @@ type OutputSize struct {
|
||||
Size int `json:"size"`
|
||||
}
|
||||
|
||||
|
||||
func RandStringBytes(n int) string {
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
|
||||
"context"
|
||||
fnclient "github.com/funcy/functions_go/client"
|
||||
client "gitlab-odx.oracle.com/odx/functions/fn/client"
|
||||
apiapps "github.com/funcy/functions_go/client/apps"
|
||||
"github.com/funcy/functions_go/models"
|
||||
"github.com/jmoiron/jsonq"
|
||||
"github.com/urfave/cli"
|
||||
client "gitlab-odx.oracle.com/odx/functions/fn/client"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ import (
|
||||
"fmt"
|
||||
|
||||
fnclient "github.com/funcy/functions_go/client"
|
||||
client "gitlab-odx.oracle.com/odx/functions/fn/client"
|
||||
apicall "github.com/funcy/functions_go/client/call"
|
||||
"github.com/funcy/functions_go/models"
|
||||
"github.com/urfave/cli"
|
||||
client "gitlab-odx.oracle.com/odx/functions/fn/client"
|
||||
)
|
||||
|
||||
type callsCmd struct {
|
||||
|
||||
@@ -21,7 +21,6 @@ func EnvAsHeader(req *http.Request, selectedEnv []string) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func CallFN(u string, content io.Reader, output io.Writer, method string, env []string) error {
|
||||
if method == "" {
|
||||
if content == nil {
|
||||
|
||||
14
fn/main.go
14
fn/main.go
@@ -12,13 +12,13 @@ import (
|
||||
)
|
||||
|
||||
var aliases = map[string]cli.Command{
|
||||
"build": build(),
|
||||
"bump": bump(),
|
||||
"deploy": deploy(),
|
||||
"push": push(),
|
||||
"run": run(),
|
||||
"call": call(),
|
||||
"calls": calls(),
|
||||
"build": build(),
|
||||
"bump": bump(),
|
||||
"deploy": deploy(),
|
||||
"push": push(),
|
||||
"run": run(),
|
||||
"call": call(),
|
||||
"calls": calls(),
|
||||
}
|
||||
|
||||
func aliasesFn() []cli.Command {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gitlab-odx.oracle.com/odx/functions/fn/client"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
"gitlab-odx.oracle.com/odx/functions/fn/client"
|
||||
)
|
||||
|
||||
func TestEnvAsHeader(t *testing.T) {
|
||||
|
||||
@@ -11,9 +11,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitlab-odx.oracle.com/odx/functions/fn/client"
|
||||
functions "github.com/funcy/functions_go"
|
||||
"github.com/urfave/cli"
|
||||
"gitlab-odx.oracle.com/odx/functions/fn/client"
|
||||
)
|
||||
|
||||
func testfn() cli.Command {
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
"strings"
|
||||
"reflect"
|
||||
|
||||
"github.com/funcy/functions_go/client/apps"
|
||||
)
|
||||
|
||||
|
||||
func TestApps(t *testing.T) {
|
||||
s := SetupDefaultSuite()
|
||||
|
||||
@@ -50,14 +49,14 @@ func TestApps(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("create-app-with-config-test", func(t *testing.T) {
|
||||
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{"A": "a"})
|
||||
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{"A": "a"})
|
||||
t.Logf("Test `%v` passed.", t.Name())
|
||||
})
|
||||
|
||||
t.Run("inspect-app-with-config-test", func(t *testing.T) {
|
||||
cfg := &apps.GetAppsAppParams{
|
||||
Context: s.Context,
|
||||
App: s.AppName,
|
||||
App: s.AppName,
|
||||
}
|
||||
appPayload, err := s.Client.Apps.GetAppsApp(cfg)
|
||||
CheckAppResponseError(t, err)
|
||||
@@ -73,7 +72,7 @@ func TestApps(t *testing.T) {
|
||||
t.Logf("Test `%v` passed.", t.Name())
|
||||
})
|
||||
|
||||
t.Run("patch-override-app-config", func(t *testing.T){
|
||||
t.Run("patch-override-app-config", func(t *testing.T) {
|
||||
config := map[string]string{
|
||||
"A": "b",
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ package tests
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
"time"
|
||||
"net/url"
|
||||
"path"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitlab-odx.oracle.com/odx/functions/fn/client"
|
||||
"github.com/funcy/functions_go/client/call"
|
||||
"gitlab-odx.oracle.com/odx/functions/fn/client"
|
||||
)
|
||||
|
||||
func TestCalls(t *testing.T) {
|
||||
@@ -16,8 +16,8 @@ func TestCalls(t *testing.T) {
|
||||
|
||||
t.Run("list-calls-for-missing-app", func(t *testing.T) {
|
||||
cfg := &call.GetAppsAppCallsRouteParams{
|
||||
App: s.AppName,
|
||||
Route: s.RoutePath,
|
||||
App: s.AppName,
|
||||
Route: s.RoutePath,
|
||||
Context: s.Context,
|
||||
}
|
||||
_, err := s.Client.Call.GetAppsAppCallsRoute(cfg)
|
||||
@@ -36,8 +36,8 @@ func TestCalls(t *testing.T) {
|
||||
|
||||
t.Run("list-calls-for-missing-route", func(t *testing.T) {
|
||||
cfg := &call.GetAppsAppCallsRouteParams{
|
||||
App: s.AppName,
|
||||
Route: s.RoutePath,
|
||||
App: s.AppName,
|
||||
Route: s.RoutePath,
|
||||
Context: s.Context,
|
||||
}
|
||||
_, err := s.Client.Call.GetAppsAppCallsRoute(cfg)
|
||||
@@ -51,7 +51,7 @@ func TestCalls(t *testing.T) {
|
||||
|
||||
t.Run("get-dummy-call", func(t *testing.T) {
|
||||
cfg := &call.GetCallsCallParams{
|
||||
Call: "dummy",
|
||||
Call: "dummy",
|
||||
Context: s.Context,
|
||||
}
|
||||
cfg.WithTimeout(time.Second * 60)
|
||||
@@ -67,7 +67,7 @@ func TestCalls(t *testing.T) {
|
||||
callID := CallAsync(t, u, &bytes.Buffer{})
|
||||
time.Sleep(time.Second * 2)
|
||||
cfg := &call.GetCallsCallParams{
|
||||
Call: callID,
|
||||
Call: callID,
|
||||
Context: s.Context,
|
||||
}
|
||||
cfg.WithTimeout(time.Second * 60)
|
||||
@@ -84,8 +84,8 @@ func TestCalls(t *testing.T) {
|
||||
|
||||
t.Run("list-calls", func(t *testing.T) {
|
||||
cfg := &call.GetAppsAppCallsRouteParams{
|
||||
App: s.AppName,
|
||||
Route: s.RoutePath,
|
||||
App: s.AppName,
|
||||
Route: s.RoutePath,
|
||||
Context: s.Context,
|
||||
}
|
||||
calls, err := s.Client.Call.GetAppsAppCallsRoute(cfg)
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"io"
|
||||
"encoding/json"
|
||||
"bytes"
|
||||
"testing"
|
||||
"time"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitlab-odx.oracle.com/odx/functions/fn/client"
|
||||
"github.com/funcy/functions_go/client/call"
|
||||
"github.com/funcy/functions_go/client/operations"
|
||||
"gitlab-odx.oracle.com/odx/functions/fn/client"
|
||||
)
|
||||
|
||||
|
||||
type ErrMsg struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type TimeoutBody struct{
|
||||
Error ErrMsg `json:"error"`
|
||||
type TimeoutBody struct {
|
||||
Error ErrMsg `json:"error"`
|
||||
CallID string `json:"request_id"`
|
||||
}
|
||||
|
||||
@@ -51,7 +50,6 @@ func CallAsync(t *testing.T, u url.URL, content io.Reader) string {
|
||||
return callID.CallID
|
||||
}
|
||||
|
||||
|
||||
func TestRouteExecutions(t *testing.T) {
|
||||
s := SetupDefaultSuite()
|
||||
newRouteType := "async"
|
||||
@@ -114,7 +112,7 @@ func TestRouteExecutions(t *testing.T) {
|
||||
callID := CallAsync(t, u, &bytes.Buffer{})
|
||||
time.Sleep(time.Second * 2)
|
||||
cfg := &call.GetCallsCallParams{
|
||||
Call: callID,
|
||||
Call: callID,
|
||||
Context: s.Context,
|
||||
}
|
||||
cfg.WithTimeout(time.Second * 60)
|
||||
@@ -145,7 +143,6 @@ func TestRouteExecutions(t *testing.T) {
|
||||
|
||||
DeleteRoute(t, s.Context, s.Client, s.AppName, s.RoutePath)
|
||||
|
||||
|
||||
routePath := "/timeout"
|
||||
image := "funcy/timeout:0.0.1"
|
||||
routeType := "sync"
|
||||
@@ -176,7 +173,7 @@ func TestRouteExecutions(t *testing.T) {
|
||||
json.NewDecoder(output).Decode(tB)
|
||||
|
||||
cfg := &call.GetCallsCallParams{
|
||||
Call: tB.CallID,
|
||||
Call: tB.CallID,
|
||||
Context: s.Context,
|
||||
}
|
||||
cfg.WithTimeout(time.Second * 60)
|
||||
@@ -210,7 +207,7 @@ func TestRouteExecutions(t *testing.T) {
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
cfg := &operations.GetCallsCallLogParams{
|
||||
Call: callID,
|
||||
Call: callID,
|
||||
Context: s.Context,
|
||||
}
|
||||
|
||||
@@ -222,11 +219,11 @@ func TestRouteExecutions(t *testing.T) {
|
||||
t.Fatalf("Log entry must not be empty!")
|
||||
}
|
||||
if !strings.Contains(logObj.Payload.Log.Log, "First line") {
|
||||
t.Fatalf("Log entry must contain `First line` " +
|
||||
t.Fatalf("Log entry must contain `First line` "+
|
||||
"string, but got: %v", logObj.Payload.Log.Log)
|
||||
}
|
||||
if !strings.Contains(logObj.Payload.Log.Log, "Second line") {
|
||||
t.Fatalf("Log entry must contain `Second line` " +
|
||||
t.Fatalf("Log entry must contain `Second line` "+
|
||||
"string, but got: %v", logObj.Payload.Log.Log)
|
||||
}
|
||||
})
|
||||
@@ -254,7 +251,7 @@ func TestRouteExecutions(t *testing.T) {
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
cfg := &operations.GetCallsCallLogParams{
|
||||
Call: callID,
|
||||
Call: callID,
|
||||
Context: s.Context,
|
||||
}
|
||||
|
||||
@@ -283,7 +280,7 @@ func TestRouteExecutions(t *testing.T) {
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
cfg := &operations.GetCallsCallLogParams{
|
||||
Call: callID,
|
||||
Call: callID,
|
||||
Context: s.Context,
|
||||
}
|
||||
|
||||
@@ -293,7 +290,7 @@ func TestRouteExecutions(t *testing.T) {
|
||||
}
|
||||
if len(logObj.Payload.Log.Log) >= size {
|
||||
t.Fatalf("Log entry suppose to be truncated up to expected size %v, got %v",
|
||||
size / 1024, len(logObj.Payload.Log.Log))
|
||||
size/1024, len(logObj.Payload.Log.Log))
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
)
|
||||
|
||||
const lBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
@@ -13,7 +13,6 @@ type OutputSize struct {
|
||||
Size int `json:"size"`
|
||||
}
|
||||
|
||||
|
||||
func RandStringBytes(n int) string {
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
func main() {
|
||||
fmt.Fprintln(os.Stderr, "First line")
|
||||
fmt.Fprintln(os.Stdout, "Ok")
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestRoutes(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("can-get-corresponding-route", func(t *testing.T) {
|
||||
rObjects := []*models.Route{GetRoute(t, s.Context, s.Client, s.AppName, s.RoutePath), }
|
||||
rObjects := []*models.Route{GetRoute(t, s.Context, s.Client, s.AppName, s.RoutePath)}
|
||||
if !assertContainsRoute(rObjects, s.RoutePath) {
|
||||
t.Fatalf("Unable to find corresponding route `%v` in list", s.RoutePath)
|
||||
}
|
||||
|
||||
@@ -3,45 +3,43 @@ package tests
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
fn "github.com/funcy/functions_go/client"
|
||||
"github.com/funcy/functions_go/models"
|
||||
"github.com/funcy/functions_go/client/apps"
|
||||
"gitlab-odx.oracle.com/odx/functions/fn/client"
|
||||
"github.com/funcy/functions_go/client/routes"
|
||||
"github.com/funcy/functions_go/models"
|
||||
"gitlab-odx.oracle.com/odx/functions/fn/client"
|
||||
)
|
||||
|
||||
type SuiteSetup struct {
|
||||
Context context.Context
|
||||
Client *fn.Functions
|
||||
AppName string
|
||||
RoutePath string
|
||||
Image string
|
||||
RouteType string
|
||||
Format string
|
||||
Memory int64
|
||||
RouteConfig map[string]string
|
||||
Context context.Context
|
||||
Client *fn.Functions
|
||||
AppName string
|
||||
RoutePath string
|
||||
Image string
|
||||
RouteType string
|
||||
Format string
|
||||
Memory int64
|
||||
RouteConfig map[string]string
|
||||
RouteHeaders map[string][]string
|
||||
}
|
||||
|
||||
func SetupDefaultSuite() *SuiteSetup {
|
||||
return &SuiteSetup{
|
||||
Context: context.Background(),
|
||||
Client: client.APIClient(),
|
||||
AppName: "test-app",
|
||||
RoutePath: "/hello",
|
||||
Image: "funcy/hello",
|
||||
Format: "default",
|
||||
RouteType: "async",
|
||||
RouteConfig: map[string]string{},
|
||||
Context: context.Background(),
|
||||
Client: client.APIClient(),
|
||||
AppName: "test-app",
|
||||
RoutePath: "/hello",
|
||||
Image: "funcy/hello",
|
||||
Format: "default",
|
||||
RouteType: "async",
|
||||
RouteConfig: map[string]string{},
|
||||
RouteHeaders: map[string][]string{},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func CheckAppResponseError(t *testing.T, err error) {
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
@@ -93,12 +91,12 @@ func CheckAppResponseError(t *testing.T, err error) {
|
||||
|
||||
}
|
||||
|
||||
func CreateAppNoAssert(ctx context.Context, fnclient *fn.Functions, appName string, config map[string]string) (*apps.PostAppsOK, error){
|
||||
func CreateAppNoAssert(ctx context.Context, fnclient *fn.Functions, appName string, config map[string]string) (*apps.PostAppsOK, error) {
|
||||
cfg := &apps.PostAppsParams{
|
||||
Body: &models.AppWrapper{
|
||||
App: &models.App{
|
||||
Config: config,
|
||||
Name: appName,
|
||||
Name: appName,
|
||||
},
|
||||
},
|
||||
Context: ctx,
|
||||
@@ -116,14 +114,14 @@ func CreateApp(t *testing.T, ctx context.Context, fnclient *fn.Functions, appNam
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateApp(t *testing.T, ctx context.Context, fnclient *fn.Functions ,appName string, config map[string]string) *apps.PatchAppsAppOK {
|
||||
func UpdateApp(t *testing.T, ctx context.Context, fnclient *fn.Functions, appName string, config map[string]string) *apps.PatchAppsAppOK {
|
||||
CreateApp(t, ctx, fnclient, appName, map[string]string{"A": "a"})
|
||||
cfg := &apps.PatchAppsAppParams{
|
||||
App: appName,
|
||||
Body: &models.AppWrapper{
|
||||
App: &models.App{
|
||||
Config: config,
|
||||
Name: "",
|
||||
Name: "",
|
||||
},
|
||||
},
|
||||
Context: ctx,
|
||||
@@ -135,7 +133,7 @@ func UpdateApp(t *testing.T, ctx context.Context, fnclient *fn.Functions ,appNam
|
||||
|
||||
func DeleteApp(t *testing.T, ctx context.Context, fnclient *fn.Functions, appName string) {
|
||||
cfg := &apps.DeleteAppsAppParams{
|
||||
App: appName,
|
||||
App: appName,
|
||||
Context: ctx,
|
||||
}
|
||||
cfg.WithTimeout(time.Second * 60)
|
||||
@@ -143,7 +141,6 @@ func DeleteApp(t *testing.T, ctx context.Context, fnclient *fn.Functions, appNam
|
||||
CheckAppResponseError(t, err)
|
||||
}
|
||||
|
||||
|
||||
func CheckRouteResponseError(t *testing.T, err error) {
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
@@ -256,11 +253,11 @@ func createRoute(ctx context.Context, fnclient *fn.Functions, appName, image, ro
|
||||
App: appName,
|
||||
Body: &models.RouteWrapper{
|
||||
Route: &models.Route{
|
||||
Config: routeConfig,
|
||||
Config: routeConfig,
|
||||
Headers: headers,
|
||||
Image: image,
|
||||
Path: routePath,
|
||||
Type: routeType,
|
||||
Image: image,
|
||||
Path: routePath,
|
||||
Type: routeType,
|
||||
},
|
||||
},
|
||||
Context: ctx,
|
||||
@@ -277,10 +274,10 @@ func CreateRoute(t *testing.T, ctx context.Context, fnclient *fn.Functions, appN
|
||||
assertRouteFields(t, routeResponse.Payload.Route, routePath, image, routeType)
|
||||
}
|
||||
|
||||
func deleteRoute(ctx context.Context, fnclient *fn.Functions, appName, routePath string) (*routes.DeleteAppsAppRoutesRouteOK, error){
|
||||
func deleteRoute(ctx context.Context, fnclient *fn.Functions, appName, routePath string) (*routes.DeleteAppsAppRoutesRouteOK, error) {
|
||||
cfg := &routes.DeleteAppsAppRoutesRouteParams{
|
||||
App: appName,
|
||||
Route: routePath,
|
||||
App: appName,
|
||||
Route: routePath,
|
||||
Context: ctx,
|
||||
}
|
||||
cfg.WithTimeout(time.Second * 60)
|
||||
@@ -294,7 +291,7 @@ func DeleteRoute(t *testing.T, ctx context.Context, fnclient *fn.Functions, appN
|
||||
|
||||
func ListRoutes(t *testing.T, ctx context.Context, fnclient *fn.Functions, appName string) []*models.Route {
|
||||
cfg := &routes.GetAppsAppRoutesParams{
|
||||
App: appName,
|
||||
App: appName,
|
||||
Context: ctx,
|
||||
}
|
||||
cfg.WithTimeout(time.Second * 60)
|
||||
@@ -303,10 +300,10 @@ func ListRoutes(t *testing.T, ctx context.Context, fnclient *fn.Functions, appNa
|
||||
return routesResponse.Payload.Routes
|
||||
}
|
||||
|
||||
func GetRoute(t *testing.T, ctx context.Context, fnclient *fn.Functions, appName, routePath string) *models.Route{
|
||||
func GetRoute(t *testing.T, ctx context.Context, fnclient *fn.Functions, appName, routePath string) *models.Route {
|
||||
cfg := &routes.GetAppsAppRoutesRouteParams{
|
||||
App: appName,
|
||||
Route: routePath,
|
||||
App: appName,
|
||||
Route: routePath,
|
||||
Context: ctx,
|
||||
}
|
||||
cfg.WithTimeout(time.Second * 60)
|
||||
@@ -315,7 +312,7 @@ func GetRoute(t *testing.T, ctx context.Context, fnclient *fn.Functions, appName
|
||||
return routeResponse.Payload.Route
|
||||
}
|
||||
|
||||
func UpdateRoute(t *testing.T, ctx context.Context, fnclient *fn.Functions, appName, routePath, image, routeType, format string, memory int64, routeConfig map[string]string, headers map[string][]string, newRoutePath string) (*routes.PatchAppsAppRoutesRouteOK, error){
|
||||
func UpdateRoute(t *testing.T, ctx context.Context, fnclient *fn.Functions, appName, routePath, image, routeType, format string, memory int64, routeConfig map[string]string, headers map[string][]string, newRoutePath string) (*routes.PatchAppsAppRoutesRouteOK, error) {
|
||||
|
||||
routeObject := GetRoute(t, ctx, fnclient, appName, routePath)
|
||||
if routeObject.Config == nil {
|
||||
@@ -364,7 +361,7 @@ func UpdateRoute(t *testing.T, ctx context.Context, fnclient *fn.Functions, appN
|
||||
}
|
||||
|
||||
cfg := &routes.PatchAppsAppRoutesRouteParams{
|
||||
App: appName,
|
||||
App: appName,
|
||||
Context: ctx,
|
||||
Body: &models.RouteWrapper{
|
||||
Route: routeObject,
|
||||
|
||||
23
go-fmt.sh
Executable file
23
go-fmt.sh
Executable file
@@ -0,0 +1,23 @@
|
||||
#! /bin/sh
|
||||
set -e
|
||||
|
||||
function listFilesExit() {
|
||||
echo The following files need to have go fmt ran:
|
||||
echo $NEED_TO_FORMAT
|
||||
exit 1
|
||||
}
|
||||
|
||||
FOLDERS=$(go list -f {{.Dir}} ./... | grep -v vendor)
|
||||
for i in $FOLDERS
|
||||
do
|
||||
cd $i
|
||||
FILES=$(ls *.go)
|
||||
for j in $FILES
|
||||
do
|
||||
#echo $i/$j
|
||||
ALL_FILES="$ALL_FILES $i/$j"
|
||||
done
|
||||
done
|
||||
#echo $ALL_FILES
|
||||
NEED_TO_FORMAT="$(gofmt -l $ALL_FILES)"
|
||||
[[ -z $NEED_TO_FORMAT ]] || listFilesExit
|
||||
@@ -1,30 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"encoding/json"
|
||||
"time"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type execution struct {
|
||||
DurationSeconds float64
|
||||
Hostname string
|
||||
node string
|
||||
body string
|
||||
Hostname string
|
||||
node string
|
||||
body string
|
||||
responseSeconds float64
|
||||
}
|
||||
|
||||
var (
|
||||
lbHostPort, nodesStr, route string
|
||||
lbHostPort, nodesStr, route string
|
||||
numExecutions, maxPrime, numLoops int
|
||||
nodes []string
|
||||
nodesByContainerId map[string]string = make(map[string]string)
|
||||
verbose bool
|
||||
nodes []string
|
||||
nodesByContainerId map[string]string = make(map[string]string)
|
||||
verbose bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -124,4 +124,3 @@ func main() {
|
||||
discoverContainerIds()
|
||||
invokeLoadBalancer(lbHostPort, route, numExecutions, maxPrime, numLoops)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -50,10 +50,9 @@ func main() {
|
||||
for i := 0; i < numLoops; i++ {
|
||||
primes := sieveOfEratosthenes(maxPrime)
|
||||
_ = primes
|
||||
if i == numLoops - 1 {
|
||||
if i == numLoops-1 {
|
||||
//fmt.Printf("Highest three primes: %d %d %d\n", primes[len(primes) - 1], primes[len(primes) - 2], primes[len(primes) - 3])
|
||||
}
|
||||
}
|
||||
fmt.Printf("{\"durationSeconds\": %f, \"hostname\": \"%s\", \"max\": %d, \"loops\": %d}", time.Since(start).Seconds(), os.Getenv("HOSTNAME"), maxPrime, numLoops)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user