]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
tests: use subtests
authorSimon Ruderich <simon@ruderich.org>
Mon, 5 Apr 2021 08:36:02 +0000 (10:36 +0200)
committerSimon Ruderich <simon@ruderich.org>
Mon, 5 Apr 2021 08:36:02 +0000 (10:36 +0200)
This removes the need to print the name of the test in each t.Errorf()
call which reduces unnecessary code. It also permits skipping tests
which will be used in the future.

18 files changed:
cmd/safcm-remote/ainsl/ainsl_test.go
cmd/safcm-remote/sync/commands_test.go
cmd/safcm-remote/sync/files_test.go
cmd/safcm-remote/sync/packages_debian_test.go
cmd/safcm-remote/sync/services_systemd_test.go
cmd/safcm-remote/sync/sync_test.go
cmd/safcm-remote/sync/triggers_test.go
cmd/safcm/config/files_test.go
cmd/safcm/config/groups_test.go
cmd/safcm/config/hosts_test.go
cmd/safcm/config/permissions_test.go
cmd/safcm/config/templates_test.go
cmd/safcm/config/triggers_test.go
cmd/safcm/sync_changes_test.go
cmd/safcm/sync_info_test.go
cmd/safcm/sync_sync_test.go
cmd/safcm/sync_test.go
cmd/safcm/term_test.go

