package rules import "testing" func hasRule(fs []Finding, id string) bool { for _, f := range fs { if f.RuleID == id { return true } } return false } func TestMainDirty_flagsLauncherInMain(t *testing.T) { src := `package main import ( "code.nochebuena.dev/einherjar/core/launcher" "code.nochebuena.dev/einherjar/core/logz" ) func main() { logger := logz.New(logz.Config{}) lc := launcher.New(logger) _ = lc.Run() }` if !hasRule(Run(src), "main.dirty") { t.Fatal("expected main.dirty when the launcher is constructed in main") } } func TestCleanMain_isNotFlagged(t *testing.T) { src := `package main import ( "os" _ "github.com/joho/godotenv/autoload" "myapp/internal/wire" ) func main() { if err := wire.Run(); err != nil { os.Exit(1) } }` fs := Run(src) if hasRule(fs, "main.dirty") { t.Fatal("clean main must not trip main.dirty") } if hasRule(fs, "main.no-godotenv-autoload") { t.Fatal("clean main has autoload; must not trip main.no-godotenv-autoload") } } func TestMainNoGodotenv_flagsMissingAutoload(t *testing.T) { src := `package main import "myapp/internal/wire" func main() { _ = wire.Run() }` if !hasRule(Run(src), "main.no-godotenv-autoload") { t.Fatal("expected main.no-godotenv-autoload when .env is never loaded") } } func TestConfigRawGetenv_flagsEinherjarVar(t *testing.T) { src := `package config import "os" func Load() string { return os.Getenv("EINHERJAR_PG_HOST") }` if !hasRule(Run(src), "config.raw-getenv") { t.Fatal("expected config.raw-getenv when an EINHERJAR_* var is read via os.Getenv") } }