Browse code

TestMaskSecretKeys: use subtests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 32d70c7e21631224674cd60021d3ec908c2d888c)
Signed-off-by: Tibor Vass <tibor@docker.com>

Sebastiaan van Stijn authored on 2019/07/02 20:29:24
Showing 1 changed files
... ...
@@ -9,26 +9,31 @@ import (
9 9
 
10 10
 func TestMaskSecretKeys(t *testing.T) {
11 11
 	tests := []struct {
12
+		doc      string
12 13
 		path     string
13 14
 		input    map[string]interface{}
14 15
 		expected map[string]interface{}
15 16
 	}{
16 17
 		{
18
+			doc:      "secret create with API version",
17 19
 			path:     "/v1.30/secrets/create",
18 20
 			input:    map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}},
19 21
 			expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}},
20 22
 		},
21 23
 		{
24
+			doc:      "secret create with API version and trailing slashes",
22 25
 			path:     "/v1.30/secrets/create//",
23 26
 			input:    map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}},
24 27
 			expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}},
25 28
 		},
26 29
 		{
30
+			doc:      "secret create with query param",
27 31
 			path:     "/secrets/create?key=val",
28 32
 			input:    map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}},
29 33
 			expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}},
30 34
 		},
31 35
 		{
36
+			doc:  "other paths with API version",
32 37
 			path: "/v1.30/some/other/path",
33 38
 			input: map[string]interface{}{
34 39
 				"password":     "pass",
... ...
@@ -60,6 +65,7 @@ func TestMaskSecretKeys(t *testing.T) {
60 60
 			},
61 61
 		},
62 62
 		{
63
+			doc:  "other paths with API version case insensitive",
63 64
 			path: "/v1.30/some/other/path",
64 65
 			input: map[string]interface{}{
65 66
 				"PASSWORD": "pass",
... ...
@@ -77,7 +83,9 @@ func TestMaskSecretKeys(t *testing.T) {
77 77
 	}
78 78
 
79 79
 	for _, testcase := range tests {
80
-		maskSecretKeys(testcase.input, testcase.path)
81
-		assert.Check(t, is.DeepEqual(testcase.expected, testcase.input))
80
+		t.Run(testcase.doc, func(t *testing.T) {
81
+			maskSecretKeys(testcase.input, testcase.path)
82
+			assert.Check(t, is.DeepEqual(testcase.expected, testcase.input))
83
+		})
82 84
 	}
83 85
 }