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:
parent
bcb76eff06
commit
84c3cd399d
@ -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
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user