github.com/gobuffalo/buffalo-cli/v2@v2.0.0-alpha.15.0.20200919213536-a7350c8e6799/cli/internal/plugins/bzr/bzr_test.go (about)

     1  package bzr
     2  
     3  import (
     4  	"context"
     5  	"os/exec"
     6  	"testing"
     7  
     8  	"github.com/gobuffalo/plugins"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func Test_Bzr_Generalities(t *testing.T) {
    13  	r := require.New(t)
    14  	b := Versioner{}
    15  
    16  	r.Equal("bzr", b.PluginName(), "Name should be bzr")
    17  	r.Equal("Provides bzr related hooks to Buffalo applications.", b.Description(), "Description does not match")
    18  }
    19  
    20  func Test_Bzr_BuildVersion(t *testing.T) {
    21  
    22  	r := require.New(t)
    23  
    24  	var act []string
    25  	fn := func(ctx context.Context, root string, cmd *exec.Cmd) error {
    26  		act = cmd.Args
    27  		if cmd.Stdout == nil {
    28  			r.FailNow("expected stdout not to be nil")
    29  		}
    30  		cmd.Stdout.Write([]byte("42"))
    31  		return nil
    32  	}
    33  
    34  	v := &Versioner{
    35  		pluginsFn: func() []plugins.Plugin {
    36  			return []plugins.Plugin{
    37  				runner(fn),
    38  			}
    39  		},
    40  	}
    41  
    42  	s, err := v.BuildVersion(context.Background(), "")
    43  	r.NoError(err)
    44  	r.Equal("42", s)
    45  	r.Equal([]string{"bzr", "revno"}, act)
    46  }