github.com/goreleaser/goreleaser@v1.25.1/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(tb testing.TB) string { 14 tb.Helper() 15 folder := tb.TempDir() 16 current, err := os.Getwd() 17 require.NoError(tb, err) 18 require.NoError(tb, os.Chdir(folder)) 19 tb.Cleanup(func() { 20 require.NoError(tb, os.Chdir(current)) 21 }) 22 return folder 23 }