Skip to content

Commit

Permalink
handle exceptions in writing to the log file
Browse files Browse the repository at this point in the history
also cleanup some comments in colors_test.go
  • Loading branch information
jdrews committed Apr 26, 2023
1 parent 301879d commit 5b4af2f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion colors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestParseRegexPatterns(t *testing.T) {
}

func TestColorize(t *testing.T) {
// load in the default config file, so we get some regex patterns
// Load in the default config file, so we get some regex patterns
HandleConfigFile("logstation.default.conf")

// Get the compiledRegexColors
Expand Down
17 changes: 13 additions & 4 deletions tailer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@ func writeALine(t *testing.T, logFilePath string, logString string) {
// Write a line to the logFilePath
file, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
t.Fatalf("failed creating file: %s", err)
t.Errorf("failed creating file: %s", err)
}
datawriter := bufio.NewWriter(file)
datawriter.WriteString(fmt.Sprint(logString))
datawriter.Flush()
file.Close()
_, err = datawriter.WriteString(fmt.Sprint(logString))
if err != nil {
t.Errorf("Unable to write a string to %s", logFilePath)
}
err = datawriter.Flush()
if err != nil {
t.Errorf("Unable to flush %s", logFilePath)
}
err = file.Close()
if err != nil {
t.Errorf("Unable to close %s", logFilePath)
}
}

// TestFollow is an integration test for the entire backend tailing system
Expand Down

0 comments on commit 5b4af2f

Please sign in to comment.