From 93d0d38a0319fc2a70ab9565fd2f514719168b36 Mon Sep 17 00:00:00 2001 From: prog-supdex Date: Thu, 15 Feb 2024 08:37:29 +0100 Subject: [PATCH 1/2] fix: handle LEFTHOOK_QUIET when there is no skip_output in config --- internal/log/skip_settings.go | 9 +++++---- internal/log/skip_settings_test.go | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/internal/log/skip_settings.go b/internal/log/skip_settings.go index 47aa1fab..2e9cb551 100644 --- a/internal/log/skip_settings.go +++ b/internal/log/skip_settings.go @@ -27,10 +27,11 @@ func (s *SkipSettings) ApplySettings(tags string, skipOutput interface{}) { for _, skipOption := range typedSkipOutput { s.applySetting(skipOption.(string)) } - if tags != "" { - for _, skipOption := range strings.Split(tags, ",") { - s.applySetting(skipOption) - } + } + + if tags != "" { + for _, skipOption := range strings.Split(tags, ",") { + s.applySetting(skipOption) } } } diff --git a/internal/log/skip_settings_test.go b/internal/log/skip_settings_test.go index 15706964..97973cd1 100644 --- a/internal/log/skip_settings_test.go +++ b/internal/log/skip_settings_test.go @@ -106,4 +106,21 @@ func TestSkipSetting(t *testing.T) { } }) } + + t.Run("ApplySettings with non-empty tags and nil skipOutput", func(t *testing.T) { + var settings SkipSettings + (&settings).ApplySettings("meta,success", nil) + + if !settings.SkipMeta() { + t.Errorf("expected SkipMeta to be true") + } + + if !settings.SkipSuccess() { + t.Errorf("expected SkipSuccess to be true") + } + + if settings.SkipFailure() { + t.Errorf("expected SkipFailure to be false") + } + }) } From f43cb23bb67ff51afac84624f6d9aa3da145a77e Mon Sep 17 00:00:00 2001 From: prog-supdex Date: Thu, 15 Feb 2024 09:56:26 +0100 Subject: [PATCH 2/2] refactored the test --- internal/log/skip_settings_test.go | 40 ++++++++++++++++-------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/internal/log/skip_settings_test.go b/internal/log/skip_settings_test.go index 97973cd1..f2f85e9f 100644 --- a/internal/log/skip_settings_test.go +++ b/internal/log/skip_settings_test.go @@ -7,18 +7,22 @@ import ( func TestSkipSetting(t *testing.T) { for i, tt := range [...]struct { + tags string settings interface{} results map[string]bool }{ { + tags: "", settings: []interface{}{}, results: map[string]bool{}, }, { + tags: "", settings: false, results: map[string]bool{}, }, { + tags: "", settings: []interface{}{"failure", "execution"}, results: map[string]bool{ "failure": true, @@ -26,6 +30,7 @@ func TestSkipSetting(t *testing.T) { }, }, { + tags: "", settings: []interface{}{ "meta", "summary", @@ -50,6 +55,7 @@ func TestSkipSetting(t *testing.T) { }, }, { + tags: "", settings: true, results: map[string]bool{ "meta": true, @@ -63,11 +69,26 @@ func TestSkipSetting(t *testing.T) { "empty_summary": true, }, }, + { + tags: "meta,summary,success,skips,empty_summary", + settings: nil, + results: map[string]bool{ + "meta": true, + "summary": true, + "success": true, + "failure": false, + "skips": true, + "execution": false, + "execution_out": false, + "execution_info": false, + "empty_summary": true, + }, + }, } { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { var settings SkipSettings - (&settings).ApplySettings("", tt.settings) + (&settings).ApplySettings(tt.tags, tt.settings) if settings.SkipMeta() != tt.results["meta"] { t.Errorf("expected SkipMeta to be %v", tt.results["meta"]) @@ -106,21 +127,4 @@ func TestSkipSetting(t *testing.T) { } }) } - - t.Run("ApplySettings with non-empty tags and nil skipOutput", func(t *testing.T) { - var settings SkipSettings - (&settings).ApplySettings("meta,success", nil) - - if !settings.SkipMeta() { - t.Errorf("expected SkipMeta to be true") - } - - if !settings.SkipSuccess() { - t.Errorf("expected SkipSuccess to be true") - } - - if settings.SkipFailure() { - t.Errorf("expected SkipFailure to be false") - } - }) }