github.com/markbates/grift@v1.5.0/cli/run_test.go (about)

     1  package cli
     2  
     3  import (
     4  	"bytes"
     5  	"context"
     6  	"os"
     7  	"path/filepath"
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func Test_Run(t *testing.T) {
    15  	r := require.New(t)
    16  
    17  	bb := &bytes.Buffer{}
    18  
    19  	ctx := context.Background()
    20  	ctx = WithStdout(bb, ctx)
    21  
    22  	args := []string{"db:seed", "1", "2", "3"}
    23  
    24  	pwd, err := os.Getwd()
    25  	r.NoError(err)
    26  	defer os.Chdir(pwd)
    27  	os.Chdir(filepath.Dir(pwd))
    28  
    29  	err = Run(ctx, args)
    30  	r.NoError(err)
    31  
    32  	act := strings.TrimSpace(bb.String())
    33  
    34  	r.Equal("Seeding DB [1 2 3]", act)
    35  }