index 25258ff0aeb65cb98acaff6b5512aebb807904db..e4d6b46ddebeecb8cd0906f9c0c6052b55acdcd2 100644 (file)
@@ -293,6 +293,7 @@ func TestHandle(t *testing.T) {
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                // Create separate test directory for each test case
                path := filepath.Join(cwd, "testdata", tc.name)
                err = os.Mkdir(path, 0700)
@@ -310,13 +311,13 @@ func TestHandle(t *testing.T) {
 
                changes, err := handle(tc.path, tc.line, tc.create)
                if !reflect.DeepEqual(tc.expChanges, changes) {
-                       t.Errorf("%s: changes: %s", tc.name,
+                       t.Errorf("changes: %s",
                                cmp.Diff(tc.expChanges, changes))
                }
                // Ugly but the simplest way to compare errors (including nil)
                if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) {
-                       t.Errorf("%s: err = %#v, want %#v",
-                               tc.name, err, tc.expErr)
+                       t.Errorf("err = %#v, want %#v",
+                               err, tc.expErr)
                }
 
                files, err := ft.WalkDir(path)
@@ -324,9 +325,10 @@ func TestHandle(t *testing.T) {
                        t.Fatal(err)
                }
                if !reflect.DeepEqual(tc.expFiles, files) {
-                       t.Errorf("%s: files: %s", tc.name,
+                       t.Errorf("files: %s",
                                cmp.Diff(tc.expFiles, files))
                }
+               })
        }
 
        if !t.Failed() {
index 1b1adf71768dc0b8027c8bb0bd7edfd7c2e30156..eb0cc0ba050df313cdd29d59155792fdbb079f13 100644 (file)
@@ -497,9 +497,9 @@ func TestSyncCommands(t *testing.T) {
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                s, res := prepareSync(tc.req, &testRunner{
                        t:         t,
-                       name:      tc.name,
                        expCmds:   tc.expCmds,
                        resStdout: tc.stdout,
                        resStderr: tc.stderr,
@@ -510,18 +510,19 @@ func TestSyncCommands(t *testing.T) {
                err := s.syncCommands()
                // Ugly but the simplest way to compare errors (including nil)
                if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) {
-                       t.Errorf("%s: err = %#v, want %#v",
-                               tc.name, err, tc.expErr)
+                       t.Errorf("err = %#v, want %#v",
+                               err, tc.expErr)
                }
                dbg := res.Wait()
 
                if !reflect.DeepEqual(tc.expResp, s.resp) {
-                       t.Errorf("%s: resp: %s", tc.name,
+                       t.Errorf("resp: %s",
                                cmp.Diff(tc.expResp, s.resp))
                }
                if !reflect.DeepEqual(tc.expDbg, dbg) {
-                       t.Errorf("%s: dbg: %s", tc.name,
+                       t.Errorf("dbg: %s",
                                cmp.Diff(tc.expDbg, dbg))
                }
+               })
        }
 }
index c5c7216f81228debd074aa72a558ce97e64a9394..32130e928abbad99c77ed139fbc48373c28c1f32 100644 (file)
@@ -841,6 +841,7 @@ func TestSyncFiles(t *testing.T) {
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                // Create separate test directory for each test case
                path := filepath.Join(cwd, "testdata", "files-"+tc.name)
                err = os.Mkdir(path, 0700)
@@ -858,15 +859,14 @@ func TestSyncFiles(t *testing.T) {
 
                s, res := prepareSync(tc.req, &testRunner{
                        t:    t,
-                       name: tc.name,
                })
                s.setDefaults()
 
                err := s.syncFiles()
                // Ugly but the simplest way to compare errors (including nil)
                if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) {
-                       t.Errorf("%s: err = %#v, want %#v",
-                               tc.name, err, tc.expErr)
+                       t.Errorf("err = %#v, want %#v",
+                               err, tc.expErr)
                }
                dbg := res.Wait()
                // Remove random file names from result
@@ -874,7 +874,7 @@ func TestSyncFiles(t *testing.T) {
                        dbg[i] = randFilesRegexp.ReplaceAllString(x, `RND"`)
                }
                if !reflect.DeepEqual(tc.expDbg, dbg) {
-                       t.Errorf("%s: dbg: %s", tc.name,
+                       t.Errorf("dbg: %s",
                                cmp.Diff(tc.expDbg, dbg))
                }
 
@@ -883,18 +883,19 @@ func TestSyncFiles(t *testing.T) {
                        t.Fatal(err)
                }
                if !reflect.DeepEqual(tc.expFiles, files) {
-                       t.Errorf("%s: files: %s", tc.name,
+                       t.Errorf("files: %s",
                                cmp.Diff(tc.expFiles, files))
                }
 
                if !reflect.DeepEqual(tc.expResp, s.resp) {
-                       t.Errorf("%s: resp: %s", tc.name,
+                       t.Errorf("resp: %s",
                                cmp.Diff(tc.expResp, s.resp))
                }
                if !reflect.DeepEqual(tc.triggers, s.triggers) {
-                       t.Errorf("%s: triggers: %s", tc.name,
+                       t.Errorf("triggers: %s",
                                cmp.Diff(tc.triggers, s.triggers))
                }
+               })
        }
 
        os.Remove(tmpTestFilePath)
@@ -2395,6 +2396,7 @@ file
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                // Create separate test directory for each test case
                path := filepath.Join(cwd, "testdata", "file-"+tc.name)
                err = os.Mkdir(path, 0700)
@@ -2412,7 +2414,6 @@ file
 
                s, res := prepareSync(tc.req, &testRunner{
                        t:    t,
-                       name: tc.name,
                })
                s.setDefaults()
 
@@ -2423,8 +2424,8 @@ file
                err := s.syncFile(tc.file, &changed)
                // Ugly but the simplest way to compare errors (including nil)
                if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) {
-                       t.Errorf("%s: err = %#v, want %#v",
-                               tc.name, err, tc.expErr)
+                       t.Errorf("err = %#v, want %#v",
+                               err, tc.expErr)
                }
                dbg := res.Wait()
                // Remove random file names from result
@@ -2432,7 +2433,7 @@ file
                        dbg[i] = randFilesRegexp.ReplaceAllString(x, `RND"`)
                }
                if !reflect.DeepEqual(tc.expDbg, dbg) {
-                       t.Errorf("%s: dbg: %s", tc.name,
+                       t.Errorf("dbg: %s",
                                cmp.Diff(tc.expDbg, dbg))
                }
 
@@ -2441,18 +2442,19 @@ file
                        t.Fatal(err)
                }
                if !reflect.DeepEqual(tc.expFiles, files) {
-                       t.Errorf("%s: files: %s", tc.name,
+                       t.Errorf("files: %s",
                                cmp.Diff(tc.expFiles, files))
                }
 
                if tc.expChanged != changed {
-                       t.Errorf("%s: changed = %#v, want %#v",
-                               tc.name, changed, tc.expChanged)
+                       t.Errorf("changed = %#v, want %#v",
+                               changed, tc.expChanged)
                }
                if !reflect.DeepEqual(tc.expResp, s.resp) {
-                       t.Errorf("%s: resp: %s", tc.name,
+                       t.Errorf("resp: %s",
                                cmp.Diff(tc.expResp, s.resp))
                }
+               })
        }
 
        if !t.Failed() {
index f67dda9484bd5e4a5821138a7e1e4dc0014fb11a..51b6b746865da76bee636a81e7717a9d1ca9b995 100644 (file)
@@ -300,9 +300,9 @@ install ok installed        golang-1.16-src
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                s, res := prepareSync(tc.req, &testRunner{
                        t:         t,
-                       name:      tc.name,
                        expCmds:   tc.expCmds,
                        resStdout: tc.stdout,
                        resStderr: tc.stderr,
@@ -312,18 +312,19 @@ install ok installed      golang-1.16-src
                err := s.syncPackagesDebian()
                // Ugly but the simplest way to compare errors (including nil)
                if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) {
-                       t.Errorf("%s: err = %#v, want %#v",
-                               tc.name, err, tc.expErr)
+                       t.Errorf("err = %#v, want %#v",
+                               err, tc.expErr)
                }
                dbg := res.Wait()
 
                if !reflect.DeepEqual(tc.expResp, s.resp) {
-                       t.Errorf("%s: resp: %s", tc.name,
+                       t.Errorf("resp: %s",
                                cmp.Diff(tc.expResp, s.resp))
                }
                if !reflect.DeepEqual(tc.expDbg, dbg) {
-                       t.Errorf("%s: dbg: %s", tc.name,
+                       t.Errorf("dbg: %s",
                                cmp.Diff(tc.expDbg, dbg))
                }
+               })
        }
 }
index 8ba0bfabed44a66e0f4ce787ce658b10b5d2649a..df226fc85e00fae40dc06834e25deae3a1bce5e5 100644 (file)
@@ -507,9 +507,9 @@ LoadError=
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                s, res := prepareSync(tc.req, &testRunner{
                        t:         t,
-                       name:      tc.name,
                        expCmds:   tc.expCmds,
                        resStdout: tc.stdout,
                        resStderr: tc.stderr,
@@ -519,18 +519,19 @@ LoadError=
                err := s.syncServicesSystemd()
                // Ugly but the simplest way to compare errors (including nil)
                if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) {
-                       t.Errorf("%s: err = %#v, want %#v",
-                               tc.name, err, tc.expErr)
+                       t.Errorf("err = %#v, want %#v",
+                               err, tc.expErr)
                }
                dbg := res.Wait()
 
                if !reflect.DeepEqual(tc.expResp, s.resp) {
-                       t.Errorf("%s: resp: %s", tc.name,
+                       t.Errorf("resp: %s",
                                cmp.Diff(tc.expResp, s.resp))
                }
                if !reflect.DeepEqual(tc.expDbg, dbg) {
-                       t.Errorf("%s: dbg: %s", tc.name,
+                       t.Errorf("dbg: %s",
                                cmp.Diff(tc.expDbg, dbg))
                }
+               })
        }
 }
