]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
tests: go fmt and rewrap
authorSimon Ruderich <simon@ruderich.org>
Mon, 5 Apr 2021 08:44:52 +0000 (10:44 +0200)
committerSimon Ruderich <simon@ruderich.org>
Mon, 5 Apr 2021 08:44:52 +0000 (10:44 +0200)
17 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/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 e4d6b46ddebeecb8cd0906f9c0c6052b55acdcd2..564bc37d99fde46e81ebbe305d27ee838d59b5f1 100644 (file)
@@ -294,40 +294,40 @@ 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)
-               if err != nil {
-                       t.Fatal(err)
-               }
-               err = os.Chdir(path)
-               if err != nil {
-                       t.Fatal(err)
-               }
+                       // Create separate test directory for each test case
+                       path := filepath.Join(cwd, "testdata", tc.name)
+                       err = os.Mkdir(path, 0700)
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+                       err = os.Chdir(path)
+                       if err != nil {
+                               t.Fatal(err)
+                       }
 
-               if tc.prepare != nil {
-                       tc.prepare()
-               }
+                       if tc.prepare != nil {
+                               tc.prepare()
+                       }
 
-               changes, err := handle(tc.path, tc.line, tc.create)
-               if !reflect.DeepEqual(tc.expChanges, changes) {
-                       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("err = %#v, want %#v",
-                               err, tc.expErr)
-               }
+                       changes, err := handle(tc.path, tc.line, tc.create)
+                       if !reflect.DeepEqual(tc.expChanges, changes) {
+                               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("err = %#v, want %#v",
+                                       err, tc.expErr)
+                       }
 
-               files, err := ft.WalkDir(path)
-               if err != nil {
-                       t.Fatal(err)
-               }
-               if !reflect.DeepEqual(tc.expFiles, files) {
-                       t.Errorf("files: %s",
-                               cmp.Diff(tc.expFiles, files))
-               }
+                       files, err := ft.WalkDir(path)
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+                       if !reflect.DeepEqual(tc.expFiles, files) {
+                               t.Errorf("files: %s",
+                                       cmp.Diff(tc.expFiles, files))
+                       }
                })
        }
 
index eb0cc0ba050df313cdd29d59155792fdbb079f13..3c47c1757c6adf5f199dc4342a692127da263e03 100644 (file)
@@ -498,31 +498,31 @@ 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,
-                       expCmds:   tc.expCmds,
-                       resStdout: tc.stdout,
-                       resStderr: tc.stderr,
-                       resError:  tc.errors,
-               })
-               s.triggers = tc.triggers
+                       s, res := prepareSync(tc.req, &testRunner{
+                               t:         t,
+                               expCmds:   tc.expCmds,
+                               resStdout: tc.stdout,
+                               resStderr: tc.stderr,
+                               resError:  tc.errors,
+                       })
+                       s.triggers = tc.triggers
 
-               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("err = %#v, want %#v",
-                               err, tc.expErr)
-               }
-               dbg := res.Wait()
+                       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("err = %#v, want %#v",
+                                       err, tc.expErr)
+                       }
+                       dbg := res.Wait()
 
-               if !reflect.DeepEqual(tc.expResp, s.resp) {
-                       t.Errorf("resp: %s",
-                               cmp.Diff(tc.expResp, s.resp))
-               }
-               if !reflect.DeepEqual(tc.expDbg, dbg) {
-                       t.Errorf("dbg: %s",
-                               cmp.Diff(tc.expDbg, dbg))
-               }
+                       if !reflect.DeepEqual(tc.expResp, s.resp) {
+                               t.Errorf("resp: %s",
+                                       cmp.Diff(tc.expResp, s.resp))
+                       }
+                       if !reflect.DeepEqual(tc.expDbg, dbg) {
+                               t.Errorf("dbg: %s",
+                                       cmp.Diff(tc.expDbg, dbg))
+                       }
                })
        }
 }
