Files
autogits/reparent-bot/main_test.go

33 lines
623 B
Go

package main
import (
"flag"
"os"
"testing"
)
func TestMainFunction(t *testing.T) {
os.Setenv("AUTOGITS_GITEA_TOKEN", "dummy")
os.Setenv("AUTOGITS_RABBIT_USER", "dummy")
os.Setenv("AUTOGITS_RABBIT_PASSWORD", "dummy")
os.Setenv("AUTOGITS_CONFIG", "test_config.json")
// Backup and restore os.Args and flag.CommandLine
oldArgs := os.Args
defer func() { os.Args = oldArgs }()
os.Args = []string{"cmd", "-test.main"}
// Reset flags
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
defer func() {
if r := recover(); r != nil {
t.Log("Recovered from main panic:", r)
}
}()
main()
}