index 44e2be29f3e87918767c8fd22b14906805351394..4c0f08d5abdf6515f4da8df503b2088fd71d355d 100644 (file)
@@ -33,7 +33,6 @@ import (
 
 type testRunner struct {
        t         *testing.T
-       name      string
        expCmds   []*exec.Cmd
        resStdout [][]byte
        resStderr [][]byte
@@ -56,8 +55,7 @@ func (r *testRunner) CombinedOutput(cmd *exec.Cmd) ([]byte, error) {
        stdout, stderr, err := r.check("combinedOutput", cmd)
        if stderr != nil {
                // stdout also contains stderr
-               r.t.Fatalf("%s: CombinedOutput: stderr != nil, but %v",
-                       r.name, stderr)
+               r.t.Fatalf("CombinedOutput: stderr != nil, but %v", stderr)
        }
        return stdout, err
 }
@@ -65,22 +63,22 @@ func (r *testRunner) check(method string, cmd *exec.Cmd) (
        []byte, []byte, error) {
 
        if len(r.expCmds) == 0 {
-               r.t.Fatalf("%s: %s: empty expCmds", r.name, method)
+               r.t.Fatalf("%s: empty expCmds", method)
        }
        if len(r.resStdout) == 0 {
-               r.t.Fatalf("%s: %s: empty resStdout", r.name, method)
+               r.t.Fatalf("%s: empty resStdout", method)
        }
        if len(r.resStderr) == 0 {
-               r.t.Fatalf("%s: %s: empty resStderr", r.name, method)
+               r.t.Fatalf("%s: empty resStderr", method)
        }
        if len(r.resError) == 0 {
-               r.t.Fatalf("%s: %s: empty resError", r.name, method)
+               r.t.Fatalf("%s: empty resError", method)
        }
 
        exp := r.expCmds[0]
        r.expCmds = r.expCmds[1:]
        if !reflect.DeepEqual(exp, cmd) {
-               r.t.Errorf("%s: %s: %s", r.name, method,
+               r.t.Errorf("%s: %s", method,
                        cmp.Diff(exp, cmd, cmpopts.IgnoreUnexported(
                                exec.Cmd{},
                                bytes.Buffer{})))
@@ -140,20 +138,16 @@ func (s *syncTestResult) Wait() []string {
 
        // All expected commands must have been executed
        if len(s.runner.expCmds) != 0 {
-               s.runner.t.Errorf("%s: expCmds left: %v",
-                       s.runner.name, s.runner.expCmds)
+               s.runner.t.Errorf("expCmds left: %v", s.runner.expCmds)
        }
        if len(s.runner.resStdout) != 0 {
-               s.runner.t.Errorf("%s: resStdout left: %v",
-                       s.runner.name, s.runner.resStdout)
+               s.runner.t.Errorf("resStdout left: %v", s.runner.resStdout)
        }
        if len(s.runner.resStderr) != 0 {
-               s.runner.t.Errorf("%s: resStderr left: %v",
-                       s.runner.name, s.runner.resStderr)
+               s.runner.t.Errorf("resStderr left: %v", s.runner.resStderr)
        }
        if len(s.runner.resError) != 0 {
-               s.runner.t.Errorf("%s: resError left: %v",
-                       s.runner.name, s.runner.resError)
+               s.runner.t.Errorf("resError left: %v", s.runner.resError)
        }
 
        return s.dbg
index 27a0d022cf7ef6e1d2e3f32f900903c76655d789..cc418862c8f872c10be0943f312e4d28a1c14fd8 100644 (file)
@@ -55,10 +55,12 @@ func TestTriggerPaths(t *testing.T) {
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                res := triggerPaths(tc.path)
                if !reflect.DeepEqual(tc.exp, res) {
-                       t.Errorf("%s: res: %s", tc.name,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, res))
                }
+               })
        }
 }
index 398394c8f43d3fc0c28027500e4605db9f2625ee..ef31591fe8fdc31de081f4e3cfbe7a07fb6ef021 100644 (file)
@@ -188,16 +188,18 @@ This is FreeBSD host
        }
 
        for _, tc := range tests {
+               t.Run(tc.group, func(t *testing.T) {
                res, err := LoadFiles(tc.group)
 
                if !reflect.DeepEqual(tc.exp, res) {
-                       t.Errorf("%s: res: %s", tc.group,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, res))
                }
                // Ugly but the simplest way to compare errors (including nil)
                if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) {
-                       t.Errorf("%s: err = %#v, want %#v",
-                               tc.group, err, tc.expErr)
+                       t.Errorf("err = %#v, want %#v",
+                               err, tc.expErr)
                }
+               })
        }
 }
