github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/genny/plugins/install/install_test.go (about)

     1  package install
     2  
     3  import (
     4  	"bytes"
     5  	"go/build"
     6  	"io"
     7  	"path/filepath"
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/gobuffalo/buffalo/plugins/plugdeps"
    12  	"github.com/gobuffalo/genny/v2"
    13  	"github.com/gobuffalo/genny/v2/gentest"
    14  	"github.com/gobuffalo/meta"
    15  	"github.com/stretchr/testify/require"
    16  )
    17  
    18  func Test_New(t *testing.T) {
    19  	r := require.New(t)
    20  
    21  	g, err := New(&Options{
    22  		App: meta.New("."),
    23  		Plugins: []plugdeps.Plugin{
    24  			{Binary: "buffalo-pop", GoGet: "github.com/gobuffalo/buffalo-pop/v2", Tags: meta.BuildTags{"sqlite"}},
    25  			{Binary: "buffalo-hello.rb", Local: "./plugins/buffalo-hello.rb"},
    26  		},
    27  	})
    28  	r.NoError(err)
    29  
    30  	run := gentest.NewRunner()
    31  	c := build.Default
    32  	run.Disk.Add(genny.NewFile(filepath.Join(c.GOPATH, "bin", "buffalo-pop"), &bytes.Buffer{}))
    33  	run.FileFn = func(f genny.File) (genny.File, error) {
    34  		bb := &bytes.Buffer{}
    35  		if _, err := io.Copy(bb, f); err != nil {
    36  			return f, err
    37  		}
    38  		return genny.NewFile(f.Name(), bb), nil
    39  	}
    40  
    41  	run.WithGroup(g)
    42  
    43  	r.NoError(run.Run())
    44  
    45  	res := run.Results()
    46  
    47  	ecmds := []string{"go get -tags sqlite github.com/gobuffalo/buffalo-pop/v2"}
    48  	r.Len(res.Commands, len(ecmds))
    49  	for i, c := range res.Commands {
    50  		r.Equal(ecmds[i], strings.Join(c.Args, " "))
    51  	}
    52  
    53  	efiles := []string{"bin/buffalo-pop", "config/buffalo-plugins.toml"}
    54  	r.Len(res.Files, len(efiles))
    55  	for i, f := range res.Files {
    56  		r.True(strings.HasSuffix(f.Name(), efiles[i]))
    57  	}
    58  }