github.com/goreleaser/releaser@v0.92.0/internal/testlib/mktemp.go (about)

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