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

show error when go modules is used with --with-dep #1390

Merged
merged 2 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions generators/newapp/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ var Templates = packr.NewBox("../newapp/templates")
// ErrNotInGoPath can be asserted against
var ErrNotInGoPath = errors.New("currently not in a $GOPATH")

var errGoModulesWithDep = errors.New("--with-dep cannot be used with Go Modules enabled")

// Generator is the representation of a new Buffalo application
type Generator struct {
meta.App
Expand Down Expand Up @@ -118,9 +120,14 @@ func (g Generator) Validate() error {
}

func (g Generator) validateInGoPath() error {
if g.App.WithModules && g.App.WithDep {
return errGoModulesWithDep
}

if g.App.WithModules {
return nil
}

gpMultiple := envy.GoPaths()

larp := strings.ToLower(meta.ResolveSymlinks(filepath.Dir(g.Root)))
Expand Down
27 changes: 27 additions & 0 deletions generators/newapp/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package newapp
import (
"testing"

"github.com/gobuffalo/buffalo/meta"
"github.com/gobuffalo/packr"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -31,3 +32,29 @@ func Test_Validate_TemplatesMissing(t *testing.T) {
r.Error(err)
r.Equal(ErrTemplatesNotFound, errors.Cause(err))
}

func Test_Validate_InGoPath(t *testing.T) {
r := require.New(t)

tests := []struct {
g Generator
err error
}{
{
g: Generator{
App: meta.App{WithModules: true},
},
err: nil,
},
{
g: Generator{
App: meta.App{WithModules: true, WithDep: true},
},
err: errGoModulesWithDep,
},
}

for _, test := range tests {
r.Equal(test.err, test.err)
}
}