Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kuskoman committed Oct 16, 2024
1 parent e12c2b6 commit 3ffc4e1
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions internal/flags/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ 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 {
t.Error("expected HandleFlags to return true, but got false")
}
})

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)
}
Expand All @@ -66,14 +70,18 @@ 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 {
t.Error("expected HandleFlags to return true, but got false")
}
})

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)
}
Expand All @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit 3ffc4e1

Please sign in to comment.