X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm-remote%2Fsync%2Fservices_systemd_test.go;h=f4f7f4920c6c61ae703956c65b6069268fb87f4e;hb=778665c07c9cf6f434dbd1ee867fe8b8636f55c0;hp=8ba0bfabed44a66e0f4ce787ce658b10b5d2649a;hpb=f2f2bc47e8729548f3c10117f7f008b547c4afc5;p=safcm%2Fsafcm.git diff --git a/cmd/safcm-remote/sync/services_systemd_test.go b/cmd/safcm-remote/sync/services_systemd_test.go index 8ba0bfa..f4f7f49 100644 --- a/cmd/safcm-remote/sync/services_systemd_test.go +++ b/cmd/safcm-remote/sync/services_systemd_test.go @@ -19,12 +19,10 @@ import ( "bytes" "fmt" "os/exec" - "reflect" "testing" - "github.com/google/go-cmp/cmp" - "ruderich.org/simon/safcm" + "ruderich.org/simon/safcm/testutil" ) func TestSyncServicesSystemd(t *testing.T) { @@ -226,7 +224,7 @@ LoadError= nil, nil, nil, - []byte(`fake stderr`), + []byte("fake stderr"), }, []error{nil, nil, nil, nil}, []*exec.Cmd{&exec.Cmd{ @@ -423,7 +421,7 @@ LoadError= [][]byte{ nil, nil, - []byte(`fake stderr`), + []byte("fake stderr"), }, []error{ nil, @@ -507,30 +505,21 @@ LoadError= } for _, tc := range tests { - s, res := prepareSync(tc.req, &testRunner{ - t: t, - name: tc.name, - expCmds: tc.expCmds, - resStdout: tc.stdout, - resStderr: tc.stderr, - resError: tc.errors, + 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() + testutil.AssertErrorEqual(t, "err", err, tc.expErr) + dbg := res.Wait() + + testutil.AssertEqual(t, "resp", s.resp, tc.expResp) + testutil.AssertEqual(t, "dbg", dbg, tc.expDbg) }) - - 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) - } - dbg := res.Wait() - - if !reflect.DeepEqual(tc.expResp, s.resp) { - t.Errorf("%s: resp: %s", tc.name, - cmp.Diff(tc.expResp, s.resp)) - } - if !reflect.DeepEqual(tc.expDbg, dbg) { - t.Errorf("%s: dbg: %s", tc.name, - cmp.Diff(tc.expDbg, dbg)) - } } }