index 32130e928abbad99c77ed139fbc48373c28c1f32..e57401e3ada3c13b5d3e0edca9b37f06ab19d306 100644 (file)
@@ -842,59 +842,59 @@ 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)
-               if err != nil {
-                       t.Fatal(err)
-               }
-               err = os.Chdir(path)
-               if err != nil {
-                       t.Fatal(err)
-               }
-
-               if tc.prepare != nil {
-                       tc.prepare()
-               }
-
-               s, res := prepareSync(tc.req, &testRunner{
-                       t:    t,
-               })
-               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("err = %#v, want %#v",
-                               err, tc.expErr)
-               }
-               dbg := res.Wait()
-               // Remove random file names from result
-               for i, x := range dbg {
-                       dbg[i] = randFilesRegexp.ReplaceAllString(x, `RND"`)
-               }
-               if !reflect.DeepEqual(tc.expDbg, dbg) {
-                       t.Errorf("dbg: %s",
-                               cmp.Diff(tc.expDbg, dbg))
-               }
-
-               files, err := ft.WalkDir(path)
-               if err != nil {
-                       t.Fatal(err)
-               }
-               if !reflect.DeepEqual(tc.expFiles, files) {
-                       t.Errorf("files: %s",
-                               cmp.Diff(tc.expFiles, files))
-               }
-
-               if !reflect.DeepEqual(tc.expResp, s.resp) {
-                       t.Errorf("resp: %s",
-                               cmp.Diff(tc.expResp, s.resp))
-               }
-               if !reflect.DeepEqual(tc.triggers, s.triggers) {
-                       t.Errorf("triggers: %s",
-                               cmp.Diff(tc.triggers, s.triggers))
-               }
+                       // Create separate test directory for each test case
+                       path := filepath.Join(cwd, "testdata", "files-"+tc.name)
+                       err = os.Mkdir(path, 0700)
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+                       err = os.Chdir(path)
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+
+                       if tc.prepare != nil {
+                               tc.prepare()
+                       }
+
+                       s, res := prepareSync(tc.req, &testRunner{
+                               t: t,
+                       })
+                       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("err = %#v, want %#v",
+                                       err, tc.expErr)
+                       }
+                       dbg := res.Wait()
+                       // Remove random file names from result
+                       for i, x := range dbg {
+                               dbg[i] = randFilesRegexp.ReplaceAllString(x, `RND"`)
+                       }
+                       if !reflect.DeepEqual(tc.expDbg, dbg) {
+                               t.Errorf("dbg: %s",
+                                       cmp.Diff(tc.expDbg, dbg))
+                       }
+
+                       files, err := ft.WalkDir(path)
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+                       if !reflect.DeepEqual(tc.expFiles, files) {
+                               t.Errorf("files: %s",
+                                       cmp.Diff(tc.expFiles, files))
+                       }
+
+                       if !reflect.DeepEqual(tc.expResp, s.resp) {
+                               t.Errorf("resp: %s",
+                                       cmp.Diff(tc.expResp, s.resp))
+                       }
+                       if !reflect.DeepEqual(tc.triggers, s.triggers) {
+                               t.Errorf("triggers: %s",
+                                       cmp.Diff(tc.triggers, s.triggers))
+                       }
                })
        }
 
