mirror of
https://github.com/kjanat/articulate-parser.git
synced 2026-01-16 09:02:10 +01:00
refactor(core)!: Add context, config, and structured logging
Introduces `context.Context` to the `FetchCourse` method and its call chain, allowing for cancellable network requests and timeouts. This improves application robustness when fetching remote course data. A new configuration package centralizes application settings, loading them from environment variables with sensible defaults for base URL, request timeout, and logging. Standard `log` and `fmt` calls are replaced with a structured logging system built on `slog`, supporting both JSON and human-readable text formats. This change also includes: - Extensive benchmarks and example tests. - Simplified Go doc comments across several packages. BREAKING CHANGE: The `NewArticulateParser` constructor signature has been updated to accept a logger, base URL, and timeout, which are now supplied via the new configuration system.
This commit is contained in:
24
main_test.go
24
main_test.go
@ -3,7 +3,6 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
@ -297,10 +296,10 @@ func TestRunWithInvalidFile(t *testing.T) {
|
||||
t.Errorf("Expected exit code 1 for non-existent file, got %d", exitCode)
|
||||
}
|
||||
|
||||
// Should have error output
|
||||
errorOutput := stderrBuf.String()
|
||||
if !strings.Contains(errorOutput, "Error processing course") {
|
||||
t.Errorf("Expected error message about processing course, got: %s", errorOutput)
|
||||
// Should have error output in structured log format
|
||||
output := stdoutBuf.String()
|
||||
if !strings.Contains(output, "level=ERROR") && !strings.Contains(output, "failed to process course") {
|
||||
t.Errorf("Expected error message about processing course, got: %s", output)
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,10 +349,10 @@ func TestRunWithInvalidURI(t *testing.T) {
|
||||
t.Errorf("Expected failure (exit code 1) for invalid URI, got %d", exitCode)
|
||||
}
|
||||
|
||||
// Should have error output
|
||||
errorOutput := stderrBuf.String()
|
||||
if !strings.Contains(errorOutput, "Error processing course") {
|
||||
t.Errorf("Expected error message about processing course, got: %s", errorOutput)
|
||||
// Should have error output in structured log format
|
||||
output := stdoutBuf.String()
|
||||
if !strings.Contains(output, "level=ERROR") && !strings.Contains(output, "failed to process course") {
|
||||
t.Errorf("Expected error message about processing course, got: %s", output)
|
||||
}
|
||||
}
|
||||
|
||||
@ -436,10 +435,9 @@ func TestRunWithValidJSONFile(t *testing.T) {
|
||||
t.Errorf("Expected successful execution (exit code 0), got %d", exitCode)
|
||||
}
|
||||
|
||||
// Verify success message
|
||||
expectedMsg := fmt.Sprintf("Successfully exported course to %s", outputFile)
|
||||
if !strings.Contains(output, expectedMsg) {
|
||||
t.Errorf("Expected success message '%s' in output, got: %s", expectedMsg, output)
|
||||
// Verify success message in structured log format
|
||||
if !strings.Contains(output, "level=INFO") || !strings.Contains(output, "successfully exported course") {
|
||||
t.Errorf("Expected success message in output, got: %s", output)
|
||||
}
|
||||
|
||||
// Verify output file was created
|
||||
|
||||
Reference in New Issue
Block a user