X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm-remote%2Fsync%2Fsync_test.go;h=8ee14593148dc5b48eb95bc4f7e9ba31dd44eabc;hb=bab6dfbc0ee5fb3ce2b84029ed118a5ba9af0a56;hp=4c0f08d5abdf6515f4da8df503b2088fd71d355d;hpb=992eaae7fec45c2d58fff89d1bc0ae920a899296;p=safcm%2Fsafcm.git diff --git a/cmd/safcm-remote/sync/sync_test.go b/cmd/safcm-remote/sync/sync_test.go index 4c0f08d..8ee1459 100644 --- a/cmd/safcm-remote/sync/sync_test.go +++ b/cmd/safcm-remote/sync/sync_test.go @@ -31,6 +31,8 @@ import ( "ruderich.org/simon/safcm/cmd/safcm-remote/run" ) +// testRunner implements run.Runner to test commands without actually running +// them. type testRunner struct { t *testing.T expCmds []*exec.Cmd @@ -52,6 +54,8 @@ func (r *testRunner) Run(cmd *exec.Cmd) error { return resErr } func (r *testRunner) CombinedOutput(cmd *exec.Cmd) ([]byte, error) { + r.t.Helper() + stdout, stderr, err := r.check("combinedOutput", cmd) if stderr != nil { // stdout also contains stderr @@ -61,6 +65,7 @@ func (r *testRunner) CombinedOutput(cmd *exec.Cmd) ([]byte, error) { } func (r *testRunner) check(method string, cmd *exec.Cmd) ( []byte, []byte, error) { + r.t.Helper() if len(r.expCmds) == 0 { r.t.Fatalf("%s: empty expCmds", method) @@ -78,10 +83,8 @@ func (r *testRunner) check(method string, cmd *exec.Cmd) ( exp := r.expCmds[0] r.expCmds = r.expCmds[1:] if !reflect.DeepEqual(exp, cmd) { - r.t.Errorf("%s: %s", method, - cmp.Diff(exp, cmd, cmpopts.IgnoreUnexported( - exec.Cmd{}, - bytes.Buffer{}))) + opts := cmpopts.IgnoreUnexported(exec.Cmd{}, bytes.Buffer{}) + r.t.Errorf("%s: %s", method, cmp.Diff(exp, cmd, opts)) } var stdout, stderr []byte @@ -133,6 +136,8 @@ func prepareSync(req safcm.MsgSyncReq, runner *testRunner) ( } func (s *syncTestResult) Wait() []string { + s.runner.t.Helper() + close(s.ch) s.wg.Wait()