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