github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/plugins/plugdeps/plugdeps_test.go (about) 1 package plugdeps 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 8 "github.com/gobuffalo/meta" 9 "github.com/segakazzz/buffalo/internal/takeon/github.com/markbates/errx" 10 "github.com/stretchr/testify/require" 11 ) 12 13 var heroku = Plugin{ 14 Binary: "buffalo-heroku", 15 GoGet: "github.com/gobuffalo/buffalo-heroku", 16 Commands: []Command{ 17 {Name: "deploy", Flags: []string{"-v"}}, 18 }, 19 Tags: []string{"foo", "bar"}, 20 } 21 22 var local = Plugin{ 23 Binary: "buffalo-hello.rb", 24 Local: "./plugins/buffalo-hello.rb", 25 } 26 27 func Test_ConfigPath(t *testing.T) { 28 r := require.New(t) 29 30 x := ConfigPath(meta.App{Root: "foo"}) 31 r.Equal(x, filepath.Join("foo", "config", "buffalo-plugins.toml")) 32 } 33 34 func Test_List_Off(t *testing.T) { 35 r := require.New(t) 36 37 app := meta.App{} 38 plugs, err := List(app) 39 r.Error(err) 40 r.Equal(errx.Unwrap(err), ErrMissingConfig) 41 r.Len(plugs.List(), 0) 42 } 43 44 func Test_List_On(t *testing.T) { 45 r := require.New(t) 46 47 app := meta.New(os.TempDir()) 48 49 p := ConfigPath(app) 50 r.NoError(os.MkdirAll(filepath.Dir(p), 0755)) 51 f, err := os.Create(p) 52 r.NoError(err) 53 f.WriteString(eToml) 54 r.NoError(f.Close()) 55 56 plugs, err := List(app) 57 r.NoError(err) 58 r.Len(plugs.List(), 3) 59 } 60 61 const eToml = `[[plugin]] 62 binary = "buffalo-hello.rb" 63 local = "./plugins/buffalo-hello.rb" 64 65 [[plugin]] 66 binary = "buffalo-heroku" 67 go_get = "github.com/gobuffalo/buffalo-heroku" 68 tags = ["foo", "bar"] 69 70 [[plugin.command]] 71 name = "deploy" 72 flags = ["-v"] 73 74 [[plugin]] 75 binary = "buffalo-pop" 76 go_get = "github.com/gobuffalo/buffalo-pop/v2" 77 `