mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Merge branch 'add_go_fmt' into 'master'
Add go fmt See merge request !94
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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,7 +14,6 @@ import (
|
||||
"gitlab-odx.oracle.com/odx/functions/api/models"
|
||||
)
|
||||
|
||||
|
||||
type BoltLogDatastore struct {
|
||||
callLogsBucket []byte
|
||||
db *bolt.DB
|
||||
@@ -22,7 +21,6 @@ type BoltLogDatastore struct {
|
||||
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})
|
||||
|
||||
@@ -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,8 +2,8 @@ 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 {
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -49,7 +49,6 @@ type FnCallLog struct {
|
||||
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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
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"`
|
||||
}
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
|
||||
@@ -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,14 +3,14 @@ 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 {
|
||||
@@ -40,8 +40,6 @@ func SetupDefaultSuite() *SuiteSetup {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func CheckAppResponseError(t *testing.T, err error) {
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
@@ -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) {
|
||||
|
||||
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,14 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"encoding/json"
|
||||
"time"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type execution struct {
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -56,4 +56,3 @@ func main() {
|
||||
}
|
||||
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