Skip to content

Commit

Permalink
reverts v0.5.x fixes #36 (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates authored Dec 24, 2019
1 parent 82a8de1 commit 46253f7
Show file tree
Hide file tree
Showing 27 changed files with 631 additions and 142 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
TAGS ?= ""
GO_BIN ?= "go"

install: packr
cd ./genny && go install -tags ${TAGS} -v .
go install -tags ${TAGS} -v ./genny
make tidy

tidy:
Expand All @@ -16,6 +17,5 @@ test: packr
make tidy

packr:
go get github.com/gobuffalo/packr/v2/packr2
packr2
make tidy
29 changes: 29 additions & 0 deletions depgen/ensure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package depgen

import (
"os/exec"

"github.com/gobuffalo/genny"
)

func Ensure(verbose bool) (*genny.Generator, error) {
g := genny.New()

var args []string
if verbose {
args = append(args, "-v")
}

id, err := InstallDep(args...)
if err != nil {
return g, err
}
g.Merge(id)

cmd := exec.Command("dep", "ensure")
if verbose {
cmd.Args = append(cmd.Args, args...)
}
g.Command(cmd)
return g, nil
}
28 changes: 28 additions & 0 deletions depgen/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package depgen

import (
"os/exec"

"github.com/gobuffalo/genny"
)

func Init(path string, verbose bool) (*genny.Generator, error) {
g := genny.New()
var args []string
if verbose {
args = append(args, "-v")
}

id, err := InstallDep(args...)
if err != nil {
return g, err
}
g.Merge(id)

cmd := exec.Command("dep", "init")
if verbose {
cmd.Args = append(cmd.Args, args...)
}
g.Command(cmd)
return g, nil
}
63 changes: 63 additions & 0 deletions depgen/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package depgen

import (
"os"
"os/exec"
"strings"
"testing"

"github.com/gobuffalo/genny"
"github.com/gobuffalo/genny/gentest"
"github.com/stretchr/testify/require"
)

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

run := gentest.NewRunner()
run.LookPathFn = func(s string) (string, error) {
if s == "dep" {
return "dep", nil
}
return exec.LookPath(s)
}

err := run.WithNew(Init("", false))
r.NoError(err)

r.NoError(run.Run())

res := run.Results()

r.Len(res.Commands, 1)

c := res.Commands[0]
r.Equal("dep init", strings.Join(c.Args, " "))
}

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

run := gentest.NewRunner()
run.LookPathFn = func(s string) (string, error) {
if s == "dep" {
return "", os.ErrNotExist
}
return exec.LookPath(s)
}

err := run.WithNew(Init("", false))
r.NoError(err)

r.NoError(run.Run())

res := run.Results()

r.Len(res.Commands, 2)

c := res.Commands[0]
r.Equal(genny.GoBin()+" get github.com/golang/dep/cmd/dep", strings.Join(c.Args, " "))

c = res.Commands[1]
r.Equal("dep init", strings.Join(c.Args, " "))
}
22 changes: 22 additions & 0 deletions depgen/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package depgen

import (
"os/exec"

"github.com/gobuffalo/genny"
)

func InstallDep(args ...string) (*genny.Generator, error) {
g := genny.New()
g.RunFn(func(r *genny.Runner) error {
if _, err := r.LookPath("dep"); err == nil {
return nil
}

args = append([]string{"get"}, args...)
args = append(args, "github.com/golang/dep/cmd/dep")
c := exec.Command(genny.GoBin(), args...)
return r.Exec(c)
})
return g, nil
}
42 changes: 42 additions & 0 deletions depgen/install_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package depgen

import (
"errors"
"testing"

"github.com/gobuffalo/envy"
"github.com/gobuffalo/genny/gentest"
"github.com/stretchr/testify/require"
)

func Test_InstallDep_NotInstalled(t *testing.T) {
envy.Set("GO_BIN", "go")
r := require.New(t)

run := gentest.NewRunner()
run.LookPathFn = func(s string) (string, error) {
return s, errors.New("couldn't find dep")
}
run.WithNew(InstallDep())
r.NoError(run.Run())

res := run.Results()

cmds := []string{"go get github.com/golang/dep/cmd/dep"}
r.Len(res.Commands, len(cmds))
}

