PageRenderTime 69ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/engine/init_test.go

https://github.com/dotcloud/docker
Go | 42 lines | 35 code | 5 blank | 2 comment | 6 complexity | 7a478694a04eee343614206699b4cd8b MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0, BSD-2-Clause, CC-BY-4.0, 0BSD, CC-BY-SA-4.0, GPL-2.0, BSD-3-Clause, MIT
  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 init() {
  12. Register("dummy", func(job *Job) string { return "" })
  13. }
  14. func mkEngine(t *testing.T) *Engine {
  15. // Use the caller function name as a prefix.
  16. // This helps trace temp directories back to their test.
  17. pc, _, _, _ := runtime.Caller(1)
  18. callerLongName := runtime.FuncForPC(pc).Name()
  19. parts := strings.Split(callerLongName, ".")
  20. callerShortName := parts[len(parts)-1]
  21. if globalTestID == "" {
  22. globalTestID = utils.RandomString()[:4]
  23. }
  24. prefix := fmt.Sprintf("docker-test%s-%s-", globalTestID, callerShortName)
  25. root, err := ioutil.TempDir("", prefix)
  26. if err != nil {
  27. t.Fatal(err)
  28. }
  29. eng, err := New(root)
  30. if err != nil {
  31. t.Fatal(err)
  32. }
  33. return eng
  34. }
  35. func mkJob(t *testing.T, name string, args ...string) *Job {
  36. return mkEngine(t).Job(name, args...)
  37. }