From 40d888c7f2a34c1fff966b4ee36c149fa9af4ebe Mon Sep 17 00:00:00 2001 From: Jim Date: Thu, 20 Apr 2023 08:34:43 -0400 Subject: [PATCH] fix (test): update how we determine when/if a test is running. (#3169) --- internal/test/test.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/internal/test/test.go b/internal/test/test.go index 4a8940f67b..280dcef927 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -5,22 +5,24 @@ package test import ( "flag" - "testing" + "os" + "strings" ) -func init() { - testing.Init() - flag.Parse() -} - // IsTestRun will return whether or not we're operating within the context of a // test. func IsTestRun() bool { // TODO jimlambrt 4/23 -> convert to go 1.21 built-in func when it's // available in boundary: // https://github.com/golang/go/commit/7f38067acb738c43d870400dd648662d31456f5f#diff-b3e6126779b5ec9d3d6cea7cc54054ba78f4d7a0a6248d9e458bbd9b3d72fce3 - - // just check if the test verbose (test.v) has been initialized... we don't - // care about it's value. - return flag.Lookup("test.v") != nil + switch { + case flag.Lookup("test.v") != nil: + return true + case strings.HasSuffix(os.Args[0], ".test"): + return true + case strings.Contains(os.Args[0], "/_test/"): + return true + default: + return false + } }