@@ -2397,63 +2397,63 @@ 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)
-               if err != nil {
-                       t.Fatal(err)
-               }
-               err = os.Chdir(path)
-               if err != nil {
-                       t.Fatal(err)
-               }
-
-               if tc.prepare != nil {
-                       tc.prepare()
-               }
-
-               s, res := prepareSync(tc.req, &testRunner{
-                       t:    t,
-               })
-               s.setDefaults()
-
-               // Deterministic temporary symlink names
-               rand.Seed(0)
-
-               var changed bool
-               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("err = %#v, want %#v",
-                               err, tc.expErr)
-               }
-               dbg := res.Wait()
-               // Remove random file names from result
-               for i, x := range dbg {
-                       dbg[i] = randFilesRegexp.ReplaceAllString(x, `RND"`)
-               }
-               if !reflect.DeepEqual(tc.expDbg, dbg) {
-                       t.Errorf("dbg: %s",
-                               cmp.Diff(tc.expDbg, dbg))
-               }
-
-               files, err := ft.WalkDir(path)
-               if err != nil {
-                       t.Fatal(err)
-               }
-               if !reflect.DeepEqual(tc.expFiles, files) {
-                       t.Errorf("files: %s",
-                               cmp.Diff(tc.expFiles, files))
-               }
-
-               if tc.expChanged != changed {
-                       t.Errorf("changed = %#v, want %#v",
-                               changed, tc.expChanged)
-               }
-               if !reflect.DeepEqual(tc.expResp, s.resp) {
-                       t.Errorf("resp: %s",
-                               cmp.Diff(tc.expResp, s.resp))
-               }
+                       // Create separate test directory for each test case
+                       path := filepath.Join(cwd, "testdata", "file-"+tc.name)
+                       err = os.Mkdir(path, 0700)
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+                       err = os.Chdir(path)
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+
+                       if tc.prepare != nil {
+                               tc.prepare()
+                       }
+
+                       s, res := prepareSync(tc.req, &testRunner{
+                               t: t,
+                       })
+                       s.setDefaults()
+
+                       // Deterministic temporary symlink names
+                       rand.Seed(0)
+
+                       var changed bool
+                       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("err = %#v, want %#v",
+                                       err, tc.expErr)
+                       }
+                       dbg := res.Wait()
+                       // Remove random file names from result
+                       for i, x := range dbg {
+                               dbg[i] = randFilesRegexp.ReplaceAllString(x, `RND"`)
+                       }
+                       if !reflect.DeepEqual(tc.expDbg, dbg) {
+                               t.Errorf("dbg: %s",
+                                       cmp.Diff(tc.expDbg, dbg))
+                       }
+
+                       files, err := ft.WalkDir(path)
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+                       if !reflect.DeepEqual(tc.expFiles, files) {
+                               t.Errorf("files: %s",
+                                       cmp.Diff(tc.expFiles, files))
+                       }
+
+                       if tc.expChanged != changed {
+                               t.Errorf("changed = %#v, want %#v",
+                                       changed, tc.expChanged)
+                       }
+                       if !reflect.DeepEqual(tc.expResp, s.resp) {
+                               t.Errorf("resp: %s",
+                                       cmp.Diff(tc.expResp, s.resp))
+                       }
                })
        }
 
index 51b6b746865da76bee636a81e7717a9d1ca9b995..ff0e066ae0d8e8ad806bdd4d1fbfe1d7521c6dc0 100644 (file)
@@ -301,30 +301,30 @@ 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,
-                       expCmds:   tc.expCmds,
-                       resStdout: tc.stdout,
-                       resStderr: tc.stderr,
-                       resError:  tc.errors,
-               })
+                       s, res := prepareSync(tc.req, &testRunner{
+                               t:         t,
+                               expCmds:   tc.expCmds,
+                               resStdout: tc.stdout,
+                               resStderr: tc.stderr,
+                               resError:  tc.errors,
+                       })
 
-               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("err = %#v, want %#v",
-                               err, tc.expErr)
-               }
-               dbg := res.Wait()
+                       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("err = %#v, want %#v",
+                                       err, tc.expErr)
+                       }
+                       dbg := res.Wait()
 
-               if !reflect.DeepEqual(tc.expResp, s.resp) {
-                       t.Errorf("resp: %s",
-                               cmp.Diff(tc.expResp, s.resp))
-               }
-               if !reflect.DeepEqual(tc.expDbg, dbg) {
-                       t.Errorf("dbg: %s",
-                               cmp.Diff(tc.expDbg, dbg))
-               }
+                       if !reflect.DeepEqual(tc.expResp, s.resp) {
+                               t.Errorf("resp: %s",
+                                       cmp.Diff(tc.expResp, s.resp))
+                       }
+                       if !reflect.DeepEqual(tc.expDbg, dbg) {
+                               t.Errorf("dbg: %s",
+                                       cmp.Diff(tc.expDbg, dbg))
+                       }
                })
        }
 }