func Test_InstallDep_Installed(t *testing.T) {
envy.Set("GO_BIN", "go")
r := require.New(t)

run := gentest.NewRunner()
run.LookPathFn = func(s string) (string, error) {
return s, nil
}
run.WithNew(InstallDep())
r.NoError(run.Run())

res := run.Results()
r.Len(res.Commands, 0)
}
28 changes: 28 additions & 0 deletions depgen/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package depgen

import (
"os/exec"

"github.com/gobuffalo/genny"
)

func Update(verbose bool) (*genny.Generator, error) {
g := genny.New()
var args []string
if verbose {
args = append(args, "-v")
}

id, err := InstallDep(args...)
if err != nil {
return g, err
}
g.Merge(id)

cmd := exec.Command("dep", "ensure")
args = append(args, "-update")
if verbose {
cmd.Args = append(cmd.Args, args...)
}
return g, nil
}
4 changes: 4 additions & 0 deletions depgen/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package depgen

// Version of depgen
const Version = "v0.2.0"
94 changes: 0 additions & 94 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -1,95 +1 @@
package genny_test

// // exampleLogger just cleans up variable log content
// // such as GOPATH, step names, etc....
// // without this Go Example tests won't work.
// func exampleLogger(l *gentest.Logger) genny.Logger {
// l.CloseFn = func() error {
// s := l.Stream.String()
// c := build.Default
// for _, src := range c.SrcDirs() {
// s = strings.Replace(s, src, "/go/src", -1)
// }
// s = strings.Replace(s, "\\", "/", -1)
//
// for i, line := range strings.Split(s, "\n") {
// if strings.Contains(line, "Step:") {
// s = strings.Replace(s, line, fmt.Sprintf("[DEBU] Step: %d", i+1), 1)
// }
// }
// fmt.Print(s)
// return nil
// }
// return l
// }
//
// func ExampleGenerator_withCommand() {
// // create a new `*genny.Generator`
// g := genny.New()
//
// g.Command(exec.Command("go", "version"))
//
// // create a new `*genny.Runner`
// r := genny.NewRunner(context.Background())
//
// // add a new logger to clean and dump output
// // for the example tests
// r.Logger = exampleLogger(gentest.NewLogger())
//
// // add the generator to the `*genny.Runner`.
// r.With(g)
//
// // run the runner
// if err := r.Run(); err != nil {
// log.Fatal(err)
// }
// // Output:
// // [DEBU] Step: 1
// // [DEBU] Chdir: /go/src/github.com/gobuffalo/genny
// // [DEBU] Exec: go version
// }
//
// func ExampleGenerator_withFile() {
// // create a new `*genny.Generator`
// g := genny.New()
//
// // add a file named `index.html` that has a body of `Hello\n`
// // to the generator
// g.File(genny.NewFileS("index.html", "Hello\n"))
//
// // create a new `*genny.Runner`
// r := genny.NewRunner(context.Background())
//
// // add a new logger to clean and dump output
// // for the example tests
// r.Logger = exampleLogger(gentest.NewLogger())
//
// // add the generator to the `*genny.Runner`.
// r.With(g)
//
// // run the runner
// if err := r.Run(); err != nil {
// log.Fatal(err)
// }
// // Output:
// // [DEBU] Step: 1
// // [DEBU] Chdir: /go/src/github.com/gobuffalo/genny
// // [DEBU] File: /go/src/github.com/gobuffalo/genny/index.html
// }
//
// func ExampleRunner() {
// // create a new `*genny.Runner`
// r := genny.NewRunner(context.Background())
//
// // add a new logger to clean and dump output
// // for the example tests
// r.Logger = exampleLogger(gentest.NewLogger())
//
// // add the generator(s) to the `*genny.Runner`.
// // r.With(g)
//
// // run the runner
// if err := r.Run(); err != nil {
// log.Fatal(err)
// }
// }
Loading

0 comments on commit 46253f7

Please sign in to comment.