docker/engine/helpers_test.go

39 строки
857 B
Go
Исходник Обычный вид История

2013-10-23 12:35:26 +04:00
package engine
import (
"fmt"
"github.com/dotcloud/docker/utils"
2013-11-08 00:19:24 +04:00
"io/ioutil"
"runtime"
"strings"
"testing"
2013-10-23 12:35:26 +04:00
)
var globalTestID string
func newTestEngine(t *testing.T) *Engine {
2013-10-23 12: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 12:35:26 +04:00
}