From: Simon Ruderich Date: Sun, 25 Apr 2021 07:57:37 +0000 (+0200) Subject: changes: display "no changes" when nothing was changed X-Git-Url: https://ruderich.org/simon/gitweb/?p=safcm%2Fsafcm.git;a=commitdiff_plain;h=367edc1286a52d96fcfef6f98330148cad8a64e1 changes: display "no changes" when nothing was changed It's confusing to show nothing at all when no changes occur on a host. To inform the user that the sync was successful but nothing changed display a short message. --- diff --git a/cmd/safcm/main_sync_test.go b/cmd/safcm/main_sync_test.go index 8d702db..39784fa 100644 --- a/cmd/safcm/main_sync_test.go +++ b/cmd/safcm/main_sync_test.go @@ -85,6 +85,7 @@ func TestSyncSshEndToEnd(t *testing.T) { true, []string{"no-settings.example.org"}, `[info] [no-settings.example.org] remote helper upload in progress +[info] [no-settings.example.org] no changes `, nil, }, @@ -92,6 +93,14 @@ func TestSyncSshEndToEnd(t *testing.T) { "no settings (no helper upload)", false, []string{"no-settings.example.org"}, + `[info] [no-settings.example.org] no changes +`, + nil, + }, + { + "no settings (error)", + true, + []string{"-log", "error", "no-settings.example.org"}, ``, nil, }, @@ -102,6 +111,7 @@ func TestSyncSshEndToEnd(t *testing.T) { `[info] [no-settings.example.org] remote helper upload in progress [verbose] [no-settings.example.org] host groups: all no-settings.example.org [verbose] [no-settings.example.org] host group priorities (desc. order): no-settings.example.org +[info] [no-settings.example.org] no changes `, nil, }, @@ -112,6 +122,7 @@ func TestSyncSshEndToEnd(t *testing.T) { `[info] [no-settings.example.org] remote helper upload in progress [verbose] [no-settings.example.org] host groups: all no-settings.example.org [verbose] [no-settings.example.org] host group priorities (desc. order): no-settings.example.org +[info] [no-settings.example.org] no changes `, nil, }, diff --git a/cmd/safcm/sync_changes.go b/cmd/safcm/sync_changes.go index a85b810..3e91768 100644 --- a/cmd/safcm/sync_changes.go +++ b/cmd/safcm/sync_changes.go @@ -49,7 +49,8 @@ func (s *Sync) formatChanges(resp safcm.MsgSyncResp) string { s.formatCommandChanges(resp.CommandChanges)) } if len(changes) == 0 { - return "" + // Notify user that the host was synced successfully + return "no changes" } x := strings.Join(changes, "\n") diff --git a/cmd/safcm/sync_changes_test.go b/cmd/safcm/sync_changes_test.go index 6c7ba39..d8ce97b 100644 --- a/cmd/safcm/sync_changes_test.go +++ b/cmd/safcm/sync_changes_test.go @@ -43,7 +43,7 @@ func TestFormatChanges(t *testing.T) { false, false, safcm.MsgSyncResp{}, - "", + "no changes", }, {