From 3ffc4e127bf2ca1f91d211b9c328f618f092e96d Mon Sep 17 00:00:00 2001 From: Jakub Surdej Date: Wed, 16 Oct 2024 23:58:50 +0200 Subject: [PATCH] Fix linter errors --- internal/flags/flags_test.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/internal/flags/flags_test.go b/internal/flags/flags_test.go index 69f3927..e863df7 100644 --- a/internal/flags/flags_test.go +++ b/internal/flags/flags_test.go @@ -48,7 +48,7 @@ func TestParseFlags(t *testing.T) { func TestHandleFlags(t *testing.T) { t.Run("prints help when Help flag is true", func(t *testing.T) { // Capture the output of the print functions - output := captureOutput(func() { + output, err := captureOutput(func() { flagsConfig := &FlagsConfig{Help: true} result := HandleFlags(flagsConfig) if !result { @@ -56,6 +56,10 @@ func TestHandleFlags(t *testing.T) { } }) + if err != nil { + t.Fatalf("unexpected error capturing output: %v", err) + } + if !contains(output, "Usage of") { t.Errorf("expected 'Usage of' to be printed, but it was not found in output: %s", output) } @@ -66,7 +70,7 @@ func TestHandleFlags(t *testing.T) { // Mock config.SemanticVersion config.SemanticVersion = "v1.0.0" - output := captureOutput(func() { + output, err := captureOutput(func() { flagsConfig := &FlagsConfig{Version: true} result := HandleFlags(flagsConfig) if !result { @@ -74,6 +78,10 @@ func TestHandleFlags(t *testing.T) { } }) + if err != nil { + t.Fatalf("unexpected error capturing output: %v", err) + } + if !contains(output, "v1.0.0") { t.Errorf("expected version 'v1.0.0' to be printed, but it was not found in output: %s", output) } @@ -90,7 +98,7 @@ func TestHandleFlags(t *testing.T) { } // Helper function to capture output printed to stdout -func captureOutput(f func()) string { +func captureOutput(f func()) (string, error) { var buf bytes.Buffer stdout := os.Stdout r, w, _ := os.Pipe() @@ -100,9 +108,12 @@ func captureOutput(f func()) string { w.Close() os.Stdout = stdout - buf.ReadFrom(r) + _, err := buf.ReadFrom(r) + if err != nil { + return "", err + } - return buf.String() + return buf.String(), nil } // Helper function to check if a string contains a substring