Merge branch 'add_go_fmt' into 'master'

Add go fmt

See merge request !94
This commit is contained in:
Reed Allman
2017-07-07 10:14:08 -07:00
40 changed files with 185 additions and 187 deletions

View File

@@ -52,6 +52,11 @@ build_job_fn:
- cd fn - cd fn
- go build -o fn-alpine - go build -o fn-alpine
formatting:
stage: build
script:
- ./go-fmt.sh
test_job: test_job:
stage: test stage: test
script: script:

View File

@@ -19,11 +19,11 @@ import (
) )
type BoltDatastore struct { type BoltDatastore struct {
routesBucket []byte routesBucket []byte
appsBucket []byte appsBucket []byte
logsBucket []byte logsBucket []byte
extrasBucket []byte extrasBucket []byte
callsBucket []byte callsBucket []byte
db *bolt.DB db *bolt.DB
log logrus.FieldLogger log logrus.FieldLogger
} }
@@ -69,11 +69,11 @@ func New(url *url.URL) (models.Datastore, error) {
} }
ds := &BoltDatastore{ ds := &BoltDatastore{
routesBucket: routesBucketName, routesBucket: routesBucketName,
appsBucket: appsBucketName, appsBucket: appsBucketName,
logsBucket: logsBucketName, logsBucket: logsBucketName,
extrasBucket: extrasBucketName, extrasBucket: extrasBucketName,
callsBucket: callsBucketName, callsBucket: callsBucketName,
db: db, db: db,
log: log, log: log,
} }
@@ -82,7 +82,6 @@ func New(url *url.URL) (models.Datastore, error) {
return datastoreutil.NewValidator(ds), nil return datastoreutil.NewValidator(ds), nil
} }
func (ds *BoltDatastore) InsertTask(ctx context.Context, task *models.Task) error { func (ds *BoltDatastore) InsertTask(ctx context.Context, task *models.Task) error {
var fnCall *models.FnCall var fnCall *models.FnCall
taskID := []byte(task.ID) taskID := []byte(task.ID)
@@ -126,7 +125,6 @@ func (ds *BoltDatastore) GetTasks(ctx context.Context, filter *models.CallFilter
return res, err return res, err
} }
func (ds *BoltDatastore) GetTask(ctx context.Context, callID string) (*models.FnCall, error) { func (ds *BoltDatastore) GetTask(ctx context.Context, callID string) (*models.FnCall, error) {
var res *models.FnCall var res *models.FnCall
err := ds.db.View(func(tx *bolt.Tx) error { 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 return res, err
} }
func (ds *BoltDatastore) InsertApp(ctx context.Context, app *models.App) (*models.App, error) { func (ds *BoltDatastore) InsertApp(ctx context.Context, app *models.App) (*models.App, error) {
appname := []byte(app.Name) appname := []byte(app.Name)

View File

@@ -28,7 +28,6 @@ func setLogBuffer() *bytes.Buffer {
return &buf return &buf
} }
func Test(t *testing.T, ds models.Datastore) { func Test(t *testing.T, ds models.Datastore) {
buf := setLogBuffer() buf := setLogBuffer()

View File

@@ -11,7 +11,7 @@ type mock struct {
Apps models.Apps Apps models.Apps
Routes models.Routes Routes models.Routes
Calls models.FnCalls Calls models.FnCalls
data map[string][]byte data map[string][]byte
} }
func NewMock() models.Datastore { func NewMock() models.Datastore {

View File

@@ -8,4 +8,4 @@ import (
func TestDatastore(t *testing.T) { func TestDatastore(t *testing.T) {
datastoretest.Test(t, NewMock()) datastoretest.Test(t, NewMock())
} }

View File

@@ -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` const callSelector = `SELECT id, created_at, started_at, completed_at, status, app_name, path FROM calls`
type PostgresDatastore struct { type PostgresDatastore struct {
db *sql.DB db *sql.DB
} }

View File

@@ -14,15 +14,13 @@ import (
"gitlab-odx.oracle.com/odx/functions/api/models" "gitlab-odx.oracle.com/odx/functions/api/models"
) )
type BoltLogDatastore struct { type BoltLogDatastore struct {
callLogsBucket []byte callLogsBucket []byte
db *bolt.DB db *bolt.DB
log logrus.FieldLogger log logrus.FieldLogger
datastore models.Datastore datastore models.Datastore
} }
func NewBolt(url *url.URL) (models.FnLog, error) { func NewBolt(url *url.URL) (models.FnLog, error) {
dir := filepath.Dir(url.Path) dir := filepath.Dir(url.Path)
log := logrus.WithFields(logrus.Fields{"logdb": url.Scheme, "dir": dir}) log := logrus.WithFields(logrus.Fields{"logdb": url.Scheme, "dir": dir})
@@ -60,8 +58,8 @@ func NewBolt(url *url.URL) (models.FnLog, error) {
fnl := &BoltLogDatastore{ fnl := &BoltLogDatastore{
callLogsBucket: callLogsBucketName, callLogsBucket: callLogsBucketName,
db: db, db: db,
log: log, log: log,
} }
log.WithFields(logrus.Fields{"prefix": bucketPrefix, "file": url.Path}).Debug("BoltDB initialized") 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 { func (fnl *BoltLogDatastore) InsertLog(ctx context.Context, callID string, callLog string) error {
log := &models.FnCallLog{ log := &models.FnCallLog{
CallID: callID, CallID: callID,
Log: callLog, Log: callLog,
} }
id := []byte(callID) id := []byte(callID)
err := fnl.db.Update( err := fnl.db.Update(

View File

@@ -12,7 +12,6 @@ import (
const tmpLogDb = "/tmp/func_test_log.db" const tmpLogDb = "/tmp/func_test_log.db"
const tmpDatastore = "/tmp/func_test_datastore.db" const tmpDatastore = "/tmp/func_test_datastore.db"
func TestDatastore(t *testing.T) { func TestDatastore(t *testing.T) {
os.Remove(tmpLogDb) os.Remove(tmpLogDb)
os.Remove(tmpDatastore) os.Remove(tmpDatastore)

View File

@@ -2,9 +2,9 @@ package logs
import ( import (
"fmt" "fmt"
"net/url"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"gitlab-odx.oracle.com/odx/functions/api/models" "gitlab-odx.oracle.com/odx/functions/api/models"
"net/url"
) )
func New(dbURL string) (models.FnLog, error) { func New(dbURL string) (models.FnLog, error) {

View File

@@ -2,13 +2,13 @@ package logs
import ( import (
"context" "context"
"gitlab-odx.oracle.com/odx/functions/api/models"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab-odx.oracle.com/odx/functions/api/models"
) )
type mock struct { type mock struct {
Logs map[string]*models.FnCallLog Logs map[string]*models.FnCallLog
ds models.Datastore ds models.Datastore
} }
func NewMock() models.FnLog { 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 { 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 return nil
} }

View File

@@ -1,17 +1,16 @@
package testing package testing
import ( import (
"testing"
"time"
"context" "context"
"strings" "strings"
"testing"
"time"
"gitlab-odx.oracle.com/odx/functions/api/models"
"github.com/go-openapi/strfmt" "github.com/go-openapi/strfmt"
"gitlab-odx.oracle.com/odx/functions/api/id" "gitlab-odx.oracle.com/odx/functions/api/id"
"gitlab-odx.oracle.com/odx/functions/api/models"
) )
var testApp = &models.App{ var testApp = &models.App{
Name: "Test", Name: "Test",
} }
@@ -63,7 +62,7 @@ func Test(t *testing.T, fnl models.FnLog, ds models.Datastore) {
} }
logEntry, err := fnl.GetLog(ctx, task.ID) logEntry, err := fnl.GetLog(ctx, task.ID)
if !strings.Contains(logEntry.Log, logText) { 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) "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) logEntry, err := fnl.GetLog(ctx, task.ID)
if !strings.Contains(logEntry.Log, logText) { 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) "Expected: `%v`. Got `%v`.", logText, logEntry.Log)
} }
err = fnl.DeleteLog(ctx, task.ID) err = fnl.DeleteLog(ctx, task.ID)

View File

@@ -7,7 +7,6 @@ import (
) )
type FnLog interface { type FnLog interface {
InsertLog(ctx context.Context, callID string, callLog string) error InsertLog(ctx context.Context, callID string, callLog string) error
GetLog(ctx context.Context, callID string) (*models.FnCallLog, error) GetLog(ctx context.Context, callID string) (*models.FnCallLog, error)
DeleteLog(ctx context.Context, callID string) error DeleteLog(ctx context.Context, callID string) error
@@ -21,7 +20,6 @@ func NewValidator(fnl FnLog) models.FnLog {
return &validator{fnl} return &validator{fnl}
} }
func (v *validator) InsertLog(ctx context.Context, callID string, callLog string) error { func (v *validator) InsertLog(ctx context.Context, callID string, callLog string) error {
return v.fnl.InsertLog(ctx, callID, callLog) return v.fnl.InsertLog(ctx, callID, callLog)
} }

View File

@@ -5,7 +5,6 @@ import (
) )
type FnLog interface { type FnLog interface {
InsertLog(ctx context.Context, callID string, callLog string) error InsertLog(ctx context.Context, callID string, callLog string) error
GetLog(ctx context.Context, callID string) (*FnCallLog, error) GetLog(ctx context.Context, callID string) (*FnCallLog, error)
DeleteLog(ctx context.Context, callID string) error DeleteLog(ctx context.Context, callID string) error

View File

@@ -4,8 +4,8 @@ package models
// Editing this file might prove futile when you re-run the swagger generate command // Editing this file might prove futile when you re-run the swagger generate command
import ( import (
apierrors "errors"
"encoding/json" "encoding/json"
apierrors "errors"
strfmt "github.com/go-openapi/strfmt" strfmt "github.com/go-openapi/strfmt"
@@ -30,9 +30,9 @@ const (
) )
var ( var (
ErrCallNotFound = apierrors.New("Call not found") ErrCallNotFound = apierrors.New("Call not found")
ErrCallLogNotFound = apierrors.New("Call log not found") ErrCallLogNotFound = apierrors.New("Call log not found")
ErrCallLogRemoving = apierrors.New("Could not remove call log") ErrCallLogRemoving = apierrors.New("Could not remove call log")
) )
type FnCall struct { type FnCall struct {
@@ -46,10 +46,9 @@ type FnCall struct {
type FnCallLog struct { type FnCallLog struct {
CallID string `json:"call_id"` CallID string `json:"call_id"`
Log string `json:"log"` Log string `json:"log"`
} }
func (fnCall *FnCall) FromTask(task *Task) *FnCall { func (fnCall *FnCall) FromTask(task *Task) *FnCall {
return &FnCall{ return &FnCall{
CreatedAt: task.CreatedAt, CreatedAt: task.CreatedAt,

View File

@@ -16,11 +16,11 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab-odx.oracle.com/odx/functions/api/datastore" "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/models"
"gitlab-odx.oracle.com/odx/functions/api/mqs" "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/drivers"
"gitlab-odx.oracle.com/odx/functions/api/runner/task" "gitlab-odx.oracle.com/odx/functions/api/runner/task"
"gitlab-odx.oracle.com/odx/functions/api/logs"
) )
func setLogBuffer() *bytes.Buffer { func setLogBuffer() *bytes.Buffer {

View File

@@ -94,14 +94,14 @@ func TestDecimate(t *testing.T) {
func TestParseImage(t *testing.T) { func TestParseImage(t *testing.T) {
cases := map[string][]string{ cases := map[string][]string{
"funcy/hello": {"", "funcy/hello", "latest"}, "funcy/hello": {"", "funcy/hello", "latest"},
"funcy/hello:v1": {"", "funcy/hello", "v1"}, "funcy/hello:v1": {"", "funcy/hello", "v1"},
"my.registry/hello": {"my.registry", "hello", "latest"}, "my.registry/hello": {"my.registry", "hello", "latest"},
"my.registry/hello:v1": {"my.registry", "hello", "v1"}, "my.registry/hello:v1": {"my.registry", "hello", "v1"},
"mongo": {"", "library/mongo", "latest"}, "mongo": {"", "library/mongo", "latest"},
"mongo:v1": {"", "library/mongo", "v1"}, "mongo:v1": {"", "library/mongo", "v1"},
"quay.com/funcy/hello": {"quay.com", "funcy/hello", "latest"}, "quay.com/funcy/hello": {"quay.com", "funcy/hello", "latest"},
"quay.com:8080/funcy/hello:v2": {"quay.com:8080", "funcy/hello", "v2"}, "quay.com:8080/funcy/hello:v2": {"quay.com:8080", "funcy/hello", "v2"},
"localhost.localdomain:5000/samalba/hipache:latest": {"localhost.localdomain:5000", "samalba/hipache", "latest"}, "localhost.localdomain:5000/samalba/hipache:latest": {"localhost.localdomain:5000", "samalba/hipache", "latest"},
} }

View File

@@ -10,9 +10,9 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab-odx.oracle.com/odx/functions/api/datastore" "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/models"
"gitlab-odx.oracle.com/odx/functions/api/mqs" "gitlab-odx.oracle.com/odx/functions/api/mqs"
"gitlab-odx.oracle.com/odx/functions/api/logs"
) )
func setLogBuffer() *bytes.Buffer { func setLogBuffer() *bytes.Buffer {
@@ -36,16 +36,16 @@ func TestAppCreate(t *testing.T) {
expectedError error expectedError error
}{ }{
// errors // errors
{datastore.NewMock(), logs.NewMock(),"/v1/apps", ``, http.StatusBadRequest, models.ErrInvalidJSON}, {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", `{}`, http.StatusBadRequest, models.ErrAppsMissingNew},
{datastore.NewMock(), logs.NewMock(),"/v1/apps", `{ "name": "Test" }`, 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": "" } }`, 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": "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", `{ "app": { "name": "&&%@!#$#@$" } }`, http.StatusInternalServerError, models.ErrAppsValidationInvalidName}, {datastore.NewMock(), logs.NewMock(), "/v1/apps", `{ "app": { "name": "&&%@!#$#@$" } }`, http.StatusInternalServerError, models.ErrAppsValidationInvalidName},
// success // 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) rnr, cancel := testRunner(t)
srv := testServer(test.mock, &mqs.Mock{}, test.logDB, rnr) srv := testServer(test.mock, &mqs.Mock{}, test.logDB, rnr)
@@ -84,12 +84,12 @@ func TestAppDelete(t *testing.T) {
expectedCode int expectedCode int
expectedError error expectedError error
}{ }{
{datastore.NewMock(), logs.NewMock(),"/v1/apps/myapp", "", http.StatusNotFound, nil}, {datastore.NewMock(), logs.NewMock(), "/v1/apps/myapp", "", http.StatusNotFound, nil},
{datastore.NewMockInit( {datastore.NewMockInit(
[]*models.App{{ []*models.App{{
Name: "myapp", Name: "myapp",
}}, nil, nil, nil, }}, nil, nil, nil,
), logs.NewMock(),"/v1/apps/myapp", "", http.StatusOK, nil}, ), logs.NewMock(), "/v1/apps/myapp", "", http.StatusOK, nil},
} { } {
rnr, cancel := testRunner(t) rnr, cancel := testRunner(t)
srv := testServer(test.ds, &mqs.Mock{}, test.logDB, rnr) srv := testServer(test.ds, &mqs.Mock{}, test.logDB, rnr)
@@ -201,21 +201,21 @@ func TestAppUpdate(t *testing.T) {
expectedError error expectedError error
}{ }{
// errors // errors
{datastore.NewMock(), logs.NewMock(),"/v1/apps/myapp", ``, http.StatusBadRequest, models.ErrInvalidJSON}, {datastore.NewMock(), logs.NewMock(), "/v1/apps/myapp", ``, http.StatusBadRequest, models.ErrInvalidJSON},
// success // success
{datastore.NewMockInit( {datastore.NewMockInit(
[]*models.App{{ []*models.App{{
Name: "myapp", Name: "myapp",
}}, nil, nil, nil, }}, 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 // Addresses #380
{datastore.NewMockInit( {datastore.NewMockInit(
[]*models.App{{ []*models.App{{
Name: "myapp", Name: "myapp",
}}, nil, nil, nil, }}, 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) rnr, cancel := testRunner(t)
srv := testServer(test.mock, &mqs.Mock{}, test.logDB, rnr) srv := testServer(test.mock, &mqs.Mock{}, test.logDB, rnr)

View File

@@ -35,7 +35,7 @@ func (s *Server) handleCallList(c *gin.Context) {
return return
} }
filter := models.CallFilter{AppName:appName, Path:appRoute} filter := models.CallFilter{AppName: appName, Path: appRoute}
calls, err := s.Datastore.GetTasks(ctx, &filter) calls, err := s.Datastore.GetTasks(ctx, &filter)
if err != nil { if err != nil {

View File

@@ -27,7 +27,6 @@ func (s *Server) handleCallLogGet(c *gin.Context) {
c.JSON(http.StatusOK, fnCallLogResponse{"Successfully loaded call", callObj}) c.JSON(http.StatusOK, fnCallLogResponse{"Successfully loaded call", callObj})
} }
func (s *Server) handleCallLogDelete(c *gin.Context) { func (s *Server) handleCallLogDelete(c *gin.Context) {
ctx := c.MustGet("ctx").(context.Context) ctx := c.MustGet("ctx").(context.Context)

View File

@@ -19,7 +19,7 @@ func (s *Server) handleRouteDelete(c *gin.Context) {
handleErrorResponse(c, err) handleErrorResponse(c, err)
return return
} }
if err := s.Datastore.RemoveRoute(ctx, appName, routePath); err != nil { if err := s.Datastore.RemoveRoute(ctx, appName, routePath); err != nil {
handleErrorResponse(c, err) handleErrorResponse(c, err)
return return

View File

@@ -8,10 +8,10 @@ import (
"testing" "testing"
"gitlab-odx.oracle.com/odx/functions/api/datastore" "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/models"
"gitlab-odx.oracle.com/odx/functions/api/mqs" "gitlab-odx.oracle.com/odx/functions/api/mqs"
"gitlab-odx.oracle.com/odx/functions/api/runner" "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) { func testRunner(t *testing.T) (*runner.Runner, context.CancelFunc) {
@@ -129,11 +129,9 @@ func TestRouteRunnerExecution(t *testing.T) {
}, nil, nil, }, nil, nil,
) )
fnl := logs.NewMock() fnl := logs.NewMock()
srv := testServer(ds, &mqs.Mock{}, fnl, rnr) srv := testServer(ds, &mqs.Mock{}, fnl, rnr)
for i, test := range []struct { for i, test := range []struct {
path string path string
body string body string
@@ -187,7 +185,7 @@ func TestRouteRunnerTimeout(t *testing.T) {
) )
fnl := logs.NewMock() fnl := logs.NewMock()
srv := testServer(ds, &mqs.Mock{}, fnl, rnr) srv := testServer(ds, &mqs.Mock{}, fnl, rnr)
for i, test := range []struct { for i, test := range []struct {
path string path string
body string body string

View File

@@ -13,17 +13,16 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab-odx.oracle.com/odx/functions/api/datastore" "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/models"
"gitlab-odx.oracle.com/odx/functions/api/mqs" "gitlab-odx.oracle.com/odx/functions/api/mqs"
"gitlab-odx.oracle.com/odx/functions/api/runner" "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/server/internal/routecache"
"gitlab-odx.oracle.com/odx/functions/api/logs"
) )
var tmpDatastoreBolt = "/tmp/func_test_bolt_datastore.db" var tmpDatastoreBolt = "/tmp/func_test_bolt_datastore.db"
var tmpLogBolt = "/tmp/func_test_bolt_log.db" var tmpLogBolt = "/tmp/func_test_bolt_log.db"
func testServer(ds models.Datastore, mq models.MessageQueue, logDB models.FnLog, rnr *runner.Runner) *Server { func testServer(ds models.Datastore, mq models.MessageQueue, logDB models.FnLog, rnr *runner.Runner) *Server {
ctx := context.Background() ctx := context.Background()
@@ -94,7 +93,7 @@ func prepareBolt(ctx context.Context, t *testing.T) (models.Datastore, models.Fn
if err != nil { if err != nil {
t.Fatalf("Error when creating log store: %s", err) t.Fatalf("Error when creating log store: %s", err)
} }
return ds,logDB, func() { return ds, logDB, func() {
os.Remove(tmpDatastoreBolt) os.Remove(tmpDatastoreBolt)
os.Remove(tmpLogBolt) os.Remove(tmpLogBolt)
} }

View File

@@ -29,7 +29,7 @@ func main() {
log.Fatal(errors.Wrap(err, "failed to read stdin")) 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 { if err != nil {
log.Println("Failed to connect to postgres server") log.Println("Failed to connect to postgres server")
log.Fatal(err) log.Fatal(err)
@@ -96,7 +96,7 @@ func selectCommand(req []byte, db *sql.DB) (string, error) {
func insertCommand(req []byte, db *sql.DB) error { func insertCommand(req []byte, db *sql.DB) error {
q := "INSERT INTO " + table + " SELECT * FROM json_populate_record(null::" + table + ", $1)" q := "INSERT INTO " + table + " SELECT * FROM json_populate_record(null::" + table + ", $1)"
_, err := db.Exec(q, req) _, err := db.Exec(q, req)
if err != nil { if err != nil {
return errors.Wrap(err, "Failed to execute insert query") return errors.Wrap(err, "Failed to execute insert query")
} }
return nil return nil

View File

@@ -1,10 +1,10 @@
package main package main
import ( import (
"fmt"
"encoding/json" "encoding/json"
"os" "fmt"
"math/rand" "math/rand"
"os"
) )
const lBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" const lBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -13,7 +13,6 @@ type OutputSize struct {
Size int `json:"size"` Size int `json:"size"`
} }
func RandStringBytes(n int) string { func RandStringBytes(n int) string {
b := make([]byte, n) b := make([]byte, n)
for i := range b { for i := range b {

View File

@@ -8,11 +8,11 @@ import (
"context" "context"
fnclient "github.com/funcy/functions_go/client" fnclient "github.com/funcy/functions_go/client"
client "gitlab-odx.oracle.com/odx/functions/fn/client"
apiapps "github.com/funcy/functions_go/client/apps" apiapps "github.com/funcy/functions_go/client/apps"
"github.com/funcy/functions_go/models" "github.com/funcy/functions_go/models"
"github.com/jmoiron/jsonq" "github.com/jmoiron/jsonq"
"github.com/urfave/cli" "github.com/urfave/cli"
client "gitlab-odx.oracle.com/odx/functions/fn/client"
"strings" "strings"
) )

View File

@@ -5,10 +5,10 @@ import (
"fmt" "fmt"
fnclient "github.com/funcy/functions_go/client" fnclient "github.com/funcy/functions_go/client"
client "gitlab-odx.oracle.com/odx/functions/fn/client"
apicall "github.com/funcy/functions_go/client/call" apicall "github.com/funcy/functions_go/client/call"
"github.com/funcy/functions_go/models" "github.com/funcy/functions_go/models"
"github.com/urfave/cli" "github.com/urfave/cli"
client "gitlab-odx.oracle.com/odx/functions/fn/client"
) )
type callsCmd struct { type callsCmd struct {

View File

@@ -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 { func CallFN(u string, content io.Reader, output io.Writer, method string, env []string) error {
if method == "" { if method == "" {
if content == nil { if content == nil {

View File

@@ -12,13 +12,13 @@ import (
) )
var aliases = map[string]cli.Command{ var aliases = map[string]cli.Command{
"build": build(), "build": build(),
"bump": bump(), "bump": bump(),
"deploy": deploy(), "deploy": deploy(),
"push": push(), "push": push(),
"run": run(), "run": run(),
"call": call(), "call": call(),
"calls": calls(), "calls": calls(),
} }
func aliasesFn() []cli.Command { func aliasesFn() []cli.Command {

View File

@@ -1,10 +1,10 @@
package main package main
import ( import (
"gitlab-odx.oracle.com/odx/functions/fn/client"
"net/http" "net/http"
"os" "os"
"testing" "testing"
"gitlab-odx.oracle.com/odx/functions/fn/client"
) )
func TestEnvAsHeader(t *testing.T) { func TestEnvAsHeader(t *testing.T) {

View File

@@ -11,9 +11,9 @@ import (
"strings" "strings"
"time" "time"
"gitlab-odx.oracle.com/odx/functions/fn/client"
functions "github.com/funcy/functions_go" functions "github.com/funcy/functions_go"
"github.com/urfave/cli" "github.com/urfave/cli"
"gitlab-odx.oracle.com/odx/functions/fn/client"
) )
func testfn() cli.Command { func testfn() cli.Command {

View File

@@ -1,15 +1,14 @@
package tests package tests
import ( import (
"reflect"
"strings"
"testing" "testing"
"time" "time"
"strings"
"reflect"
"github.com/funcy/functions_go/client/apps" "github.com/funcy/functions_go/client/apps"
) )
func TestApps(t *testing.T) { func TestApps(t *testing.T) {
s := SetupDefaultSuite() s := SetupDefaultSuite()
@@ -50,14 +49,14 @@ func TestApps(t *testing.T) {
}) })
t.Run("create-app-with-config-test", func(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.Logf("Test `%v` passed.", t.Name())
}) })
t.Run("inspect-app-with-config-test", func(t *testing.T) { t.Run("inspect-app-with-config-test", func(t *testing.T) {
cfg := &apps.GetAppsAppParams{ cfg := &apps.GetAppsAppParams{
Context: s.Context, Context: s.Context,
App: s.AppName, App: s.AppName,
} }
appPayload, err := s.Client.Apps.GetAppsApp(cfg) appPayload, err := s.Client.Apps.GetAppsApp(cfg)
CheckAppResponseError(t, err) CheckAppResponseError(t, err)
@@ -73,7 +72,7 @@ func TestApps(t *testing.T) {
t.Logf("Test `%v` passed.", t.Name()) 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{ config := map[string]string{
"A": "b", "A": "b",
} }

View File

@@ -2,13 +2,13 @@ package tests
import ( import (
"bytes" "bytes"
"testing"
"time"
"net/url" "net/url"
"path" "path"
"testing"
"time"
"gitlab-odx.oracle.com/odx/functions/fn/client"
"github.com/funcy/functions_go/client/call" "github.com/funcy/functions_go/client/call"
"gitlab-odx.oracle.com/odx/functions/fn/client"
) )
func TestCalls(t *testing.T) { 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) { t.Run("list-calls-for-missing-app", func(t *testing.T) {
cfg := &call.GetAppsAppCallsRouteParams{ cfg := &call.GetAppsAppCallsRouteParams{
App: s.AppName, App: s.AppName,
Route: s.RoutePath, Route: s.RoutePath,
Context: s.Context, Context: s.Context,
} }
_, err := s.Client.Call.GetAppsAppCallsRoute(cfg) _, 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) { t.Run("list-calls-for-missing-route", func(t *testing.T) {
cfg := &call.GetAppsAppCallsRouteParams{ cfg := &call.GetAppsAppCallsRouteParams{
App: s.AppName, App: s.AppName,
Route: s.RoutePath, Route: s.RoutePath,
Context: s.Context, Context: s.Context,
} }
_, err := s.Client.Call.GetAppsAppCallsRoute(cfg) _, err := s.Client.Call.GetAppsAppCallsRoute(cfg)
@@ -51,7 +51,7 @@ func TestCalls(t *testing.T) {
t.Run("get-dummy-call", func(t *testing.T) { t.Run("get-dummy-call", func(t *testing.T) {
cfg := &call.GetCallsCallParams{ cfg := &call.GetCallsCallParams{
Call: "dummy", Call: "dummy",
Context: s.Context, Context: s.Context,
} }
cfg.WithTimeout(time.Second * 60) cfg.WithTimeout(time.Second * 60)
@@ -67,7 +67,7 @@ func TestCalls(t *testing.T) {
callID := CallAsync(t, u, &bytes.Buffer{}) callID := CallAsync(t, u, &bytes.Buffer{})
time.Sleep(time.Second * 2) time.Sleep(time.Second * 2)
cfg := &call.GetCallsCallParams{ cfg := &call.GetCallsCallParams{
Call: callID, Call: callID,
Context: s.Context, Context: s.Context,
} }
cfg.WithTimeout(time.Second * 60) cfg.WithTimeout(time.Second * 60)
@@ -84,8 +84,8 @@ func TestCalls(t *testing.T) {
t.Run("list-calls", func(t *testing.T) { t.Run("list-calls", func(t *testing.T) {
cfg := &call.GetAppsAppCallsRouteParams{ cfg := &call.GetAppsAppCallsRouteParams{
App: s.AppName, App: s.AppName,
Route: s.RoutePath, Route: s.RoutePath,
Context: s.Context, Context: s.Context,
} }
calls, err := s.Client.Call.GetAppsAppCallsRoute(cfg) calls, err := s.Client.Call.GetAppsAppCallsRoute(cfg)

View File

@@ -1,27 +1,26 @@
package tests package tests
import ( import (
"io"
"encoding/json"
"bytes" "bytes"
"testing" "encoding/json"
"time" "io"
"net/url" "net/url"
"path" "path"
"strings" "strings"
"testing"
"time"
"gitlab-odx.oracle.com/odx/functions/fn/client"
"github.com/funcy/functions_go/client/call" "github.com/funcy/functions_go/client/call"
"github.com/funcy/functions_go/client/operations" "github.com/funcy/functions_go/client/operations"
"gitlab-odx.oracle.com/odx/functions/fn/client"
) )
type ErrMsg struct { type ErrMsg struct {
Message string `json:"message"` Message string `json:"message"`
} }
type TimeoutBody struct{ type TimeoutBody struct {
Error ErrMsg `json:"error"` Error ErrMsg `json:"error"`
CallID string `json:"request_id"` CallID string `json:"request_id"`
} }
@@ -51,7 +50,6 @@ func CallAsync(t *testing.T, u url.URL, content io.Reader) string {
return callID.CallID return callID.CallID
} }
func TestRouteExecutions(t *testing.T) { func TestRouteExecutions(t *testing.T) {
s := SetupDefaultSuite() s := SetupDefaultSuite()
newRouteType := "async" newRouteType := "async"
@@ -114,7 +112,7 @@ func TestRouteExecutions(t *testing.T) {
callID := CallAsync(t, u, &bytes.Buffer{}) callID := CallAsync(t, u, &bytes.Buffer{})
time.Sleep(time.Second * 2) time.Sleep(time.Second * 2)
cfg := &call.GetCallsCallParams{ cfg := &call.GetCallsCallParams{
Call: callID, Call: callID,
Context: s.Context, Context: s.Context,
} }
cfg.WithTimeout(time.Second * 60) cfg.WithTimeout(time.Second * 60)
@@ -145,7 +143,6 @@ func TestRouteExecutions(t *testing.T) {
DeleteRoute(t, s.Context, s.Client, s.AppName, s.RoutePath) DeleteRoute(t, s.Context, s.Client, s.AppName, s.RoutePath)
routePath := "/timeout" routePath := "/timeout"
image := "funcy/timeout:0.0.1" image := "funcy/timeout:0.0.1"
routeType := "sync" routeType := "sync"
@@ -176,7 +173,7 @@ func TestRouteExecutions(t *testing.T) {
json.NewDecoder(output).Decode(tB) json.NewDecoder(output).Decode(tB)
cfg := &call.GetCallsCallParams{ cfg := &call.GetCallsCallParams{
Call: tB.CallID, Call: tB.CallID,
Context: s.Context, Context: s.Context,
} }
cfg.WithTimeout(time.Second * 60) cfg.WithTimeout(time.Second * 60)
@@ -210,7 +207,7 @@ func TestRouteExecutions(t *testing.T) {
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
cfg := &operations.GetCallsCallLogParams{ cfg := &operations.GetCallsCallLogParams{
Call: callID, Call: callID,
Context: s.Context, Context: s.Context,
} }
@@ -222,11 +219,11 @@ func TestRouteExecutions(t *testing.T) {
t.Fatalf("Log entry must not be empty!") t.Fatalf("Log entry must not be empty!")
} }
if !strings.Contains(logObj.Payload.Log.Log, "First line") { 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) "string, but got: %v", logObj.Payload.Log.Log)
} }
if !strings.Contains(logObj.Payload.Log.Log, "Second line") { 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) "string, but got: %v", logObj.Payload.Log.Log)
} }
}) })
@@ -254,7 +251,7 @@ func TestRouteExecutions(t *testing.T) {
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
cfg := &operations.GetCallsCallLogParams{ cfg := &operations.GetCallsCallLogParams{
Call: callID, Call: callID,
Context: s.Context, Context: s.Context,
} }
@@ -283,7 +280,7 @@ func TestRouteExecutions(t *testing.T) {
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
cfg := &operations.GetCallsCallLogParams{ cfg := &operations.GetCallsCallLogParams{
Call: callID, Call: callID,
Context: s.Context, Context: s.Context,
} }
@@ -293,7 +290,7 @@ func TestRouteExecutions(t *testing.T) {
} }
if len(logObj.Payload.Log.Log) >= size { if len(logObj.Payload.Log.Log) >= size {
t.Fatalf("Log entry suppose to be truncated up to expected size %v, got %v", 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))
} }
}) })

View File

@@ -1,10 +1,10 @@
package main package main
import ( import (
"fmt"
"encoding/json" "encoding/json"
"os" "fmt"
"math/rand" "math/rand"
"os"
) )
const lBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" const lBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -13,7 +13,6 @@ type OutputSize struct {
Size int `json:"size"` Size int `json:"size"`
} }
func RandStringBytes(n int) string { func RandStringBytes(n int) string {
b := make([]byte, n) b := make([]byte, n)
for i := range b { for i := range b {

View File

@@ -6,7 +6,6 @@ import (
"time" "time"
) )
func main() { func main() {
fmt.Fprintln(os.Stderr, "First line") fmt.Fprintln(os.Stderr, "First line")
fmt.Fprintln(os.Stdout, "Ok") fmt.Fprintln(os.Stdout, "Ok")

View File

@@ -28,7 +28,7 @@ func TestRoutes(t *testing.T) {
}) })
t.Run("can-get-corresponding-route", func(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) { if !assertContainsRoute(rObjects, s.RoutePath) {
t.Fatalf("Unable to find corresponding route `%v` in list", s.RoutePath) t.Fatalf("Unable to find corresponding route `%v` in list", s.RoutePath)
} }

View File

@@ -3,45 +3,43 @@ package tests
import ( import (
"context" "context"
"strings" "strings"
"time"
"testing" "testing"
"time"
fn "github.com/funcy/functions_go/client" fn "github.com/funcy/functions_go/client"
"github.com/funcy/functions_go/models"
"github.com/funcy/functions_go/client/apps" "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/client/routes"
"github.com/funcy/functions_go/models"
"gitlab-odx.oracle.com/odx/functions/fn/client"
) )
type SuiteSetup struct { type SuiteSetup struct {
Context context.Context Context context.Context
Client *fn.Functions Client *fn.Functions
AppName string AppName string
RoutePath string RoutePath string
Image string Image string
RouteType string RouteType string
Format string Format string
Memory int64 Memory int64
RouteConfig map[string]string RouteConfig map[string]string
RouteHeaders map[string][]string RouteHeaders map[string][]string
} }
func SetupDefaultSuite() *SuiteSetup { func SetupDefaultSuite() *SuiteSetup {
return &SuiteSetup{ return &SuiteSetup{
Context: context.Background(), Context: context.Background(),
Client: client.APIClient(), Client: client.APIClient(),
AppName: "test-app", AppName: "test-app",
RoutePath: "/hello", RoutePath: "/hello",
Image: "funcy/hello", Image: "funcy/hello",
Format: "default", Format: "default",
RouteType: "async", RouteType: "async",
RouteConfig: map[string]string{}, RouteConfig: map[string]string{},
RouteHeaders: map[string][]string{}, RouteHeaders: map[string][]string{},
} }
} }
func CheckAppResponseError(t *testing.T, err error) { func CheckAppResponseError(t *testing.T, err error) {
if err != nil { if err != nil {
switch err.(type) { 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{ cfg := &apps.PostAppsParams{
Body: &models.AppWrapper{ Body: &models.AppWrapper{
App: &models.App{ App: &models.App{
Config: config, Config: config,
Name: appName, Name: appName,
}, },
}, },
Context: ctx, 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"}) CreateApp(t, ctx, fnclient, appName, map[string]string{"A": "a"})
cfg := &apps.PatchAppsAppParams{ cfg := &apps.PatchAppsAppParams{
App: appName, App: appName,
Body: &models.AppWrapper{ Body: &models.AppWrapper{
App: &models.App{ App: &models.App{
Config: config, Config: config,
Name: "", Name: "",
}, },
}, },
Context: ctx, 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) { func DeleteApp(t *testing.T, ctx context.Context, fnclient *fn.Functions, appName string) {
cfg := &apps.DeleteAppsAppParams{ cfg := &apps.DeleteAppsAppParams{
App: appName, App: appName,
Context: ctx, Context: ctx,
} }
cfg.WithTimeout(time.Second * 60) cfg.WithTimeout(time.Second * 60)
@@ -143,7 +141,6 @@ func DeleteApp(t *testing.T, ctx context.Context, fnclient *fn.Functions, appNam
CheckAppResponseError(t, err) CheckAppResponseError(t, err)
} }
func CheckRouteResponseError(t *testing.T, err error) { func CheckRouteResponseError(t *testing.T, err error) {
if err != nil { if err != nil {
switch err.(type) { switch err.(type) {
@@ -256,11 +253,11 @@ func createRoute(ctx context.Context, fnclient *fn.Functions, appName, image, ro
App: appName, App: appName,
Body: &models.RouteWrapper{ Body: &models.RouteWrapper{
Route: &models.Route{ Route: &models.Route{
Config: routeConfig, Config: routeConfig,
Headers: headers, Headers: headers,
Image: image, Image: image,
Path: routePath, Path: routePath,
Type: routeType, Type: routeType,
}, },
}, },
Context: ctx, 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) 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{ cfg := &routes.DeleteAppsAppRoutesRouteParams{
App: appName, App: appName,
Route: routePath, Route: routePath,
Context: ctx, Context: ctx,
} }
cfg.WithTimeout(time.Second * 60) 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 { func ListRoutes(t *testing.T, ctx context.Context, fnclient *fn.Functions, appName string) []*models.Route {
cfg := &routes.GetAppsAppRoutesParams{ cfg := &routes.GetAppsAppRoutesParams{
App: appName, App: appName,
Context: ctx, Context: ctx,
} }
cfg.WithTimeout(time.Second * 60) 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 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{ cfg := &routes.GetAppsAppRoutesRouteParams{
App: appName, App: appName,
Route: routePath, Route: routePath,
Context: ctx, Context: ctx,
} }
cfg.WithTimeout(time.Second * 60) 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 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) routeObject := GetRoute(t, ctx, fnclient, appName, routePath)
if routeObject.Config == nil { if routeObject.Config == nil {
@@ -364,7 +361,7 @@ func UpdateRoute(t *testing.T, ctx context.Context, fnclient *fn.Functions, appN
} }
cfg := &routes.PatchAppsAppRoutesRouteParams{ cfg := &routes.PatchAppsAppRoutesRouteParams{
App: appName, App: appName,
Context: ctx, Context: ctx,
Body: &models.RouteWrapper{ Body: &models.RouteWrapper{
Route: routeObject, Route: routeObject,

23
go-fmt.sh Executable file
View 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

View File

@@ -1,30 +1,30 @@
package main package main
import ( import (
"fmt"
"net/http"
"io/ioutil"
"encoding/json" "encoding/json"
"time"
"flag" "flag"
"fmt"
"io/ioutil"
"log" "log"
"net/http"
"strings" "strings"
"time"
) )
type execution struct { type execution struct {
DurationSeconds float64 DurationSeconds float64
Hostname string Hostname string
node string node string
body string body string
responseSeconds float64 responseSeconds float64
} }
var ( var (
lbHostPort, nodesStr, route string lbHostPort, nodesStr, route string
numExecutions, maxPrime, numLoops int numExecutions, maxPrime, numLoops int
nodes []string nodes []string
nodesByContainerId map[string]string = make(map[string]string) nodesByContainerId map[string]string = make(map[string]string)
verbose bool verbose bool
) )
func init() { func init() {
@@ -124,4 +124,3 @@ func main() {
discoverContainerIds() discoverContainerIds()
invokeLoadBalancer(lbHostPort, route, numExecutions, maxPrime, numLoops) invokeLoadBalancer(lbHostPort, route, numExecutions, maxPrime, numLoops)
} }

View File

@@ -3,8 +3,8 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"strings"
"strconv" "strconv"
"strings"
"time" "time"
) )
@@ -50,10 +50,9 @@ func main() {
for i := 0; i < numLoops; i++ { for i := 0; i < numLoops; i++ {
primes := sieveOfEratosthenes(maxPrime) primes := sieveOfEratosthenes(maxPrime)
_ = primes _ = 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("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) fmt.Printf("{\"durationSeconds\": %f, \"hostname\": \"%s\", \"max\": %d, \"loops\": %d}", time.Since(start).Seconds(), os.Getenv("HOSTNAME"), maxPrime, numLoops)
} }