index ccf096897859dd775b71a86f72919d8c597d87dc..68f18bad3bc5ec3d6ff93fa9ec6010ec9951c073 100644 (file)
@@ -185,6 +185,7 @@ func TestLoadGroups(t *testing.T) {
        }
 
        for _, tc := range tests {
+               t.Run(tc.path, func(t *testing.T) {
                err := os.Chdir(tc.path)
                if err != nil {
                        t.Fatal(err)
@@ -193,19 +194,20 @@ func TestLoadGroups(t *testing.T) {
                res, err := LoadGroups(tc.cfg, tc.hosts)
 
                if !reflect.DeepEqual(tc.exp, res) {
-                       t.Errorf("%s: res: %s", tc.path,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, res))
                }
                // Ugly but the simplest way to compare errors (including nil)
                if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) {
-                       t.Errorf("%s: err = %#v, want %#v",
-                               tc.path, err, tc.expErr)
+                       t.Errorf("err = %#v, want %#v",
+                               err, tc.expErr)
                }
 
                err = os.Chdir(cwd)
                if err != nil {
                        t.Fatal(err)
                }
+               })
        }
 }
 
@@ -315,15 +317,17 @@ func TestResolveHostGroups(t *testing.T) {
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                res, err := ResolveHostGroups(tc.host, allGroups, tc.detected)
                if !reflect.DeepEqual(tc.exp, res) {
-                       t.Errorf("%s: res: %s", tc.name,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, res))
                }
                // Ugly but the simplest way to compare errors (including nil)
                if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) {
-                       t.Errorf("%s: err = %#v, want %#v",
-                               tc.name, err, tc.expErr)
+                       t.Errorf("err = %#v, want %#v",
+                               err, tc.expErr)
                }
