github.com/gobuffalo/buffalo-cli/v2@v2.0.0-alpha.15.0.20200919213536-a7350c8e6799/cli/cmds/build/cmd_test.go (about) 1 package build 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/gobuffalo/buffalo-cli/v2/cli/cmds/build/buildtest" 8 "github.com/gobuffalo/plugins" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func Test_Cmd_Subcommands(t *testing.T) { 13 r := require.New(t) 14 15 fn := func(ctx context.Context, root string, args []string) error { 16 return nil 17 } 18 b := buildtest.Builder(fn) 19 all := plugins.Plugins{ 20 background("foo"), 21 buildtest.BeforeBuilder(nil), 22 buildtest.Builder(nil), 23 buildtest.AfterBuilder(nil), 24 background("bar"), 25 buildtest.Versioner(nil), 26 buildtest.Packager(nil), 27 buildtest.GoBuilder(nil), 28 } 29 30 bc := &Cmd{ 31 pluginsFn: func() []plugins.Plugin { 32 return all 33 }, 34 } 35 36 plugs := bc.SubCommands() 37 r.Len(plugs, 1) 38 r.Equal(b.PluginName(), plugs[0].PluginName()) 39 } 40 41 func Test_Cmd_ScopedPlugins(t *testing.T) { 42 r := require.New(t) 43 44 all := plugins.Plugins{ 45 background("foo"), 46 buildtest.Builder(nil), 47 buildtest.BeforeBuilder(nil), 48 buildtest.AfterBuilder(nil), 49 background("bar"), 50 buildtest.Versioner(nil), 51 buildtest.Importer(nil), 52 buildtest.GoBuilder(nil), 53 buildtest.Packager(nil), 54 } 55 56 bc := &Cmd{ 57 pluginsFn: func() []plugins.Plugin { 58 return all 59 }, 60 } 61 62 plugs := bc.ScopedPlugins() 63 r.NotEqual(all, plugs) 64 65 ep := plugins.Plugins(plugs) 66 67 tot := len(all) - 2 68 r.Equal(tot, len(ep)) 69 70 }