github.com/amane3/goreleaser@v0.182.0/internal/testlib/mktemp.go (about)

     1  // Package testlib contains test helpers for goreleaser tests.
     2  package testlib
     3  
     4  import (
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  // Mktmp creates a new tempdir, cd into it and provides a back function that
    12  // cd into the previous directory.
    13  func Mktmp(t testing.TB) string {
    14  	var folder = t.TempDir()
    15  	current, err := os.Getwd()
    16  	require.NoError(t, err)
    17  	require.NoError(t, os.Chdir(folder))
    18  	t.Cleanup(func() {
    19  		require.NoError(t, os.Chdir(current))
    20  	})
    21  	return folder
    22  }