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
|
|
|
|
|
2013-10-27 02:57:29 -04:00
|
|
|
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 {
|
2013-10-27 02:57:29 -04:00
|
|
|
return newTestEngine(t).Job(name, args...)
|
2013-10-23 04:35:26 -04:00
|
|
|
}
|