1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-16 11:09:33 +02:00
sap-jenkins-library/pkg/orchestrator/jenkins_test.go
Christopher Fenner 950f4287c2
fix: correct env var name for git branch for Jenkins orchestrator implementation (#3311)
* fix: correct env var name for git branch for Jenkins orchestrator implementation

* fix test case
2021-11-26 12:08:22 +01:00

47 lines
1.2 KiB
Go

package orchestrator
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestJenkins(t *testing.T) {
t.Run("BranchBuild", func(t *testing.T) {
defer resetEnv(os.Environ())
os.Clearenv()
os.Setenv("JENKINS_URL", "FOO BAR BAZ")
os.Setenv("BUILD_URL", "jaas.com/foo/bar/main/42")
os.Setenv("BRANCH_NAME", "main")
os.Setenv("GIT_COMMIT", "abcdef42713")
os.Setenv("GIT_URL", "github.com/foo/bar")
p, _ := NewOrchestratorSpecificConfigProvider()
assert.False(t, p.IsPullRequest())
assert.Equal(t, "jaas.com/foo/bar/main/42", p.GetBuildUrl())
assert.Equal(t, "main", p.GetBranch())
assert.Equal(t, "abcdef42713", p.GetCommit())
assert.Equal(t, "github.com/foo/bar", p.GetRepoUrl())
assert.Equal(t, "Jenkins", p.OrchestratorType())
})
t.Run("PR", func(t *testing.T) {
defer resetEnv(os.Environ())
os.Clearenv()
os.Setenv("BRANCH_NAME", "PR-42")
os.Setenv("CHANGE_BRANCH", "feat/test-jenkins")
os.Setenv("CHANGE_TARGET", "main")
os.Setenv("CHANGE_ID", "42")
p := JenkinsConfigProvider{}
c := p.GetPullRequestConfig()
assert.True(t, p.IsPullRequest())
assert.Equal(t, "feat/test-jenkins", c.Branch)
assert.Equal(t, "main", c.Base)
assert.Equal(t, "42", c.Key)
})
}