Browse Source

hack: encode the name of the current test in temporary directories, for easier tracking

Solomon Hykes 11 years ago
parent
commit
5f58a1fbe4
1 changed files with 23 additions and 3 deletions
  1. 23 3
      utils_test.go

+ 23 - 3
utils_test.go

@@ -2,22 +2,38 @@ package docker
 
 
 import (
 import (
 	"github.com/dotcloud/docker/utils"
 	"github.com/dotcloud/docker/utils"
+	"fmt"
 	"io"
 	"io"
 	"io/ioutil"
 	"io/ioutil"
 	"os"
 	"os"
 	"path"
 	"path"
 	"strings"
 	"strings"
 	"testing"
 	"testing"
+	"runtime"
 )
 )
 
 
 // This file contains utility functions for docker's unit test suite.
 // This file contains utility functions for docker's unit test suite.
 // It has to be named XXX_test.go, apparently, in other to access private functions
 // It has to be named XXX_test.go, apparently, in other to access private functions
 // from other XXX_test.go functions.
 // from other XXX_test.go functions.
 
 
+var globalTestID string
+
 // Create a temporary runtime suitable for unit testing.
 // Create a temporary runtime suitable for unit testing.
 // Call t.Fatal() at the first error.
 // Call t.Fatal() at the first error.
 func mkRuntime(f Fataler) *Runtime {
 func mkRuntime(f Fataler) *Runtime {
-	runtime, err := newTestRuntime()
+	// 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 = GenerateID()[:4]
+	}
+	prefix := fmt.Sprintf("docker-test%s-%s-", globalTestID, callerShortName)
+	utils.Debugf("prefix = '%s'", prefix)
+
+	runtime, err := newTestRuntime(prefix)
 	if err != nil {
 	if err != nil {
 		f.Fatal(err)
 		f.Fatal(err)
 	}
 	}
@@ -30,9 +46,13 @@ type Fataler interface {
 	Fatal(args ...interface{})
 	Fatal(args ...interface{})
 }
 }
 
 
-func newTestRuntime() (runtime *Runtime, err error) {
+func newTestRuntime(prefix string) (runtime *Runtime, err error) {
+	if prefix == "" {
+		prefix = "docker-test-"
+	}
+	utils.Debugf("prefix = %s", prefix)
 	utils.Debugf("newTestRuntime start")
 	utils.Debugf("newTestRuntime start")
-	root, err := ioutil.TempDir("", "docker-test")
+	root, err := ioutil.TempDir("", prefix)
 	defer func() {
 	defer func() {
 		utils.Debugf("newTestRuntime: %s", root)
 		utils.Debugf("newTestRuntime: %s", root)
 	}()
 	}()