From 8761d4659b0c733df2f9e5f6afc4c46db0813e36 Mon Sep 17 00:00:00 2001 From: Jeremy Mill Date: Sat, 16 Apr 2022 18:04:49 -0400 Subject: [PATCH] detect unit testing and skip init Signed-off-by: Jeremy Mill --- main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.go b/main.go index 465542f7c..9e97b7281 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "net/http" + "os" "strings" "github.com/DataDog/datadog-go/statsd" @@ -60,6 +61,13 @@ var ( ) func init() { + // detect unit testing and skip init. + // see: https://github.com/alecthomas/kingpin/issues/187 + testing := (strings.HasSuffix(os.Args[0], ".test") || + strings.HasSuffix(os.Args[0], "__debug_bin")) + if testing { + return + } config = getConfig() stats = getInitStats() promStats = getInitPromStats(config)