}
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)
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)
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() {
}
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,
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))
}
+ })
}
}
}
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)
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
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))
}
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)
}
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)
s, res := prepareSync(tc.req, &testRunner{
t: t,
- name: tc.name,
})
s.setDefaults()
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
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))
}
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() {
}
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,
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))
}
+ })
}
}
}
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,
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))
}
+ })
}
}
type testRunner struct {
t *testing.T
- name string
expCmds []*exec.Cmd
resStdout [][]byte
resStderr [][]byte
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
}
[]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{})))
// 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
}
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))
}
+ })
}
}
}
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)
}
+ })
}
}
}
for _, tc := range tests {
+ t.Run(tc.path, func(t *testing.T) {
err := os.Chdir(tc.path)
if err != nil {
t.Fatal(err)
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)
}
+ })
}
}
}
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)
}
+ })
}
}
}
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)
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)
}
+ })
}
}
}
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)
}
+ })
}
}
}
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)
}
+ })
}
}
}
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)
}
+ })
}
}
}
for _, tc := range tests {
+ t.Run(tc.name, func(t *testing.T) {
s := &Sync{
config: &config.Config{
DryRun: tc.dryRun,
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))
}
+ })
}
}
}
for _, tc := range tests {
+ t.Run(tc.name, func(t *testing.T) {
s := &Sync{
config: &config.Config{
DryRun: tc.dryRun,
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))
}
+ })
}
}
}
for _, tc := range tests {
+ t.Run(tc.name, func(t *testing.T) {
s := &Sync{
config: &config.Config{
DryRun: tc.dryRun,
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))
}
+ })
}
}
}
for _, tc := range tests {
+ t.Run(tc.name, func(t *testing.T) {
s := &Sync{
config: &config.Config{
DryRun: tc.dryRun,
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))
}
+ })
}
}
}
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))
}
+ })
}
}
}
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)
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))
}
-
+ })
}
}
}
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)
}
+ })
}
}
}
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))
}
+ })
}
}