mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
911d4bc770
* Make sonarExecuteScan orchestrator-agnostic
* Increase coverage + support empty or false env vars
* Use cleared env for unit tests
* Refactor to standalone package
* Fix review findings
* Fix review findings
* Fix unit test
* Add logging
* Refactor
* Add to codeowners 😎
* Apply suggestions from code review
* Remove unreachable code
* no message
* fix typos
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
41 lines
949 B
Go
41 lines
949 B
Go
package orchestrator
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTravis(t *testing.T) {
|
|
t.Run("BranchBuild", func(t *testing.T) {
|
|
defer resetEnv(os.Environ())
|
|
os.Clearenv()
|
|
os.Setenv("TRAVIS", "true")
|
|
os.Setenv("TRAVIS_BRANCH", "feat/test-travis")
|
|
os.Setenv("TRAVIS_PULL_REQUEST", "false")
|
|
|
|
p, _ := NewOrchestratorSpecificConfigProvider()
|
|
c := p.GetBranchBuildConfig()
|
|
|
|
assert.False(t, p.IsPullRequest())
|
|
assert.Equal(t, "feat/test-travis", c.Branch)
|
|
})
|
|
|
|
t.Run("PR", func(t *testing.T) {
|
|
defer resetEnv(os.Environ())
|
|
os.Clearenv()
|
|
os.Setenv("TRAVIS_PULL_REQUEST_BRANCH", "feat/test-travis")
|
|
os.Setenv("TRAVIS_BRANCH", "main")
|
|
os.Setenv("TRAVIS_PULL_REQUEST", "42")
|
|
|
|
p := TravisConfigProvider{}
|
|
c := p.GetPullRequestConfig()
|
|
|
|
assert.True(t, p.IsPullRequest())
|
|
assert.Equal(t, "feat/test-travis", c.Branch)
|
|
assert.Equal(t, "main", c.Base)
|
|
assert.Equal(t, "42", c.Key)
|
|
})
|
|
}
|