1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

fix: orchestrator detection (#2886)

* Fix Orchestrator detection

* Add unit tests

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
This commit is contained in:
Marc Bormeth 2021-06-10 23:47:38 +02:00 committed by GitHub
parent bcb76eff06
commit 84c3cd399d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 3 deletions

View File

@ -67,11 +67,12 @@ func (o Orchestrator) String() string {
}
func areIndicatingEnvVarsSet(envVars []string) bool {
found := false
for _, v := range envVars {
found = truthy(v)
if truthy(v) {
return true
}
}
return found
return false
}
// Checks if var is set and neither empty nor false

View File

@ -27,4 +27,30 @@ func TestOrchestrator(t *testing.T) {
assert.Equal(t, "AzureDevOps", o.String())
})
t.Run("Test areIndicatingEnvVarsSet", func(t *testing.T) {
defer resetEnv(os.Environ())
os.Clearenv()
envVars := []string{"GITHUB_ACTION", "GITHUB_ACTIONS"}
os.Setenv("GITHUB_ACTION", "true")
tmp := areIndicatingEnvVarsSet(envVars)
assert.True(t, tmp)
os.Unsetenv("GITHUB_ACTION")
os.Setenv("GITHUB_ACTIONS", "true")
tmp = areIndicatingEnvVarsSet(envVars)
assert.True(t, tmp)
os.Setenv("GITHUB_ACTION", "1")
os.Setenv("GITHUB_ACTIONS", "false")
tmp = areIndicatingEnvVarsSet(envVars)
assert.True(t, tmp)
os.Setenv("GITHUB_ACTION", "false")
os.Setenv("GITHUB_ACTIONS", "0")
tmp = areIndicatingEnvVarsSet(envVars)
assert.False(t, tmp)
})
}