33 lines
592 B
Go
33 lines
592 B
Go
|
|
package starlog
|
||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"path/filepath"
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func sanitizeTestName(name string) string {
|
||
|
|
replacer := strings.NewReplacer(
|
||
|
|
"/", "_",
|
||
|
|
"\\", "_",
|
||
|
|
":", "_",
|
||
|
|
" ", "_",
|
||
|
|
"\t", "_",
|
||
|
|
".", "_",
|
||
|
|
)
|
||
|
|
return replacer.Replace(name)
|
||
|
|
}
|
||
|
|
|
||
|
|
func testBinDir(t *testing.T) string {
|
||
|
|
t.Helper()
|
||
|
|
dir := filepath.Join("bin", "tests", sanitizeTestName(t.Name()))
|
||
|
|
if err := os.RemoveAll(dir); err != nil {
|
||
|
|
t.Fatalf("cleanup test bin dir failed: %v", err)
|
||
|
|
}
|
||
|
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
||
|
|
t.Fatalf("create test bin dir failed: %v", err)
|
||
|
|
}
|
||
|
|
return dir
|
||
|
|
}
|