Merge pull request #1591 from dotcloud/1557_fix_docker_run_useage

add TEST env var during tests and silenced parserun during tests
This commit is contained in:
Guillaume J. Charmes 2013-08-29 16:51:34 -07:00
commit df8f95ac74
3 changed files with 6 additions and 4 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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()