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 <dgentry@tailscale.com>
pull/2429/head
Denton Gentry 3 years ago committed by Denton Gentry
parent 61622b18fa
commit 0ae2d2b3ab

@ -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") != "" &&

Loading…
Cancel
Save