+               })
        }
 }
index 49f4d5692da40bc96afeedc760fb53b84dfc0bad..36a8c37fd5db42127eb088ec7596d86540932849 100644 (file)
@@ -83,6 +83,7 @@ func TestLoadHosts(t *testing.T) {
        }
 
        for _, tc := range tests {
+               t.Run(tc.path, func(t *testing.T) {
                err := os.Chdir(filepath.Join(cwd, tc.path))
                if err != nil {
                        t.Fatal(err)
@@ -91,13 +92,14 @@ func TestLoadHosts(t *testing.T) {
                res, err := LoadHosts()
 
                if !reflect.DeepEqual(tc.exp, res) {
-                       t.Errorf("%s: res: %s", tc.path,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, res))
                }
                // Ugly but the simplest way to compare errors (including nil)
                if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) {
-                       t.Errorf("%s: err = %#v, want %#v",
-                               tc.path, err, tc.expErr)
+                       t.Errorf("err = %#v, want %#v",
+                               err, tc.expErr)
                }
+               })
        }
 }
index cec72a6c8f8106ad2db382b39db46a8e1549a62f..4efefafd2deb9af727d9b08894211ed41c3231f6 100644 (file)
@@ -226,23 +226,24 @@ This is FreeBSD host
        }
 
        for _, tc := range tests {
+               t.Run(tc.group, func(t *testing.T) {
                // Use LoadFiles() so we work on real data and don't make any
                // mistakes generating it
                files, err := LoadFiles(tc.group)
                if err != nil {
-                       t.Fatalf("%s: err = %#v, want nil",
-                               tc.group, err)
+                       t.Fatalf("err = %#v, want nil", err)
                }
                err = LoadPermissions(tc.group, files)
 
                if !reflect.DeepEqual(tc.exp, files) {
-                       t.Errorf("%s: res: %s", tc.group,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, files))
                }
                // Ugly but the simplest way to compare errors (including nil)
                if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) {
-                       t.Errorf("%s: err = %#v, want %#v",
-                               tc.group, err, tc.expErr)
+                       t.Errorf("err = %#v, want %#v",
+                               err, tc.expErr)
                }
+               })
        }
 }
