fix: address audit execution failures and unsafe type conversions
This commit is contained in:
@@ -2,6 +2,7 @@ package pgsql
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -237,8 +238,9 @@ func TestWriteAndFinishReport(t *testing.T) {
|
||||
options: &writers.WriterOptions{Metadata: map[string]interface{}{"report_path": path}},
|
||||
executionReport: report,
|
||||
}
|
||||
if err := w.finishReport(); err != nil {
|
||||
t.Fatalf("finishReport: %v", err)
|
||||
var failure *ExecutionFailure
|
||||
if err := w.finishReport(); !errors.As(err, &failure) || failure.Report != report {
|
||||
t.Fatalf("expected structured execution failure, got: %v", err)
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
@@ -270,10 +272,15 @@ func TestWriteReportBadPath(t *testing.T) {
|
||||
if err := w.writeReport(filepath.Join(t.TempDir(), "missing", "r.json")); err == nil {
|
||||
t.Error("expected error for unwritable path")
|
||||
}
|
||||
// finishReport must swallow the report error.
|
||||
// Explicitly requested reports are part of successful execution.
|
||||
w.options.Metadata = map[string]interface{}{"report_path": filepath.Join(t.TempDir(), "missing", "r.json")}
|
||||
if err := w.finishReport(); err != nil {
|
||||
t.Errorf("finishReport must not fail on report write error: %v", err)
|
||||
if err := w.finishReport(); err == nil {
|
||||
t.Error("finishReport must fail on report write error")
|
||||
}
|
||||
w.executionReport.FailedStatements = 1
|
||||
var failure *ExecutionFailure
|
||||
if err := w.finishReport(); !errors.As(err, &failure) || !strings.Contains(err.Error(), "requested execution report") {
|
||||
t.Fatalf("must preserve both execution and report errors: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user