index df226fc85e00fae40dc06834e25deae3a1bce5e5..40dd2e0c4644b32bcf357690ae1e1cee4de95f03 100644 (file)
@@ -508,30 +508,30 @@ LoadError=
 
        for _, tc := range tests {
                t.Run(tc.name, func(t *testing.T) {
-               s, res := prepareSync(tc.req, &testRunner{
-                       t:         t,
-                       expCmds:   tc.expCmds,
-                       resStdout: tc.stdout,
-                       resStderr: tc.stderr,
-                       resError:  tc.errors,
-               })
-
-               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("err = %#v, want %#v",
-                               err, tc.expErr)
-               }
-               dbg := res.Wait()
-
-               if !reflect.DeepEqual(tc.expResp, s.resp) {
-                       t.Errorf("resp: %s",
-                               cmp.Diff(tc.expResp, s.resp))
-               }
-               if !reflect.DeepEqual(tc.expDbg, dbg) {
-                       t.Errorf("dbg: %s",
-                               cmp.Diff(tc.expDbg, dbg))
-               }
+                       s, res := prepareSync(tc.req, &testRunner{
+                               t:         t,
+                               expCmds:   tc.expCmds,
+                               resStdout: tc.stdout,
+                               resStderr: tc.stderr,
+                               resError:  tc.errors,
+                       })
+
+                       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("err = %#v, want %#v",
+                                       err, tc.expErr)
+                       }
+                       dbg := res.Wait()
+
+                       if !reflect.DeepEqual(tc.expResp, s.resp) {
+                               t.Errorf("resp: %s",
+                                       cmp.Diff(tc.expResp, s.resp))
+                       }
+                       if !reflect.DeepEqual(tc.expDbg, dbg) {
+                               t.Errorf("dbg: %s",
+                                       cmp.Diff(tc.expDbg, dbg))
+                       }
                })
        }
 }
index cc418862c8f872c10be0943f312e4d28a1c14fd8..0b8bbe86f4adb1fbd1e34b76e98e11f39cf6ac3e 100644 (file)
@@ -56,11 +56,10 @@ 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("res: %s",
-                               cmp.Diff(tc.exp, res))
-               }
+                       res := triggerPaths(tc.path)
+                       if !reflect.DeepEqual(tc.exp, res) {
+                               t.Errorf("res: %s", cmp.Diff(tc.exp, res))
+                       }
                })
        }
 }
index ef31591fe8fdc31de081f4e3cfbe7a07fb6ef021..c9af0f23596f8fd08a8fa4c9526cc1984ff2240c 100644 (file)
@@ -189,17 +189,16 @@ 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("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("err = %#v, want %#v",
-                               err, tc.expErr)
-               }
+                       res, err := LoadFiles(tc.group)
+
+                       if !reflect.DeepEqual(tc.exp, res) {
+                               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("err = %#v, want %#v",
+                                       err, tc.expErr)
+                       }
                })
        }
 }
index 68f18bad3bc5ec3d6ff93fa9ec6010ec9951c073..b2bf5ec41d9027ecf39ebc6783dec321a936d885 100644 (file)
@@ -186,27 +186,26 @@ 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)
-               }
+                       err := os.Chdir(tc.path)
+                       if err != nil {
+                               t.Fatal(err)
+                       }
 
-               res, err := LoadGroups(tc.cfg, tc.hosts)
+                       res, err := LoadGroups(tc.cfg, tc.hosts)
 
