2017-07-23 16:27:46 -03:00
|
|
|
// Package testlib contains test helpers for goreleaser tests.
|
|
|
|
package testlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2020-10-06 09:48:04 -03:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-07-23 16:27:46 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Mktmp creates a new tempdir, cd into it and provides a back function that
|
|
|
|
// cd into the previous directory.
|
2020-12-12 13:27:35 -03:00
|
|
|
func Mktmp(t testing.TB) string {
|
|
|
|
var folder = t.TempDir()
|
2017-07-23 16:27:46 -03:00
|
|
|
current, err := os.Getwd()
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, os.Chdir(folder))
|
2020-12-12 13:27:35 -03:00
|
|
|
t.Cleanup(func() {
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, os.Chdir(current))
|
2020-12-12 13:27:35 -03:00
|
|
|
})
|
|
|
|
return folder
|
2017-07-23 16:27:46 -03:00
|
|
|
}
|