hostinfo: detect TestCase environment.
Treat automated tests as their own, unique environment
rather than the type of container they are running in.
package hostinfo
import (
+ "flag"
"io"
"os"
"runtime"
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") != "" &&
