From 367edc1286a52d96fcfef6f98330148cad8a64e1 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 25 Apr 2021 09:57:37 +0200 Subject: [PATCH] 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. --- cmd/safcm/main_sync_test.go | 11 +++++++++++ cmd/safcm/sync_changes.go | 3 ++- cmd/safcm/sync_changes_test.go | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) 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", }, { -- 2.45.2