Browse code

Merge pull request #38544 from thaJeztah/dont_sprintf

testing: pkg/signal; remove redundant fmt.Sprintf()

Vincent Demeester authored on 2019/01/15 23:28:07
Showing 1 changed files
... ...
@@ -3,7 +3,6 @@
3 3
 package signal // import "github.com/docker/docker/pkg/signal"
4 4
 
5 5
 import (
6
-	"fmt"
7 6
 	"io/ioutil"
8 7
 	"os"
9 8
 	"os/exec"
... ...
@@ -15,6 +14,7 @@ import (
15 15
 )
16 16
 
17 17
 func buildTestBinary(t *testing.T, tmpdir string, prefix string) (string, string) {
18
+	t.Helper()
18 19
 	tmpDir, err := ioutil.TempDir(tmpdir, prefix)
19 20
 	assert.NilError(t, err)
20 21
 	exePath := tmpDir + "/" + prefix
... ...
@@ -42,24 +42,25 @@ func TestTrap(t *testing.T) {
42 42
 	defer os.RemoveAll(tmpDir)
43 43
 
44 44
 	for _, v := range sigmap {
45
-		cmd := exec.Command(exePath)
46
-		cmd.Env = append(os.Environ(), fmt.Sprintf("SIGNAL_TYPE=%s", v.name))
47
-		if v.multiple {
48
-			cmd.Env = append(cmd.Env, "IF_MULTIPLE=1")
49
-		}
50
-		err := cmd.Start()
51
-		assert.NilError(t, err)
52
-		err = cmd.Wait()
53
-		if e, ok := err.(*exec.ExitError); ok {
45
+		t.Run(v.name, func(t *testing.T) {
46
+			cmd := exec.Command(exePath)
47
+			cmd.Env = append(os.Environ(), "SIGNAL_TYPE="+v.name)
48
+			if v.multiple {
49
+				cmd.Env = append(cmd.Env, "IF_MULTIPLE=1")
50
+			}
51
+			err := cmd.Start()
52
+			assert.NilError(t, err)
53
+			err = cmd.Wait()
54
+			e, ok := err.(*exec.ExitError)
55
+			assert.Assert(t, ok, "expected exec.ExitError, got %T", e)
56
+
54 57
 			code := e.Sys().(syscall.WaitStatus).ExitStatus()
55 58
 			if v.multiple {
56 59
 				assert.Check(t, is.DeepEqual(128+int(v.signal.(syscall.Signal)), code))
57 60
 			} else {
58 61
 				assert.Check(t, is.Equal(99, code))
59 62
 			}
60
-			continue
61
-		}
62
-		t.Fatal("process didn't end with any error")
63
+		})
63 64
 	}
64 65
 
65 66
 }