-               if !reflect.DeepEqual(tc.exp, res) {
-                       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("err = %#v, want %#v",
-                               err, tc.expErr)
-               }
+                       if !reflect.DeepEqual(tc.exp, res) {
+                               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("err = %#v, want %#v",
+                                       err, tc.expErr)
+                       }
 
-               err = os.Chdir(cwd)
-               if err != nil {
-                       t.Fatal(err)
-               }
+                       err = os.Chdir(cwd)
+                       if err != nil {
+                               t.Fatal(err)
+                       }
                })
        }
 }
@@ -318,16 +317,16 @@ 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("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("err = %#v, want %#v",
-                               err, tc.expErr)
-               }
+                       res, err := ResolveHostGroups(tc.host, allGroups,
+                               tc.detected)
+                       if !reflect.DeepEqual(tc.exp, res) {
+                               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("err = %#v, want %#v",
+                                       err, tc.expErr)
+                       }
                })
        }
 }
index 36a8c37fd5db42127eb088ec7596d86540932849..95f4e7531936084ba01548f5ae9aa2fdf026c49d 100644 (file)
@@ -84,22 +84,21 @@ 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)
-               }
+                       err := os.Chdir(filepath.Join(cwd, tc.path))
+                       if err != nil {
+                               t.Fatal(err)
+                       }
 
-               res, err := LoadHosts()
+                       res, err := LoadHosts()
 
-               if !reflect.DeepEqual(tc.exp, res) {
-                       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("err = %#v, want %#v",
-                               err, tc.expErr)
-               }
+                       if !reflect.DeepEqual(tc.exp, res) {
+                               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("err = %#v, want %#v",
+                                       err, tc.expErr)
+                       }
                })
        }
 }
index 4efefafd2deb9af727d9b08894211ed41c3231f6..ba1d505f9f019f314d7e02c80fa63790f298bf34 100644 (file)
@@ -227,23 +227,22 @@ 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("err = %#v, want nil", err)
-               }
-               err = LoadPermissions(tc.group, files)
+                       // 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("err = %#v, want nil", err)
+                       }
+                       err = LoadPermissions(tc.group, files)
 
-               if !reflect.DeepEqual(tc.exp, files) {
-                       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("err = %#v, want %#v",
-                               err, tc.expErr)
-               }
+                       if !reflect.DeepEqual(tc.exp, files) {
+                               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("err = %#v, want %#v",
+                                       err, tc.expErr)
+                       }
                })
        }
 }
index bd65c0976e8fe6e41e46858e289e344d3a406ef7..8097af7312f3891ea2626f435ff4a3933d4cbcef 100644 (file)
@@ -243,24 +243,23 @@ 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("err = %#v, want nil", err)
-               }
-               err = LoadTemplates(tc.group, files,
-                       host, groups, allHosts, allGroups)
+                       // 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("err = %#v, want nil", err)
+                       }
+                       err = LoadTemplates(tc.group, files,
+                               host, groups, allHosts, allGroups)
 
-               if !reflect.DeepEqual(tc.exp, files) {
-                       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("err = %#v, want %#v",
-                               err, tc.expErr)
-               }
+                       if !reflect.DeepEqual(tc.exp, files) {
+                               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("err = %#v, want %#v",
+                                       err, tc.expErr)
+                       }
                })
        }
 }
index 96e52d7e7410d2f89707bdb1267ff8436bd5a006..7de0322895ba3e0140cd83a5adacd76fc8f109b4 100644 (file)
@@ -134,23 +134,22 @@ 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("err = %#v, want nil", err)
-               }
-               err = LoadTriggers(tc.group, files)
+                       // 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("err = %#v, want nil", err)
+                       }
+                       err = LoadTriggers(tc.group, files)
 
-               if !reflect.DeepEqual(tc.exp, files) {
-                       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("err = %#v, want %#v",
-                               err, tc.expErr)
-               }
+                       if !reflect.DeepEqual(tc.exp, files) {
+                               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("err = %#v, want %#v",
+                                       err, tc.expErr)
+                       }
                })
        }
 }
