X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm%2Fsync_changes_test.go;h=f48d441208e5f0bd8dc134b0e42b0a036abe5a00;hb=30df06d9dc760f7adf8ce51f2443dedc773f1350;hp=76a016834b87d8a09d68547bcea26720511b13a4;hpb=ddd21f01f764a4ff61204d8e9d0ef8421ebf685c;p=safcm%2Fsafcm.git diff --git a/cmd/safcm/sync_changes_test.go b/cmd/safcm/sync_changes_test.go index 76a0168..f48d441 100644 --- a/cmd/safcm/sync_changes_test.go +++ b/cmd/safcm/sync_changes_test.go @@ -465,6 +465,7 @@ func TestFormatCommandChanges(t *testing.T) { tests := []struct { name string dryRun bool + quiet bool changes []safcm.CommandChange exp string }{ @@ -472,6 +473,7 @@ func TestFormatCommandChanges(t *testing.T) { { "regular", false, + false, []safcm.CommandChange{ { Command: "fake command", @@ -514,6 +516,7 @@ func TestFormatCommandChanges(t *testing.T) { { "dry-run", true, + false, []safcm.CommandChange{ { Command: "fake command", @@ -527,9 +530,116 @@ func TestFormatCommandChanges(t *testing.T) { `, }, + { + "quiet", + false, + true, + []safcm.CommandChange{ + { + Command: "fake command", + Output: "fake output", + }, + { + Command: "fake command with no output", + }, + { + Command: "fake command with newline", + Output: "fake output\n", + }, + { + Command: "fake command with more output", + Output: "fake out\nfake put\nfake\n", + }, + { + Command: "fake failed command", + Output: "fake output", + Error: "fake error", + }, + }, + `executed 5 command(s), 1 with no output: +"fake command": + > fake output + > \ No newline at end of file +"fake command with newline": + > fake output +"fake command with more output": + > fake out + > fake put + > fake +"fake failed command", failed: "fake error": + > fake output + > \ No newline at end of file +`, + }, + + { + "quiet (only quiet commands)", + false, + true, + []safcm.CommandChange{ + { + Command: "fake command with no output", + }, + { + Command: "fake command with no output", + }, + }, + `executed 2 command(s), 2 with no output +`, + }, + + { + "quiet (quiet with errors)", + false, + true, + []safcm.CommandChange{ + { + Command: "fake command with no output but error", + Error: "fake error", + }, + { + Command: "fake command with no output", + }, + }, + `executed 2 command(s), 1 with no output: +"fake command with no output but error", failed: "fake error" +`, + }, + + { + "quiet & dry-run", + true, + true, + []safcm.CommandChange{ + { + Command: "fake command", + }, + { + Command: "fake command with no output", + }, + { + Command: "fake command with newline", + }, + { + Command: "fake command with more output", + }, + { + Command: "fake failed command", + }, + }, + `executed 5 command(s): (dry-run) +"fake command" +"fake command with no output" +"fake command with newline" +"fake command with more output" +"fake failed command" +`, + }, + { "escaping", false, + false, []safcm.CommandChange{ { Command: "\x00", @@ -550,6 +660,7 @@ func TestFormatCommandChanges(t *testing.T) { s := &Sync{ config: &config.Config{ DryRun: tc.dryRun, + Quiet: tc.quiet, }, }