github.com/DataliftHQ/datalift-cli@v0.1.0/cmd/util_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"github.com/stretchr/testify/require"
     5  	"os"
     6  	"testing"
     7  )
     8  
     9  type exitMemento struct {
    10  	code int
    11  }
    12  
    13  func (e *exitMemento) Exit(i int) {
    14  	e.code = i
    15  }
    16  
    17  func setup(tb testing.TB) string {
    18  	tb.Helper()
    19  
    20  	previous, err := os.Getwd()
    21  	require.NoError(tb, err)
    22  
    23  	tb.Cleanup(func() {
    24  		require.NoError(tb, os.Chdir(previous))
    25  	})
    26  
    27  	folder := tb.TempDir()
    28  	require.NoError(tb, os.Chdir(folder))
    29  
    30  	return folder
    31  }