Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Tests
on: [push]
on: [push, pull_request]
jobs:

tests:
Expand Down
41 changes: 41 additions & 0 deletions built/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -46,6 +47,34 @@ func Test_App_No_Args(t *testing.T) {
r.True(res)
}

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

app := &App{}

var args []string
ctx := context.Background()
err := app.Main(ctx, "", args)
r.NoError(err)
}

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

var res bool
app := &App{
OriginalMain: func() {
res = true
},
}

args := []string{"--", "bob"}
ctx := context.Background()
err := app.Main(ctx, "", args)
r.NoError(err)
r.True(res)
}

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

Expand Down Expand Up @@ -81,6 +110,18 @@ func Test_App_With_Args_Fallthrough(t *testing.T) {
r.True(res)
}

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

app := &App{}

ctx := context.Background()
root, err := os.Getwd()
r.NoError(err)
err = app.Main(ctx, root, []string{"lee", "majors"})
r.NoError(err)
}

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

Expand Down
6 changes: 1 addition & 5 deletions cli/buffalo.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ type Buffalo struct {
func NewFromRoot(root string) (*Buffalo, error) {
b := &Buffalo{}

pfn := func() []plugins.Plugin {
return b.Plugins
}

b.Plugins = append(b.Plugins, clifix.Plugins()...)
b.Plugins = append(b.Plugins, cmds.Plugins()...)
b.Plugins = append(b.Plugins, fizz.Plugins()...)
Expand Down Expand Up @@ -75,7 +71,7 @@ func NewFromRoot(root string) (*Buffalo, error) {
return b.Plugins[i].PluginName() < b.Plugins[j].PluginName()
})

pfn = func() []plugins.Plugin {
pfn := func() []plugins.Plugin {
return b.Plugins
}

Expand Down
48 changes: 48 additions & 0 deletions cli/buffalo_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
package cli

import (
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/gobuffalo/plugins"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func AssertPluginContained(name string, plugins plugins.Plugins) assert.Comparison {
return func() (success bool) {
success = false
for _, p := range plugins {
if p.PluginName() == name {
return true
}
}
return
}
}

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

Expand All @@ -16,6 +32,38 @@ func Test_Buffalo_New(t *testing.T) {
r.NotEmpty(b.Plugins)
}

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

root, err := os.Getwd()
r.NoError(err)

//create files
r.NoError(ioutil.WriteFile(filepath.Join(root, "package.json"), []byte(""), 0600))
r.NoError(ioutil.WriteFile(filepath.Join(root, ".git"), []byte(""), 0600))
r.NoError(ioutil.WriteFile(filepath.Join(root, ".bzr"), []byte(""), 0600))

b, err := New()
r.NoError(err)
r.NotNil(b)
r.NotEmpty(b.Plugins)

//test for webpack builder include
r.Condition(AssertPluginContained("webpack/builder", b.Plugins))

r.NoError(os.Remove("package.json"))

//test for git builder include
r.Condition(AssertPluginContained("git/versioner", b.Plugins))

r.NoError(os.Remove(".git"))

//test for bzr builder include
r.Condition(AssertPluginContained("bzr", b.Plugins))

r.NoError(os.Remove(".bzr"))
}

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

Expand Down
12 changes: 12 additions & 0 deletions cli/cmds/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/gobuffalo/here"
"github.com/stretchr/testify/require"
)

type background string
Expand All @@ -31,3 +32,14 @@ func newRef(t *testing.T, root string) here.Info {

return info
}

func Test_Plugins(t *testing.T) {
r := require.New(t)
plugs := Plugins()
r.Len(plugs, 2)
for _, p := range plugs {
if p.PluginName() != "main" && p.PluginName() != "build" {
r.FailNow("should only be main and build")
}
}
}
2 changes: 2 additions & 0 deletions cli/cmds/build/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func Test_Cmd_ScopedPlugins(t *testing.T) {
&buildImporter{},
&bladeRunner{},
&packager{},
&buildTagger{},
&buildStdouter{},
}

