1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/engine/helpers_test.go

39 lines
857 B
Go
Raw Normal View History

2013-10-23 04:35:26 -04:00
package engine
import (
"fmt"
"github.com/dotcloud/docker/utils"
2013-11-07 15:19:24 -05:00
"io/ioutil"
"runtime"
"strings"
"testing"
2013-10-23 04:35:26 -04:00
)
var globalTestID string
func newTestEngine(t *testing.T) *Engine {
2013-10-23 04:35:26 -04:00
// Use the caller function name as a prefix.
// This helps trace temp directories back to their test.
pc, _, _, _ := runtime.Caller(1)
callerLongName := runtime.FuncForPC(pc).Name()
parts := strings.Split(callerLongName, ".")
callerShortName := parts[len(parts)-1]
if globalTestID == "" {
globalTestID = utils.RandomString()[:4]
}
prefix := fmt.Sprintf("docker-test%s-%s-", globalTestID, callerShortName)
root, err := ioutil.TempDir("", prefix)
if err != nil {
t.Fatal(err)
}
eng, err := New(root)
if err != nil {
t.Fatal(err)
}
return eng
}
func mkJob(t *testing.T, name string, args ...string) *Job {
return newTestEngine(t).Job(name, args...)
2013-10-23 04:35:26 -04:00
}