index 767564fd14221a2c37405349b9bc867a777cdaa0..dda48738063a1307efbb8260bb1151e557a6a2c3 100644 (file)
@@ -284,17 +284,16 @@ 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,
-                       },
-               }
+                       s := &Sync{
+                               config: &config.Config{
+                                       DryRun: tc.dryRun,
+                               },
+                       }
 
-               res := s.formatFileChanges(tc.changes)
-               if tc.exp != res {
-                       t.Errorf("res: %s",
-                               cmp.Diff(tc.exp, res))
-               }
+                       res := s.formatFileChanges(tc.changes)
+                       if tc.exp != res {
+                               t.Errorf("res: %s", cmp.Diff(tc.exp, res))
+                       }
                })
        }
 }
@@ -357,17 +356,16 @@ 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,
-                       },
-               }
+                       s := &Sync{
+                               config: &config.Config{
+                                       DryRun: tc.dryRun,
+                               },
+                       }
 
-               res := s.formatPackageChanges(tc.changes)
-               if tc.exp != res {
-                       t.Errorf("res: %s",
-                               cmp.Diff(tc.exp, res))
-               }
+                       res := s.formatPackageChanges(tc.changes)
+                       if tc.exp != res {
+                               t.Errorf("res: %s", cmp.Diff(tc.exp, res))
+                       }
                })
        }
 }
@@ -452,17 +450,16 @@ 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,
-                       },
-               }
+                       s := &Sync{
+                               config: &config.Config{
+                                       DryRun: tc.dryRun,
+                               },
+                       }
 
-               res := s.formatServiceChanges(tc.changes)
-               if tc.exp != res {
-                       t.Errorf("res: %s",
-                               cmp.Diff(tc.exp, res))
-               }
+                       res := s.formatServiceChanges(tc.changes)
+                       if tc.exp != res {
+                               t.Errorf("res: %s", cmp.Diff(tc.exp, res))
+                       }
                })
        }
 }
@@ -664,18 +661,17 @@ 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,
-                               Quiet:  tc.quiet,
-                       },
-               }
+                       s := &Sync{
+                               config: &config.Config{
+                                       DryRun: tc.dryRun,
+                                       Quiet:  tc.quiet,
+                               },
+                       }
 
-               res := s.formatCommandChanges(tc.changes)
-               if tc.exp != res {
-                       t.Errorf("res: %s",
-                               cmp.Diff(tc.exp, res))
-               }
+                       res := s.formatCommandChanges(tc.changes)
+                       if tc.exp != res {
+                               t.Errorf("res: %s", cmp.Diff(tc.exp, res))
+                       }
                })
        }
 }
index f234d9b17b95b031d737b70008c49d77b3b425d4..e01083bb8172b668c95c108fd113232899eff17b 100644 (file)
@@ -69,11 +69,10 @@ 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("res: %s",
-                               cmp.Diff(tc.exp, res))
-               }
+                       res := hostInfoRespToGroups(tc.resp)
+                       if !reflect.DeepEqual(tc.exp, res) {
+                               t.Errorf("res: %s", cmp.Diff(tc.exp, res))
+                       }
                })
        }
 }
index 65a490a298518963326cf3597fd720e4e82ddbc0..f3d046a23a0f4618525403fd1158239e8d149dca 100644 (file)
@@ -420,71 +420,71 @@ 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)
-               }
+                       err = os.Chdir(filepath.Join(cwd,
+                               "testdata", tc.project))
+                       if err != nil {
+                               t.Fatal(err)
+                       }
 
-               // `safcm fixperms` in case user has strict umask
-               log.SetOutput(io.Discard)
-               err := MainFixperms()
-               if err != nil {
-                       t.Fatal(err)
-               }
-               log.SetOutput(os.Stderr)
+                       // `safcm fixperms` in case user has strict umask
+                       log.SetOutput(io.Discard)
+                       err := MainFixperms()
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+                       log.SetOutput(os.Stderr)
 
