From 16e1a602816225cb515a9e723fc313c1f1c346e9 Mon Sep 17 00:00:00 2001 From: sebgl Date: Thu, 28 Nov 2019 16:27:00 +0100 Subject: [PATCH] Don't init flags in init() An issue prevents unit tests to run if flags are initialized in an init() function. More details there: https://github.com/golang/go/issues/31859. A workaround is to init flags another way (here by calling a function from main()). --- main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 6aa8f47..7ab05aa 100644 --- a/main.go +++ b/main.go @@ -75,7 +75,7 @@ type apiPackage struct { func (v *apiPackage) identifier() string { return fmt.Sprintf("%s/%s", v.apiGroup, v.apiVersion) } -func init() { +func initFlags() { klog.InitFlags(nil) flag.Set("alsologtostderr", "true") // for klog flag.Parse() @@ -114,6 +114,8 @@ func resolveTemplateDir(dir string) error { func main() { defer klog.Flush() + initFlags() + f, err := os.Open(*flConfig) if err != nil { klog.Fatalf("failed to open config file: %+v", err)