helpers_test.go 857 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package engine
  2. import (
  3. "fmt"
  4. "github.com/dotcloud/docker/utils"
  5. "io/ioutil"
  6. "runtime"
  7. "strings"
  8. "testing"
  9. )
  10. var globalTestID string
  11. func newTestEngine(t *testing.T) *Engine {
  12. // Use the caller function name as a prefix.
  13. // This helps trace temp directories back to their test.
  14. pc, _, _, _ := runtime.Caller(1)
  15. callerLongName := runtime.FuncForPC(pc).Name()
  16. parts := strings.Split(callerLongName, ".")
  17. callerShortName := parts[len(parts)-1]
  18. if globalTestID == "" {
  19. globalTestID = utils.RandomString()[:4]
  20. }
  21. prefix := fmt.Sprintf("docker-test%s-%s-", globalTestID, callerShortName)
  22. root, err := ioutil.TempDir("", prefix)
  23. if err != nil {
  24. t.Fatal(err)
  25. }
  26. eng, err := New(root)
  27. if err != nil {
  28. t.Fatal(err)
  29. }
  30. return eng
  31. }
  32. func mkJob(t *testing.T, name string, args ...string) *Job {
  33. return newTestEngine(t).Job(name, args...)
  34. }