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