From 0ae2d2b3ab43eea1c96511833dbea8e9c3119c11 Mon Sep 17 00:00:00 2001 From: Denton Gentry Date: Sat, 3 Jul 2021 15:18:18 -0700 Subject: [PATCH] hostinfo: detect TestCase environment. Treat automated tests as their own, unique environment rather than the type of container they are running in. Signed-off-by: Denton Gentry --- hostinfo/hostinfo.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hostinfo/hostinfo.go b/hostinfo/hostinfo.go index 3293692fc..9f4099e61 100644 --- a/hostinfo/hostinfo.go +++ b/hostinfo/hostinfo.go @@ -9,6 +9,7 @@ package hostinfo import ( + "flag" "io" "os" "runtime" @@ -27,6 +28,7 @@ const ( AWSLambda = EnvType("lm") Heroku = EnvType("hr") AzureAppService = EnvType("az") + TestCase = EnvType("tc") ) var envType atomic.Value // of EnvType @@ -41,6 +43,11 @@ func GetEnvType() EnvType { } func getEnvType() EnvType { + // inTestCase needs to go first. If running tests in a container, we want + // the environment to be TestCase not the type of container. + if inTestCase() { + return TestCase + } if inKnative() { return KNative } @@ -80,6 +87,13 @@ func InContainer() bool { return ret } +func inTestCase() bool { + if flag.CommandLine.Lookup("test.v") != nil { + return true + } + return false +} + func inKnative() bool { // https://cloud.google.com/run/docs/reference/container-contract#env-vars if os.Getenv("K_REVISION") != "" && os.Getenv("K_CONFIGURATION") != "" &&