]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
changes: display "no changes" when nothing was changed
authorSimon Ruderich <simon@ruderich.org>
Sun, 25 Apr 2021 07:57:37 +0000 (09:57 +0200)
committerSimon Ruderich <simon@ruderich.org>
Sun, 25 Apr 2021 07:57:37 +0000 (09:57 +0200)
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
cmd/safcm/sync_changes.go
cmd/safcm/sync_changes_test.go

index 8d702db218a3655318583864c47fd347c7eaabfe..39784fa12ef270ab380ff3402112a55f5660cc50 100644 (file)
@@ -85,6 +85,7 @@ func TestSyncSshEndToEnd(t *testing.T) {
                        true,
                        []string{"no-settings.example.org"},
                        `<LOG>[info]    [no-settings.example.org] remote helper upload in progress
+<LOG>[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"},
+                       `<LOG>[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) {
                        `<LOG>[info]    [no-settings.example.org] remote helper upload in progress
 <LOG>[verbose] [no-settings.example.org] host groups: all <DET> <DET> no-settings.example.org
 <LOG>[verbose] [no-settings.example.org] host group priorities (desc. order): no-settings.example.org
+<LOG>[info]    [no-settings.example.org] no changes
 `,
                        nil,
                },
@@ -112,6 +122,7 @@ func TestSyncSshEndToEnd(t *testing.T) {
                        `<LOG>[info]    [no-settings.example.org] remote helper upload in progress
 <LOG>[verbose] [no-settings.example.org] host groups: all <DET> <DET> no-settings.example.org
 <LOG>[verbose] [no-settings.example.org] host group priorities (desc. order): no-settings.example.org
+<LOG>[info]    [no-settings.example.org] no changes
 `,
                        nil,
                },
index a85b8100946da96a6bf2670a2a4f0d32917eba2e..3e91768bfca3eb3273e5c24954c506f86934a63b 100644 (file)
@@ -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")
index 6c7ba392aac7b36b01399eb7e1d8c6fba4af9b8c..d8ce97b2a876ea45c2d18d5d78f0959eb2e1fe17 100644 (file)
@@ -43,7 +43,7 @@ func TestFormatChanges(t *testing.T) {
                        false,
                        false,
                        safcm.MsgSyncResp{},
-                       "",
+                       "no changes",
                },
 
                {