index 6a0182c3be153910f21ef302e4d40f3932e21d41..bd65c0976e8fe6e41e46858e289e344d3a406ef7 100644 (file)
@@ -242,24 +242,25 @@ This is GNU/Linux host
        }
 
        for _, tc := range tests {
+               t.Run(tc.group, func(t *testing.T) {
                // Use LoadFiles() so we work on real data and don't make any
                // mistakes generating it
                files, err := LoadFiles(tc.group)
                if err != nil {
-                       t.Fatalf("%s: err = %#v, want nil",
-                               tc.group, err)
+                       t.Fatalf("err = %#v, want nil", err)
                }
                err = LoadTemplates(tc.group, files,
                        host, groups, allHosts, allGroups)
 
                if !reflect.DeepEqual(tc.exp, files) {
-                       t.Errorf("%s: res: %s", tc.group,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, files))
                }
                // Ugly but the simplest way to compare errors (including nil)
                if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) {
-                       t.Errorf("%s: err = %#v, want %#v",
-                               tc.group, err, tc.expErr)
+                       t.Errorf("err = %#v, want %#v",
+                               err, tc.expErr)
                }
+               })
        }
 }
index a27ec6a50902be9d55cfe94147e148540bdd39f5..96e52d7e7410d2f89707bdb1267ff8436bd5a006 100644 (file)
@@ -133,23 +133,24 @@ This is FreeBSD host
        }
 
        for _, tc := range tests {
+               t.Run(tc.group, func(t *testing.T) {
                // Use LoadFiles() so we work on real data and don't make any
                // mistakes generating it
                files, err := LoadFiles(tc.group)
                if err != nil {
-                       t.Fatalf("%s: err = %#v, want nil",
-                               tc.group, err)
+                       t.Fatalf("err = %#v, want nil", err)
                }
                err = LoadTriggers(tc.group, files)
 
                if !reflect.DeepEqual(tc.exp, files) {
-                       t.Errorf("%s: res: %s", tc.group,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, files))
                }
                // Ugly but the simplest way to compare errors (including nil)
                if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) {
-                       t.Errorf("%s: err = %#v, want %#v",
-                               tc.group, err, tc.expErr)
+                       t.Errorf("err = %#v, want %#v",
+                               err, tc.expErr)
                }
+               })
        }
 }
index f48d441208e5f0bd8dc134b0e42b0a036abe5a00..767564fd14221a2c37405349b9bc867a777cdaa0 100644 (file)
@@ -283,6 +283,7 @@ func TestFormatFileChanges(t *testing.T) {
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                s := &Sync{
                        config: &config.Config{
                                DryRun: tc.dryRun,
@@ -291,9 +292,10 @@ func TestFormatFileChanges(t *testing.T) {
 
                res := s.formatFileChanges(tc.changes)
                if tc.exp != res {
-                       t.Errorf("%s: res: %s", tc.name,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, res))
                }
+               })
        }
 }
 
@@ -354,6 +356,7 @@ func TestFormatPackageChanges(t *testing.T) {
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                s := &Sync{
                        config: &config.Config{
                                DryRun: tc.dryRun,
@@ -362,9 +365,10 @@ func TestFormatPackageChanges(t *testing.T) {
 
                res := s.formatPackageChanges(tc.changes)
                if tc.exp != res {
-                       t.Errorf("%s: res: %s", tc.name,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, res))
                }
+               })
        }
 }
 
