X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm-remote%2Fsync%2Fcommands_test.go;h=ba7f4a2e89ec47e16fec11f88f41aad4577a2617;hb=1934f1ab83306dff45310d5b45e2a99c97e28c35;hp=3c47c1757c6adf5f199dc4342a692127da263e03;hpb=4299c5d0946ecfa034e9eefe6b16e50bab94a820;p=safcm%2Fsafcm.git diff --git a/cmd/safcm-remote/sync/commands_test.go b/cmd/safcm-remote/sync/commands_test.go index 3c47c17..ba7f4a2 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) { @@ -67,8 +65,10 @@ func TestSyncCommands(t *testing.T) { "group2", "host.example.org", }, - Commands: []string{ - "echo; env | grep SAFCM_", + Commands: []*safcm.Command{ + { + Cmd: "echo; env | grep SAFCM_", + }, }, }, nil, @@ -107,8 +107,10 @@ func TestSyncCommands(t *testing.T) { "group2", "host.example.org", }, - Commands: []string{ - "echo; env | grep SAFCM_", + Commands: []*safcm.Command{ + { + Cmd: "echo; env | grep SAFCM_", + }, }, }, nil, @@ -136,8 +138,10 @@ func TestSyncCommands(t *testing.T) { "group2", "host.example.org", }, - Commands: []string{ - "echo hi; false", + Commands: []*safcm.Command{ + { + Cmd: "echo hi; false", + }, }, }, nil, @@ -177,8 +181,10 @@ func TestSyncCommands(t *testing.T) { "group2", "host.example.org", }, - Commands: []string{ - "echo hi; false", + Commands: []*safcm.Command{ + { + Cmd: "echo hi; false", + }, }, }, nil, @@ -206,11 +212,16 @@ func TestSyncCommands(t *testing.T) { "group2", "host.example.org", }, - Commands: []string{ - "echo first", - "echo second", - "false", - "echo third", + Commands: []*safcm.Command{ + { + Cmd: "echo first", + }, { + Cmd: "echo second", + }, { + Cmd: "false", + }, { + Cmd: "echo third", + }, }, }, nil, @@ -320,8 +331,10 @@ func TestSyncCommands(t *testing.T) { }, }, }, - Commands: []string{ - "echo; env | grep SAFCM_", + Commands: []*safcm.Command{ + { + Cmd: "echo; env | grep SAFCM_", + }, }, }, []string{ @@ -436,8 +449,10 @@ func TestSyncCommands(t *testing.T) { }, }, }, - Commands: []string{ - "echo; env | grep SAFCM_", + Commands: []*safcm.Command{ + { + Cmd: "echo; env | grep SAFCM_", + }, }, }, []string{ @@ -508,21 +523,11 @@ func TestSyncCommands(t *testing.T) { 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("err = %#v, want %#v", - err, tc.expErr) - } + testutil.AssertErrorEqual(t, "err", err, tc.expErr) dbg := res.Wait() - if !reflect.DeepEqual(tc.expResp, s.resp) { - t.Errorf("resp: %s", - cmp.Diff(tc.expResp, s.resp)) - } - if !reflect.DeepEqual(tc.expDbg, dbg) { - t.Errorf("dbg: %s", - cmp.Diff(tc.expDbg, dbg)) - } + testutil.AssertEqual(t, "resp", s.resp, tc.expResp) + testutil.AssertEqual(t, "dbg", dbg, tc.expDbg) }) } }