From 5a86b8a999b5c4b4173e7fa891f239018136e9c8 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Sun, 1 Dec 2019 18:46:40 +0000
Subject: [PATCH] Fix the tests

The 'echo hi' test command has been replaced by 'sleep 1': previously
the container would exit so quickly that systemd-docker would fail to
detect its PID, thinking it didn't start at all.
---
 main_test.go | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/main_test.go b/main_test.go
index 414a560..bcbedf1 100644
--- a/main_test.go
+++ b/main_test.go
@@ -204,8 +204,8 @@ func TestBadExec(t *testing.T) {
 
 	if e, ok := err.(*exec.ExitError); ok {
 		if status, ok := e.Sys().(syscall.WaitStatus); ok {
-			if status.ExitStatus() != 2 {
-				log.Fatal("Expect 2 exit code got ", status.ExitStatus())
+			if status.ExitStatus() != 125 {
+				log.Fatal("Expect 125 exit code got ", status.ExitStatus())
 			}
 		}
 	} else {
@@ -215,7 +215,7 @@ func TestBadExec(t *testing.T) {
 
 func TestGoodExec(t *testing.T) {
 	c := &Context{
-		Args: []string{"-d", "busybox", "echo", "hi"},
+		Args: []string{"-d", "busybox", "sleep", "1"},
 	}
 
 	err := runContainer(c)
@@ -243,7 +243,7 @@ func TestParseCgroups(t *testing.T) {
 	if val, ok := cgroups["blkio"]; ok {
 		p := path.Join(SYSFS, "blkio", val)
 		if _, err := os.Stat(p); os.IsNotExist(err) {
-			log.Fatalf("Path does not exist %s", p, err)
+			log.Fatalf("Path does not exist %s", err)
 		}
 	} else {
 		log.Fatal("Failed to find blkio cgroup", val)
@@ -252,7 +252,7 @@ func TestParseCgroups(t *testing.T) {
 
 func TestMoveCgroup(t *testing.T) {
 	c := &Context{
-		Args: []string{"-d", "busybox", "echo", "hi"},
+		Args: []string{"-d", "busybox", "sleep", "1"},
 	}
 
 	err := runContainer(c)
@@ -277,7 +277,7 @@ func TestMoveCgroup(t *testing.T) {
 }
 
 func TestRemoveNoLogs(t *testing.T) {
-	c, err := mainWithArgs([]string{"--logs=false", "run", "-rm", "busybox", "echo", "hi"})
+	c, err := mainWithArgs([]string{"--logs=false", "run", "-rm", "busybox", "sleep", "1"})
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -294,7 +294,7 @@ func TestRemoveNoLogs(t *testing.T) {
 }
 
 func TestRemoveWithLogs(t *testing.T) {
-	c, err := mainWithArgs([]string{"--logs", "run", "-rm", "busybox", "echo", "hi"})
+	c, err := mainWithArgs([]string{"--logs", "run", "-rm", "busybox", "sleep", "1"})
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -338,7 +338,7 @@ func TestNamedContainerNoRm(t *testing.T) {
 
 	deleteTestContainer(t)
 
-	c, err := mainWithArgs([]string{"--logs", "run", "--privileged=true", "--name", "systemd-docker-test", "--privileged=true", "busybox", "echo", "hi"})
+	_, err = mainWithArgs([]string{"--logs", "run", "--privileged=true", "--name", "systemd-docker-test", "--privileged=true", "busybox", "sleep", "1"})
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -352,7 +352,7 @@ func TestNamedContainerNoRm(t *testing.T) {
 		t.Fatal("Should not be running")
 	}
 
-	c, err = mainWithArgs([]string{"--logs", "run", "--privileged=true", "--name", "systemd-docker-test", "busybox", "echo", "hi"})
+	c, err := mainWithArgs([]string{"--logs", "run", "--privileged=true", "--name", "systemd-docker-test", "busybox", "sleep", "1"})
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -370,9 +370,9 @@ func TestNamedContainerNoRm(t *testing.T) {
 		t.Fatal("Should be the same container", container.ID, container2.ID)
 	}
 
-        if !container2.HostConfig.Privileged {
-                t.Fatal("Container2 is not privileged")
-        }
+	if !container2.HostConfig.Privileged {
+		t.Fatal("Container2 is not privileged")
+	}
 
 	deleteTestContainer(t)
 }
@@ -385,7 +385,7 @@ func TestNamedContainerRmPrevious(t *testing.T) {
 
 	deleteTestContainer(t)
 
-	c, err := mainWithArgs([]string{"--logs", "run", "--name", "systemd-docker-test", "busybox", "echo", "hi"})
+	c, err := mainWithArgs([]string{"--logs", "run", "--name", "systemd-docker-test", "busybox", "sleep", "1"})
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -399,7 +399,7 @@ func TestNamedContainerRmPrevious(t *testing.T) {
 		t.Fatal("Should not be running")
 	}
 
-	c, err = mainWithArgs([]string{"--logs", "run", "--rm", "--name", "systemd-docker-test", "busybox", "echo", "hi"})
+	c, err = mainWithArgs([]string{"--logs", "run", "--rm", "--name", "systemd-docker-test", "busybox", "sleep", "1"})
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -438,7 +438,7 @@ func TestNamedContainerAttach(t *testing.T) {
 		t.Fatal("Should be running")
 	}
 
-	c, err = mainWithArgs([]string{"--logs=false", "run", "--name", "systemd-docker-test", "busybox", "echo", "hi"})
+	c, err = mainWithArgs([]string{"--logs=false", "run", "--name", "systemd-docker-test", "busybox", "sleep", "1"})
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -474,7 +474,7 @@ func TestPidFile(t *testing.T) {
 
 	os.Remove(pidFileName)
 
-	c, err := mainWithArgs([]string{"--logs=false", "--pid-file", "./pid-file", "run", "--rm", "busybox", "echo", "hi"})
+	c, err := mainWithArgs([]string{"--logs=false", "--pid-file", "./pid-file", "run", "--rm", "busybox", "sleep", "1"})
 	if err != nil {
 		t.Fatal(err)
 	}
-- 
GitLab