X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm-remote%2Fsync%2Fcommands_test.go;h=142a2542a931d4191d56f0b5be641da6a2b00cd7;hb=3473766d8afb07cb0685694656947883cbbd1138;hp=1b1adf71768dc0b8027c8bb0bd7edfd7c2e30156;hpb=bc439f5c4aabef1cccfe40233c2e467602a55a60;p=safcm%2Fsafcm.git diff --git a/cmd/safcm-remote/sync/commands_test.go b/cmd/safcm-remote/sync/commands_test.go index 1b1adf7..142a254 100644 --- a/cmd/safcm-remote/sync/commands_test.go +++ b/cmd/safcm-remote/sync/commands_test.go @@ -20,12 +20,10 @@ import ( "io/fs" "os" "os/exec" - "reflect" "testing" - "github.com/google/go-cmp/cmp" - "ruderich.org/simon/safcm" + "ruderich.org/simon/safcm/testutil" ) func TestSyncCommands(t *testing.T) { @@ -497,31 +495,22 @@ func TestSyncCommands(t *testing.T) { } 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, - }) - s.triggers = tc.triggers + 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 - 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) - } - dbg := res.Wait() + err := s.syncCommands() + testutil.AssertErrorEqual(t, "err", 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)) - } + testutil.AssertEqual(t, "resp", s.resp, tc.expResp) + testutil.AssertEqual(t, "dbg", dbg, tc.expDbg) + }) } }