Files
weatherreporter/internal/app/output_linux_test.go

60 lines
1.7 KiB
Go

//go:build linux
package app
import (
"context"
"net"
"os"
"path/filepath"
"syscall"
"testing"
)
func TestGenerateDetailedRejectsSpecialOutputBeforeWork(t *testing.T) {
for _, tt := range []struct {
name string
setup func(t *testing.T, path string)
}{
{
name: "named pipe",
setup: func(t *testing.T, path string) {
t.Helper()
if err := syscall.Mkfifo(path, 0o600); err != nil {
t.Fatal(err)
}
},
},
{
name: "socket",
setup: func(t *testing.T, path string) {
t.Helper()
listener, err := net.ListenUnix("unix", &net.UnixAddr{Name: path, Net: "unix"})
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = listener.Close() })
},
},
} {
t.Run(tt.name, func(t *testing.T) {
outputPath := filepath.Join(t.TempDir(), "daily.md")
tt.setup(t, outputPath)
bundle := generationBundle(t)
collector := &generationCollector{bundle: &bundle}
executor := &generationExecutor{}
notifier := &generationNotifier{}
result, err := GenerateDetailed(context.Background(), GenerateRequest{
Config: generationConfig(), Report: ReportDaily,
Date: generationTime("2026-05-29T12:00:00-05:00"), Now: generationTime("2026-05-29T08:30:00-05:00"),
WorkingDir: t.TempDir(), OutputPath: outputPath, Collector: collector, Executor: executor, Notifier: notifier,
})
info, statErr := os.Lstat(outputPath)
if err == nil || result == nil || statErr != nil || info.Mode().IsRegular() || collector.called || executor.promptInspections != 0 || executor.called || notifier.calls != 0 {
t.Fatalf("GenerateDetailed() result/error/output/collector/executor/notifier = %#v/%v/%#v (%v)/%t/%#v/%#v", result, err, info, statErr, collector.called, executor, notifier)
}
})
}
}