Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
updated the integration tests to use gometalinter and setup a bunch o…
Browse files Browse the repository at this point in the history
…f linters that need to pass before a PR can merge. (#1025)

* updated the integration tests to use gometalinter and setup a bunch of
linters that need to pass before a PR can merge.

* added the --deadline flag for gometalinter

* lol, apparently that new line was important. oops

* removed a deprecated call

* added a missing return
  • Loading branch information
markbates committed Apr 14, 2018
1 parent 92582b1 commit e8adcbf
Show file tree
Hide file tree
Showing 33 changed files with 120 additions and 112 deletions.
3 changes: 3 additions & 0 deletions .gometalinter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Enable": ["vet", "golint", "goimports", "deadcode", "gotype", "ineffassign", "misspell", "nakedret", "unconvert", "megacheck", "varcheck"]
}
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ FROM gobuffalo/buffalo:development

RUN buffalo version

RUN go get -v -u github.com/golang/lint/golint
RUN go get -u github.com/alecthomas/gometalinter
RUN gometalinter --install
RUN go get -v -u github.com/markbates/filetest
RUN go get -v -u github.com/gobuffalo/makr
RUN go get -v -u github.com/markbates/grift
Expand All @@ -24,18 +25,17 @@ RUN go get -v -t ./...

RUN go install -v -tags sqlite ./buffalo

RUN go test -tags sqlite -race $(go list ./... | grep -v /vendor/)

RUN golint -set_exit_status $(go list ./... | grep -v /vendor/)
RUN go test -tags sqlite -race ./...

RUN gometalinter --vendor --deadline=5m ./...

WORKDIR $GOPATH/src/
RUN buffalo new --db-type=sqlite3 hello_world --ci-provider=travis
WORKDIR ./hello_world

RUN filetest -c $GOPATH/src/github.com/gobuffalo/buffalo/buffalo/cmd/filetests/new_travis.json