-               cfg, allHosts, allGroups, err := LoadBaseFiles()
-               if err != nil {
-                       t.Fatal(err)
-               }
-               cfg.LogLevel = tc.level
+                       cfg, allHosts, allGroups, err := LoadBaseFiles()
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+                       cfg.LogLevel = tc.level
 
-               var events []string
-               ch := make(chan Event)
-               done := make(chan struct{})
-               go func() {
-                       for {
-                               x, ok := <-ch
-                               if !ok {
-                                       break
+                       var events []string
+                       ch := make(chan Event)
+                       done := make(chan struct{})
+                       go func() {
+                               for {
+                                       x, ok := <-ch
+                                       if !ok {
+                                               break
+                                       }
+                                       if x.ConnEvent.Type != 0 {
+                                               panic("unexpected ConnEvent")
+                                       }
+                                       events = append(events,
+                                               fmt.Sprintf("%s: %v %d %s",
+                                                       x.Host.Name,
+                                                       x.Error, x.Log.Level,
+                                                       x.Log.Text))
                                }
-                               if x.ConnEvent.Type != 0 {
-                                       panic("unexpected ConnEvent")
-                               }
-                               events = append(events,
-                                       fmt.Sprintf("%s: %v %d %s",
-                                               x.Host.Name,
-                                               x.Error, x.Log.Level,
-                                               x.Log.Text))
-                       }
-                       done <- struct{}{}
-               }()
+                               done <- struct{}{}
+                       }()
 
-               s := &Sync{
-                       host:      allHosts.Map[tc.host],
-                       config:    cfg,
-                       allHosts:  allHosts,
-                       allGroups: allGroups,
-                       events:    ch,
-               }
+                       s := &Sync{
+                               host:      allHosts.Map[tc.host],
+                               config:    cfg,
+                               allHosts:  allHosts,
+                               allGroups: allGroups,
+                               events:    ch,
+                       }
 
-               res, err := s.hostSyncReq(tc.detected)
-               if !reflect.DeepEqual(tc.exp, res) {
-                       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("err = %#v, want %#v",
-                               err, tc.expErr)
-               }
+                       res, err := s.hostSyncReq(tc.detected)
+                       if !reflect.DeepEqual(tc.exp, res) {
+                               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("err = %#v, want %#v",
+                                       err, tc.expErr)
+                       }
 
-               close(ch)
-               <-done
-               if !reflect.DeepEqual(tc.expEvents, events) {
-                       t.Errorf("events: %s",
-                               cmp.Diff(tc.expEvents, events))
-               }
+                       close(ch)
+                       <-done
+                       if !reflect.DeepEqual(tc.expEvents, events) {
+                               t.Errorf("events: %s",
+                                       cmp.Diff(tc.expEvents, events))
+                       }
                })
        }
 }
index 753f942fe06706d123967df5d95df9a43ee7c2e7..f904711ccb06963a27ad8d38c6a3a524923c2681 100644 (file)
@@ -167,16 +167,15 @@ 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("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("err = %#v, want %#v",
-                               err, tc.expErr)
-               }
+                       res, err := hostsToSync(tc.names, allHosts, allGroups)
+                       if !reflect.DeepEqual(tc.exp, res) {
+                               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("err = %#v, want %#v",
+                                       err, tc.expErr)
+                       }
                })
        }
 }
index f433eb589f8486059ca73fec2f6d6f57c9f73f08..e5faf174c6e43f02603bfdb785154f07ff9eff33 100644 (file)
@@ -83,11 +83,10 @@ 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("res: %s",
-                               cmp.Diff(tc.exp, res))
-               }
+                       res := EscapeControlCharacters(tc.isTTY, tc.x)
+                       if tc.exp != res {
+                               t.Errorf("res: %s", cmp.Diff(tc.exp, res))
+                       }
                })
        }
 }