mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-18 20:51:45 +00:00
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>
This commit is contained in:
parent
61622b18fa
commit
0ae2d2b3ab
@ -9,6 +9,7 @@
|
|||||||
package hostinfo
|
package hostinfo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -27,6 +28,7 @@ const (
|
|||||||
AWSLambda = EnvType("lm")
|
AWSLambda = EnvType("lm")
|
||||||
Heroku = EnvType("hr")
|
Heroku = EnvType("hr")
|
||||||
AzureAppService = EnvType("az")
|
AzureAppService = EnvType("az")
|
||||||
|
TestCase = EnvType("tc")
|
||||||
)
|
)
|
||||||
|
|
||||||
var envType atomic.Value // of EnvType
|
var envType atomic.Value // of EnvType
|
||||||
@ -41,6 +43,11 @@ func GetEnvType() EnvType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
if inKnative() {
|
||||||
return KNative
|
return KNative
|
||||||
}
|
}
|
||||||
@ -80,6 +87,13 @@ func InContainer() bool {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func inTestCase() bool {
|
||||||
|
if flag.CommandLine.Lookup("test.v") != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func inKnative() bool {
|
func inKnative() bool {
|
||||||
// https://cloud.google.com/run/docs/reference/container-contract#env-vars
|
// https://cloud.google.com/run/docs/reference/container-contract#env-vars
|
||||||
if os.Getenv("K_REVISION") != "" && os.Getenv("K_CONFIGURATION") != "" &&
|
if os.Getenv("K_REVISION") != "" && os.Getenv("K_CONFIGURATION") != "" &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user