-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Allow suppressing execution output (#309)
* feature: Allow supresssing execution output Signed-off-by: Valentin Kiselev <mrexox@evilmartians.com> * chore: Refactor and rename type to SkipSettings Signed-off-by: Valentin Kiselev <mrexox@evilmartians.com>
- Loading branch information
Showing
5 changed files
with
151 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package log | ||
|
||
const ( | ||
skipMeta = 1 << iota | ||
skipSuccess | ||
skipFailure | ||
skipSummary | ||
skipExecution | ||
) | ||
|
||
type SkipSettings int8 | ||
|
||
func (s *SkipSettings) ApplySetting(setting string) { | ||
switch setting { | ||
case "meta": | ||
*s |= skipMeta | ||
case "success": | ||
*s |= skipSuccess | ||
case "failure": | ||
*s |= skipFailure | ||
case "summary": | ||
*s |= skipSummary | ||
case "execution": | ||
*s |= skipExecution | ||
} | ||
} | ||
|
||
func (s SkipSettings) SkipSuccess() bool { | ||
return s.doSkip(skipSuccess) | ||
} | ||
|
||
func (s SkipSettings) SkipFailure() bool { | ||
return s.doSkip(skipFailure) | ||
} | ||
|
||
func (s SkipSettings) SkipSummary() bool { | ||
return s.doSkip(skipSummary) | ||
} | ||
|
||
func (s SkipSettings) SkipMeta() bool { | ||
return s.doSkip(skipMeta) | ||
} | ||
|
||
func (s SkipSettings) SkipExecution() bool { | ||
return s.doSkip(skipExecution) | ||
} | ||
|
||
func (s SkipSettings) doSkip(option int8) bool { | ||
return int8(s)&option != 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package log | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestSkipSetting(t *testing.T) { | ||
for i, tt := range [...]struct { | ||
settings []string | ||
results map[string]bool | ||
}{ | ||
{ | ||
settings: []string{}, | ||
results: map[string]bool{}, | ||
}, | ||
{ | ||
settings: []string{"failure", "execution"}, | ||
results: map[string]bool{ | ||
"failure": true, | ||
"execution": true, | ||
}, | ||
}, | ||
{ | ||
settings: []string{"meta", "summary", "success", "failure", "execution"}, | ||
results: map[string]bool{ | ||
"meta": true, | ||
"summary": true, | ||
"success": true, | ||
"failure": true, | ||
"execution": true, | ||
}, | ||
}, | ||
} { | ||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { | ||
var settings SkipSettings | ||
|
||
for _, option := range tt.settings { | ||
(&settings).ApplySetting(option) | ||
} | ||
|
||
if settings.SkipMeta() != tt.results["meta"] { | ||
t.Errorf("expected SkipMeta to be %v", tt.results["meta"]) | ||
} | ||
|
||
if settings.SkipSuccess() != tt.results["success"] { | ||
t.Errorf("expected SkipSuccess to be %v", tt.results["success"]) | ||
} | ||
|
||
if settings.SkipFailure() != tt.results["failure"] { | ||
t.Errorf("expected SkipFailure to be %v", tt.results["failure"]) | ||
} | ||
|
||
if settings.SkipSummary() != tt.results["summary"] { | ||
t.Errorf("expected SkipSummary to be %v", tt.results["summary"]) | ||
} | ||
|
||
if settings.SkipExecution() != tt.results["execution"] { | ||
t.Errorf("expected SkipExecution to be %v", tt.results["execution"]) | ||
} | ||
}) | ||
} | ||
} |