bc := &Cmd{
Expand Down
111 changes: 111 additions & 0 deletions cli/cmds/build/find_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package build

import (
"testing"

"github.com/gobuffalo/plugins"
"github.com/stretchr/testify/require"
)

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

bb := &buildBuilder{}
plugs := []plugins.Plugin{
&buildFlagger{},
bb,
}

builder := FindBuilder("buildBuilder", plugs)
r.NotNil(builder)
r.Equal(bb.PluginName(), builder.PluginName())
}

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

plugs := []plugins.Plugin{
&buildFlagger{},
&buildImporter{},
}

builder := FindBuilder("buildBuilder", plugs)
r.Nil(builder)
}

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

bn := &buildNamer{cmdName: "first"}
plugs := []plugins.Plugin{
&buildFlagger{},
bn,
}

expects := []struct {
Term string
IsNil bool
IsNamer bool
}{
{"first", false, true},
{"second", true, false},
{"buildNamer", false, true},
{"third", true, false},
{"buildBuilder", true, false},
}

for _, e := range expects {
builder := FindBuilder(e.Term, plugs)
if e.IsNil {
r.Nil(builder)
} else {
r.NotNil(builder)
r.Equal(bn.PluginName(), builder.PluginName())
namer, ok := builder.(Namer)
if e.IsNamer {
r.True(ok)
r.Equal(bn.CmdName(), namer.CmdName())
} else {
r.False(ok)
}
}
}
}

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

ba := &buildAliaser{aliases: []string{"first", "second"}}
plugs := []plugins.Plugin{
&buildFlagger{},
ba,
}

expects := []struct {
Term string
IsNil bool
IsAliaser bool
}{
{"first", false, true},
{"second", false, true},
{"buildAliaser", false, true},
{"third", true, false},
}

for _, expect := range expects {
builder := FindBuilder(expect.Term, plugs)
if expect.IsNil {
r.Nil(builder)
} else {
r.NotNil(builder)
r.Equal(ba.PluginName(), builder.PluginName())
aliaser, ok := builder.(Aliaser)
if expect.IsAliaser {
r.True(ok)
r.Equal(ba.CmdAliases(), aliaser.CmdAliases())
} else {
r.False(ok)
}
}
}
}
80 changes: 80 additions & 0 deletions cli/cmds/build/gobuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package build

import (
"context"
"errors"
"path/filepath"
"runtime"
"testing"

"github.com/gobuffalo/plugins"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -129,3 +131,81 @@ func Test_Cmd_GoCmd_LDFlags(t *testing.T) {
exp := []string{"go", "build", "-o", n, "-ldflags", "linky"}
r.Equal(exp, cmd.Args)
}

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

bc := &Cmd{}

ctx := context.Background()
cmd, err := bc.GoCmd(ctx, "")
r.Error(err)
r.Nil(cmd)
}

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

pfn := func() []plugins.Plugin {
return []plugins.Plugin{
&buildTagger{},
}
}

bc := &Cmd{
pluginsFn: pfn,
}

ctx := context.Background()
cmd, err := bc.GoCmd(ctx, ".")
r.NoError(err)
r.NotNil(cmd)
}

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

pfn := func() []plugins.Plugin {
return []plugins.Plugin{
&buildTagger{err: errors.New("Bad Tagger")},
}
}

bc := &Cmd{
pluginsFn: pfn,
}

ctx := context.Background()
cmd, err := bc.GoCmd(ctx, ".")
r.Error(err)
r.Nil(cmd)
r.Contains(err.Error(), "Bad Tagger")
}

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

pfn := func() []plugins.Plugin {
return []plugins.Plugin{
&bladeRunner{err: errors.New("Bad Runner")},
}
}

bc := &Cmd{
pluginsFn: pfn,
}

ctx := context.Background()
var args []string
err := bc.build(ctx, "", args)
r.Error(err)
if runtime.GOOS == "windows" {
r.Contains(err.Error(), "The system cannot find the path specified")
} else {
r.Contains(err.Error(), "no such file or directory")
}

err = bc.build(ctx, ".", args)
r.Error(err)
r.Contains(err.Error(), "Bad Runner")
}
Loading