1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/testlib/mktemp.go

24 lines
509 B
Go
Raw Normal View History

2017-07-23 21:27:46 +02:00
// Package testlib contains test helpers for goreleaser tests.
package testlib
import (
"os"
"testing"
"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.
func Mktmp(tb testing.TB) string {
tb.Helper()
folder := tb.TempDir()
2017-07-23 21:27:46 +02:00
current, err := os.Getwd()
require.NoError(tb, err)
require.NoError(tb, os.Chdir(folder))
tb.Cleanup(func() {
require.NoError(tb, os.Chdir(current))
})
return folder
2017-07-23 21:27:46 +02:00
}