Browse Source

Merge pull request #1591 from dotcloud/1557_fix_docker_run_useage

add TEST env var during tests and silenced parserun during tests
Guillaume J. Charmes 12 years ago
parent
commit
df8f95ac74
3 changed files with 6 additions and 4 deletions
  1. 1 1
      container.go
  2. 3 3
      runtime.go
  3. 2 0
      runtime_test.go

+ 1 - 1
container.go

@@ -107,7 +107,7 @@ type KeyValuePair struct {
 
 func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig, *flag.FlagSet, error) {
 	cmd := Subcmd("run", "[OPTIONS] IMAGE [COMMAND] [ARG...]", "Run a command in a new container")
-	if len(args) > 0 && args[0] != "--help" {
+	if os.Getenv("TEST") != "" {
 		cmd.SetOutput(ioutil.Discard)
 		cmd.Usage = nil
 	}

+ 3 - 3
runtime.go

@@ -208,7 +208,7 @@ func (runtime *Runtime) Destroy(container *Container) error {
 
 func (runtime *Runtime) restore() error {
 	wheel := "-\\|/"
-	if os.Getenv("DEBUG") == "" {
+	if os.Getenv("DEBUG") == "" && os.Getenv("TEST") == "" {
 		fmt.Printf("Loading containers:  ")
 	}
 	dir, err := ioutil.ReadDir(runtime.repository)
@@ -218,7 +218,7 @@ func (runtime *Runtime) restore() error {
 	for i, v := range dir {
 		id := v.Name()
 		container, err := runtime.Load(id)
-		if i%21 == 0 && os.Getenv("DEBUG") == "" {
+		if i%21 == 0 && os.Getenv("DEBUG") == "" && os.Getenv("TEST") == "" {
 			fmt.Printf("\b%c", wheel[i%4])
 		}
 		if err != nil {
@@ -227,7 +227,7 @@ func (runtime *Runtime) restore() error {
 		}
 		utils.Debugf("Loaded container %v", container.ID)
 	}
-	if os.Getenv("DEBUG") == "" {
+	if os.Getenv("DEBUG") == "" && os.Getenv("TEST") == "" {
 		fmt.Printf("\bdone.\n")
 	}
 	return nil

+ 2 - 0
runtime_test.go

@@ -72,6 +72,8 @@ func layerArchive(tarfile string) (io.Reader, error) {
 }
 
 func init() {
+	os.Setenv("TEST", "1")
+
 	// Hack to run sys init during unit testing
 	if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || selfPath == "/.dockerinit" {
 		SysInit()