X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm%2Fsync_sync_test.go;h=e96fe140ae612a6a08f2429388c2d333fced2191;hb=a8f56fb33726b836ce853d0606ab0d173f5444f8;hp=f3d046a23a0f4618525403fd1158239e8d149dca;hpb=4299c5d0946ecfa034e9eefe6b16e50bab94a820;p=safcm%2Fsafcm.git diff --git a/cmd/safcm/sync_sync_test.go b/cmd/safcm/sync_sync_test.go index f3d046a..e96fe14 100644 --- a/cmd/safcm/sync_sync_test.go +++ b/cmd/safcm/sync_sync_test.go @@ -22,12 +22,10 @@ import ( "log" "os" "path/filepath" - "reflect" "testing" - "github.com/google/go-cmp/cmp" - "ruderich.org/simon/safcm" + "ruderich.org/simon/safcm/testutil" ) func TestHostSyncReq(t *testing.T) { @@ -61,6 +59,7 @@ func TestHostSyncReq(t *testing.T) { Groups: []string{ "all", "group", + "group3", "remove", "host1.example.org", }, @@ -95,7 +94,7 @@ func TestHostSyncReq(t *testing.T) { Mode: 0644, Uid: -1, Gid: -1, - Data: []byte("Welcome to Host ONE\n\n\n\n"), + Data: []byte("Welcome to Host ONE\n\n\n\n\n\nall\n\n\nhost1.example.org\n\n\n\n"), }, "/etc/rc.local": &safcm.File{ OrigGroup: "group", @@ -137,13 +136,19 @@ func TestHostSyncReq(t *testing.T) { Services: []string{ "unbound", }, - Commands: []string{ - "echo command one", - "echo -n command two", + Commands: []*safcm.Command{ + { + OrigGroup: "group", + Cmd: "echo command one", + }, + { + OrigGroup: "group", + Cmd: "echo -n command two", + }, }, }, []string{ - "host1.example.org: 3 host groups: all group host1.example.org remove", + "host1.example.org: 3 host groups: all group group3 host1.example.org remove", "host1.example.org: 3 host group priorities (desc. order): host1.example.org", }, nil, @@ -159,6 +164,7 @@ func TestHostSyncReq(t *testing.T) { Groups: []string{ "all", "group", + "group3", "remove", "host1.example.org", }, @@ -193,7 +199,7 @@ func TestHostSyncReq(t *testing.T) { Mode: 0644, Uid: -1, Gid: -1, - Data: []byte("Welcome to Host ONE\n\n\n\n"), + Data: []byte("Welcome to Host ONE\n\n\n\n\n\nall\n\n\nhost1.example.org\n\n\n\n"), }, "/etc/rc.local": &safcm.File{ OrigGroup: "group", @@ -235,9 +241,15 @@ func TestHostSyncReq(t *testing.T) { Services: []string{ "unbound", }, - Commands: []string{ - "echo command one", - "echo -n command two", + Commands: []*safcm.Command{ + { + OrigGroup: "group", + Cmd: "echo command one", + }, + { + OrigGroup: "group", + Cmd: "echo -n command two", + }, }, }, nil, @@ -470,21 +482,14 @@ func TestHostSyncReq(t *testing.T) { } res, err := s.hostSyncReq(tc.detected) - if !reflect.DeepEqual(tc.exp, res) { - t.Errorf("res: %s", cmp.Diff(tc.exp, res)) - } - // 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.AssertEqual(t, "res", res, tc.exp) + testutil.AssertErrorEqual(t, "err", err, tc.expErr) close(ch) <-done - if !reflect.DeepEqual(tc.expEvents, events) { - t.Errorf("events: %s", - cmp.Diff(tc.expEvents, events)) - } + testutil.AssertEqual(t, "events", + events, tc.expEvents) }) } }