"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) {
"group2",
"host.example.org",
},
- Commands: []string{
- "echo; env | grep SAFCM_",
+ Commands: []*safcm.Command{
+ {
+ Cmd: "echo; env | grep SAFCM_",
+ },
},
},
nil,
"group2",
"host.example.org",
},
- Commands: []string{
- "echo; env | grep SAFCM_",
+ Commands: []*safcm.Command{
+ {
+ Cmd: "echo; env | grep SAFCM_",
+ },
},
},
nil,
"group2",
"host.example.org",
},
- Commands: []string{
- "echo hi; false",
+ Commands: []*safcm.Command{
+ {
+ Cmd: "echo hi; false",
+ },
},
},
nil,
"group2",
"host.example.org",
},
- Commands: []string{
- "echo hi; false",
+ Commands: []*safcm.Command{
+ {
+ Cmd: "echo hi; false",
+ },
},
},
nil,
"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,
},
},
},
- Commands: []string{
- "echo; env | grep SAFCM_",
+ Commands: []*safcm.Command{
+ {
+ Cmd: "echo; env | grep SAFCM_",
+ },
},
},
[]string{
},
},
},
- Commands: []string{
- "echo; env | grep SAFCM_",
+ Commands: []*safcm.Command{
+ {
+ Cmd: "echo; env | grep SAFCM_",
+ },
},
},
[]string{
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)
})
}
}