"fmt"
"os"
"os/exec"
- "reflect"
"testing"
- "github.com/google/go-cmp/cmp"
-
"ruderich.org/simon/safcm"
+ "ruderich.org/simon/safcm/testutil"
)
func TestSyncPackagesDebian(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,
- })
+ 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.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)
- }
- dbg := res.Wait()
+ err := s.syncPackagesDebian()
+ 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)
+ })
}
}