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))
+ }
})
}
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))
+ }
})
}
}
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))
+ }
})
}
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))
+ }
})
}
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))
+ }
})
}
}
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))
+ }
})
}
}
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))
+ }
})
}
}
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)
+ }
})
}
}
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)
+ }
})
}
}
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)
+ }
})
}
}
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)
+ }
})
}
}
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)
+ }
})
}
}
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)
+ }
})
}
}
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)
+ }
})
}
}
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))
+ }
})
}
}
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))
+ }
})
}
}
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))
+ }
})
}
}
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))
+ }
})
}
}
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))
+ }
})
}
}
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))
+ }
})
}
}
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)
+ }
})
}
}
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))
+ }
})
}
}