package audita import ( "context" "errors" "os" "path/filepath" "strings" "testing" ) func TestFakeRunnerCapturesRequestAndReturnsPath(t *testing.T) { fake := &FakeRunner{} dir := t.TempDir() req := PolishRequest{ GeneratedConfigPath: filepath.Join(dir, "config", "audita.yml"), OutputProcessedPath: filepath.Join(dir, "transcripts", "processed.json"), StdoutLogPath: filepath.Join(dir, "logs", "audita.stdout.log"), StderrLogPath: filepath.Join(dir, "logs", "audita.stderr.log"), } res, err := fake.Run(context.Background(), req) if err != nil { t.Fatalf("Run() error = %v", err) } if len(fake.Requests) != 1 || fake.Requests[0].GeneratedConfigPath == "" { t.Fatalf("requests = %#v, want captured request", fake.Requests) } if res.ProcessedTranscriptPath != req.OutputProcessedPath { t.Fatalf("processed path = %q, want %q", res.ProcessedTranscriptPath, req.OutputProcessedPath) } cfgData, err := os.ReadFile(req.GeneratedConfigPath) if err != nil { t.Fatalf("read generated config: %v", err) } if !strings.Contains(string(cfgData), "placeholder: true") { t.Fatalf("generated config = %q, want placeholder marker", string(cfgData)) } for _, logPath := range []string{req.StdoutLogPath, req.StderrLogPath} { if _, err := os.Stat(logPath); err != nil { t.Fatalf("expected log file %q to exist: %v", logPath, err) } } } func TestFakeRunnerError(t *testing.T) { fake := &FakeRunner{Err: errors.New("boom")} _, err := fake.Run(context.Background(), PolishRequest{}) if err == nil { t.Fatal("expected error, got nil") } }