refactor: split into packages and add tests

This commit is contained in:
technofab 2025-06-03 12:05:16 +02:00
parent fd58344ca7
commit 11117e0c0e
28 changed files with 2736 additions and 636 deletions

43
internal/config/config.go Normal file
View file

@ -0,0 +1,43 @@
package config
import (
"github.com/jedib0t/go-pretty/v6/text"
"github.com/rs/zerolog/log"
flag "github.com/spf13/pflag"
)
type AppConfig struct {
NumWorkers int
TestsFile string
SnapshotDir string
JunitPath string
UpdateSnapshots bool
SkipPattern string
PureEnv bool
NoColor bool
}
// loads configuration from cli flags
func Load() AppConfig {
cfg := AppConfig{}
flag.IntVarP(&cfg.NumWorkers, "workers", "w", 4, "Amount of tests to run in parallel")
flag.StringVarP(&cfg.TestsFile, "tests", "f", "", "Path to JSON file containing tests (required)")
flag.StringVar(&cfg.SnapshotDir, "snapshot-dir", "./snapshots", "Directory where snapshots are stored")
flag.StringVar(&cfg.JunitPath, "junit", "", "Path to generate JUNIT report to, leave empty to disable")
flag.BoolVarP(&cfg.UpdateSnapshots, "update-snapshots", "u", false, "Update all snapshots")
flag.StringVarP(&cfg.SkipPattern, "skip", "s", "", "Regular expression to skip tests (e.g., 'test-.*|.*-b')")
flag.BoolVar(&cfg.PureEnv, "pure", false, "Unset all env vars before running script tests")
flag.BoolVar(&cfg.NoColor, "no-color", false, "Disable coloring")
flag.Parse()
if cfg.TestsFile == "" {
log.Panic().Msg("Tests file path (-f or --tests) is required.")
}
if cfg.NoColor {
text.DisableColors()
}
return cfg
}