Add go fmt

This commit is contained in:
James Jeffrey
2017-07-07 10:14:08 -07:00
committed by Reed Allman
parent 9a7141967c
commit 81e39b210d
40 changed files with 185 additions and 187 deletions

View File

@@ -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)

View File

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

View File

@@ -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 {

View File

@@ -8,4 +8,4 @@ import (
func TestDatastore(t *testing.T) {
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`
type PostgresDatastore struct {
db *sql.DB
}

View File

@@ -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(

View File

@@ -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)

View File

@@ -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) {

View File

@@ -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
}

View File

@@ -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)

View File

@@ -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)
}

View File

@@ -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

View File

@@ -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,

View File

@@ -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 {

View File

@@ -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"},
}

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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)
}