@@ -447,6 +451,7 @@ func TestFormatServiceChanges(t *testing.T) {
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                s := &Sync{
                        config: &config.Config{
                                DryRun: tc.dryRun,
@@ -455,9 +460,10 @@ func TestFormatServiceChanges(t *testing.T) {
 
                res := s.formatServiceChanges(tc.changes)
                if tc.exp != res {
-                       t.Errorf("%s: res: %s", tc.name,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, res))
                }
+               })
        }
 }
 
@@ -657,6 +663,7 @@ func TestFormatCommandChanges(t *testing.T) {
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                s := &Sync{
                        config: &config.Config{
                                DryRun: tc.dryRun,
@@ -666,8 +673,9 @@ func TestFormatCommandChanges(t *testing.T) {
 
                res := s.formatCommandChanges(tc.changes)
                if tc.exp != res {
-                       t.Errorf("%s: res: %s", tc.name,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, res))
                }
+               })
        }
 }
index b883bb75c6e29552e227b1c3c297b8153796060b..f234d9b17b95b031d737b70008c49d77b3b425d4 100644 (file)
@@ -68,10 +68,12 @@ func TestHostInfoRespToGroups(t *testing.T) {
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                res := hostInfoRespToGroups(tc.resp)
                if !reflect.DeepEqual(tc.exp, res) {
-                       t.Errorf("%s: res: %s", tc.name,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, res))
                }
+               })
        }
 }
index f6aafd52445e6664f4958ab82703736a51e93982..65a490a298518963326cf3597fd720e4e82ddbc0 100644 (file)
@@ -419,6 +419,7 @@ func TestHostSyncReq(t *testing.T) {
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                err = os.Chdir(filepath.Join(cwd, "testdata", tc.project))
                if err != nil {
                        t.Fatal(err)
@@ -469,21 +470,21 @@ func TestHostSyncReq(t *testing.T) {
 
                res, err := s.hostSyncReq(tc.detected)
                if !reflect.DeepEqual(tc.exp, res) {
-                       t.Errorf("%s: res: %s", tc.name,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, res))
                }
                // Ugly but the simplest way to compare errors (including nil)
                if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) {
-                       t.Errorf("%s: err = %#v, want %#v",
-                               tc.name, err, tc.expErr)
+                       t.Errorf("err = %#v, want %#v",
+                               err, tc.expErr)
                }
 
                close(ch)
                <-done
                if !reflect.DeepEqual(tc.expEvents, events) {
-                       t.Errorf("%s: events: %s", tc.name,
+                       t.Errorf("events: %s",
                                cmp.Diff(tc.expEvents, events))
                }
-
+               })
        }
 }
index dba1d7e054bd7e4b8e99238b7d0692c6aa2ef8b4..753f942fe06706d123967df5d95df9a43ee7c2e7 100644 (file)
@@ -166,15 +166,17 @@ func TestHostsToSync(t *testing.T) {
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                res, err := hostsToSync(tc.names, allHosts, allGroups)
                if !reflect.DeepEqual(tc.exp, res) {
-                       t.Errorf("%s: res: %s", tc.name,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, res))
                }
                // Ugly but the simplest way to compare errors (including nil)
                if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) {
-                       t.Errorf("%s: err = %#v, want %#v",
-                               tc.name, err, tc.expErr)
+                       t.Errorf("err = %#v, want %#v",
+                               err, tc.expErr)
                }
+               })
        }
 }
index 63ad3c991aa3e4d17482273efee3b5659eb9cf79..f433eb589f8486059ca73fec2f6d6f57c9f73f08 100644 (file)
@@ -82,10 +82,12 @@ func TestEscapeControlCharacters(t *testing.T) {
        }
 
        for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
                res := EscapeControlCharacters(tc.isTTY, tc.x)
                if tc.exp != res {
-                       t.Errorf("%s: res: %s", tc.name,
+                       t.Errorf("res: %s",
                                cmp.Diff(tc.exp, res))
                }
+               })
        }
 }