RUN go vet -x $(go list ./... | grep -v /vendor/)
RUN go vet ./...
RUN buffalo db create -a
RUN buffalo db migrate -e test
RUN buffalo test -race
Expand Down
37 changes: 15 additions & 22 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,19 @@ func (a *App) Serve() error {
<-ctx.Done()
logrus.Info("Shutting down application")

err := a.Stop(ctx.Err())
if err != nil {
if err := a.Stop(ctx.Err()); err != nil {
logrus.Error(err)
}

if !a.WorkerOff {
// stop the workers
logrus.Info("Shutting down worker")
err = a.Worker.Stop()
if err != nil {
if err := a.Worker.Stop(); err != nil {
logrus.Error(err)
}
}

err = server.Shutdown(ctx)
if err != nil {
if err := server.Shutdown(ctx); err != nil {
logrus.Error(err)
}

Expand All @@ -73,32 +70,29 @@ func (a *App) Serve() error {
// if configured to do so, start the workers
if !a.WorkerOff {
go func() {
err := a.Worker.Start(ctx)
if err != nil {
if err := a.Worker.Start(ctx); err != nil {
a.Stop(err)
}
}()
}

var err error

if strings.HasPrefix(a.Options.Addr, "unix:") {
// Use an UNIX socket
listener, err := net.Listen("unix", a.Options.Addr[5:])
if err != nil {
return a.Stop(err)
}
// start the web server
err = server.Serve(listener)
} else {
// Use a TCP socket
server.Addr = a.Options.Addr

// start the web server
err = server.ListenAndServe()
if err = server.Serve(listener); err != nil {
return a.Stop(err)
}
return nil
}
// Use a TCP socket
server.Addr = a.Options.Addr

if err != nil {
// start the web server
if err := server.ListenAndServe(); err != nil {
return a.Stop(err)
}

Expand Down Expand Up @@ -126,8 +120,7 @@ func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

var h http.Handler
h = a.router
var h http.Handler = a.router
if a.Env == "development" {
h = web.ErrorChecker(h)
}
Expand Down Expand Up @@ -160,8 +153,8 @@ func New(opts Options) *App {
}
}

a.router.NotFoundHandler = http.HandlerFunc(notFoundHandler("path not found: %s %s", 404))
a.router.MethodNotAllowedHandler = http.HandlerFunc(notFoundHandler("method not found: %s %s", 405))
a.router.NotFoundHandler = notFoundHandler("path not found: %s %s", 404)
a.router.MethodNotAllowedHandler = notFoundHandler("method not found: %s %s", 405)

if a.MethodOverride == nil {
a.MethodOverride = MethodOverride
Expand Down
5 changes: 1 addition & 4 deletions binding/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ type File struct {

// Valid if there is an actual uploaded file
func (f File) Valid() bool {
if f.File == nil {
return false
}
return true
return f.File != nil
}

func (f File) String() string {
Expand Down
7 changes: 4 additions & 3 deletions binding/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ func newfileUploadRequest(uri string, paramName, path string) (*http.Request, er
if err != nil {
return nil, err
}
_, err = io.Copy(part, file)
if _, err = io.Copy(part, file); err != nil {
return nil, err
}

err = writer.Close()
if err != nil {
if err = writer.Close(); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion buffalo/cmd/build/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (b *Builder) validateTemplates() error {
return nil
}
errs := []string{}
err := filepath.Walk(filepath.Join(b.App.Root, "templates"), func(path string, info os.FileInfo, err error) error {
err := filepath.Walk(filepath.Join(b.App.Root, "templates"), func(path string, info os.FileInfo, _ error) error {
if info == nil || info.IsDir() {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions buffalo/cmd/destroy/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ var ResourceCmd = &cobra.Command{

func confirm(msg string) bool {
reader := bufio.NewReader(os.Stdin)
fmt.Printf(msg)
fmt.Print(msg)
text, _ := reader.ReadString('\n')

return (text == "y\n" || text == "Y\n")
}

func removeTemplates(fileName string) {
if YesToAll || confirm("Want to remove templates? (Y/n)") {
templatesFolder := fmt.Sprintf(filepath.Join("templates", fileName))
templatesFolder := filepath.Join("templates", fileName)
logrus.Infof("- Deleted %v folder\n", templatesFolder)
os.RemoveAll(templatesFolder)
}
Expand Down
9 changes: 5 additions & 4 deletions buffalo/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,16 @@ func startWebpack(ctx context.Context) error {

func startDevServer(ctx context.Context) error {
cfgFile := "./.buffalo.dev.yml"
_, err := os.Stat(cfgFile)
if err != nil {
if _, err := os.Stat(cfgFile); err != nil {
err = rg.Run("./", map[string]interface{}{
"name": "buffalo",
})
if err != nil {
return err
}
}
c := &refresh.Configuration{}
err = c.Load(cfgFile)
if err != nil {
if err := c.Load(cfgFile); err != nil {
return err
}
c.Debug = devOptions.Debug
Expand Down
2 changes: 0 additions & 2 deletions buffalo/cmd/generate/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ var ResourceCmd = &cobra.Command{
},
}

var resourceMN string

func init() {
ResourceCmd.Flags().BoolVarP(&resourceOptions.SkipMigration, "skip-migration", "s", false, "tells resource generator not-to add model migration")
ResourceCmd.Flags().BoolVarP(&resourceOptions.SkipModel, "skip-model", "", false, "tells resource generator not to generate model nor migrations")
Expand Down
2 changes: 0 additions & 2 deletions buffalo/cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"github.com/spf13/cobra"
)

var rootPath string

var app = newapp.Generator{
App: meta.New("."),
DBType: "postgres",
Expand Down
2 changes: 1 addition & 1 deletion buffalo/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var RootCmd = &cobra.Command{
return nil
}

if insideBuffaloProject() == false {
if !insideBuffaloProject() {
return errors.New("you need to be inside your buffalo project path to run this command")
}

Expand Down
7 changes: 2 additions & 5 deletions buffalo/cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ Tests:
}

func updateGoDepsCheck(app meta.App) error {
deps, _ := deplist.List()
if app.WithDep {
// use github.com/golang/dep
args := []string{"ensure"}
Expand Down Expand Up @@ -189,8 +188,7 @@ func npmCheck(app meta.App) error {
}

func yarnCheck(app meta.App) error {
err := nodeCheck(app)
if err != nil {
if err := nodeCheck(app); err != nil {
return errors.WithStack(err)
}
if _, err := exec.LookPath("yarn"); err != nil {
Expand All @@ -199,8 +197,7 @@ func yarnCheck(app meta.App) error {
return errors.Errorf("This application require yarn, and we could not find it installed on your system. We tried to install it for you, but ran into the following error:\n%s", err)
}
}
err = run(exec.Command("yarn", "install", "--no-progress"))
if err != nil {
if err := run(exec.Command("yarn", "install", "--no-progress")); err != nil {
return errors.Errorf("We encountered the following error when trying to install your asset dependencies using yarn:\n%s", err)
}
return nil
Expand Down
16 changes: 2 additions & 14 deletions buffalo/cmd/updater/dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ import (
"golang.org/x/sync/errgroup"
)

type lockToml struct {
Name string `toml:"name"`
Branch string `toml:"branch"`
Packages []string `toml:"packages"`
Revision string `toml:"revision"`
Version string `toml:"version"`
}

func goGetUpdate(r *Runner) error {
fmt.Println("~~~ Running go get ~~~")
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -68,10 +60,8 @@ func DepEnsure(r *Runner) error {
"github.com/gobuffalo/suite@v2.0.0",
}
args := []string{"ensure", "-v", "-add"}
args = append(args, apkg...)

for _, p := range apkg {
args = append(args, p)
}
cc = exec.Command("dep", args...)
cc.Stdin = os.Stdin
cc.Stderr = os.Stderr
Expand All @@ -87,9 +77,7 @@ func DepEnsure(r *Runner) error {
}

args = []string{"ensure", "-v", "-update"}
for _, p := range upkg {
args = append(args, p)
}
args = append(args, upkg...)
cc = exec.Command("dep", args...)
cc.Stdin = os.Stdin
cc.Stderr = os.Stderr
Expand Down
4 changes: 2 additions & 2 deletions buffalo/cmd/updater/deprecations.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func DeprecrationsCheck(r *Runner) error {
r.Warnings = append(r.Warnings, "app.Start has been removed in v0.11.0. Use app.Serve Instead. [main.go]")
}

return filepath.Walk(filepath.Join(r.App.Root, "actions"), func(path string, info os.FileInfo, err error) error {
return filepath.Walk(filepath.Join(r.App.Root, "actions"), func(path string, info os.FileInfo, _ error) error {
if info.IsDir() {
return nil
}
Expand All @@ -47,7 +47,7 @@ func DeprecrationsCheck(r *Runner) error {
if bytes.Contains(b, []byte("T.LanguageFinder=")) || bytes.Contains(b, []byte("T.LanguageFinder ")) {
r.Warnings = append(r.Warnings, fmt.Sprintf("i18n.Translator#LanguageFinder has been deprecated in v0.11.1. Use i18n.Translator#LanguageExtractors instead. [%s]", path))
}
ioutil.WriteFile(path, b, 664)
ioutil.WriteFile(path, b, 0664)

return nil
})
Expand Down
2 changes: 1 addition & 1 deletion buffalo/cmd/updater/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (c ImportConverter) rewriteFile(name string) error {
}
}

// if no change occured, then we don't need to write to disk, just return.
// if no change occurred, then we don't need to write to disk, just return.
if !change {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions default_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ func (d *DefaultContext) Error(status int, err error) error {
// Websocket is deprecated, and will be removed in v0.12.0. Use github.com/gorilla/websocket directly instead.
func (d *DefaultContext) Websocket() (*websocket.Conn, error) {
warningMsg := "Websocket is deprecated, and will be removed in v0.12.0. Use github.com/gorilla/websocket directly instead."
_, file, no, ok := runtime.Caller(1)
if ok {
if _, file, no, ok := runtime.Caller(1); ok {
warningMsg = fmt.Sprintf("%s Called from %s:%d", warningMsg, file, no)
}
fmt.Println(warningMsg)
return defaultUpgrader.Upgrade(d.Response(), d.Request(), nil)
}

Expand Down
17 changes: 11 additions & 6 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ func productionErrorResponseFor(status int) []byte {
return []byte(prodErrorTmpl)
}

func defaultErrorHandler(status int, err error, c Context) error {
func defaultErrorHandler(status int, origErr error, c Context) error {
env := c.Value("env")

c.Logger().Error(err)
c.Logger().Error(origErr)
c.Response().WriteHeader(status)

if env != nil && env.(string) == "production" {
Expand All @@ -92,17 +92,22 @@ func defaultErrorHandler(status int, err error, c Context) error {
return nil
}

msg := fmt.Sprintf("%+v", err)
msg := fmt.Sprintf("%+v", origErr)
ct := httpx.ContentType(c.Request())
switch strings.ToLower(ct) {
case "application/json", "text/json", "json":
err = json.NewEncoder(c.Response()).Encode(map[string]interface{}{
err := json.NewEncoder(c.Response()).Encode(map[string]interface{}{
"error": msg,
"code": status,
})
if err != nil {
return errors.WithStack(err)
}
case "application/xml", "text/xml", "xml":
default:
err := c.Request().ParseForm()
if err := c.Request().ParseForm(); err != nil {
msg = fmt.Sprintf("%s\n%s", err.Error(), msg)
}
routes := c.Value("routes")
if cd, ok := c.(*DefaultContext); ok {
delete(cd.data, "app")
Expand Down Expand Up @@ -130,7 +135,7 @@ func defaultErrorHandler(status int, err error, c Context) error {
_, err = res.Write([]byte(t))
return err
}
return err
return nil
}

type inspectHeaders http.Header
Expand Down
2 changes: 1 addition & 1 deletion generators/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (act Generator) buildTestsTemplate(filePath string) string {
func (act Generator) addTemplateFiles(actionsToAdd []inflect.Name, data makr.Data) error {
for _, action := range actionsToAdd {
vg := makr.New()
viewPath := filepath.Join("templates", fmt.Sprintf("%s", act.Name.File()), fmt.Sprintf("%s.html", action.File()))
viewPath := filepath.Join("templates", act.Name.File(), fmt.Sprintf("%s.html", action.File()))
vg.Add(makr.NewFile(viewPath, viewTmpl))
err := vg.Run(".", makr.Data{
"opts": act,
Expand Down
2 changes: 1 addition & 1 deletion generators/grift/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func New(args ...string) (Generator, error) {
for _, n := range strings.Split(args[0], ":") {
g.Parts = append(g.Parts, inflect.Name(n))
}
g.Name = inflect.Name(g.Parts[len(g.Parts)-1])
g.Name = g.Parts[len(g.Parts)-1]
}

return g, g.Validate()
Expand Down

0 comments on commit e8adcbf

Please sign in to comment.