Add unit test cases for gitlab multi-branch pipeline
Signed-off-by: rick <rick@jenkins-zh.cn>
This commit is contained in:
@@ -11,13 +11,10 @@ func AppendGitlabSourceToEtree(source *etree.Element, gitSource *devopsv1alpha3.
|
||||
source.CreateAttr("class", "io.jenkins.plugins.gitlabbranchsource.GitLabSCMSource")
|
||||
source.CreateAttr("plugin", "gitlab-branch-source")
|
||||
source.CreateElement("id").SetText(gitSource.ScmId)
|
||||
source.CreateElement("gitlab-7069").SetText(gitSource.ServerName)
|
||||
source.CreateElement("serverName").SetText(gitSource.ServerName)
|
||||
source.CreateElement("credentialsId").SetText(gitSource.CredentialId)
|
||||
source.CreateElement("projectOwner").SetText(gitSource.Owner)
|
||||
source.CreateElement("projectPath").SetText(gitSource.Repo)
|
||||
if gitSource.ApiUri != "" {
|
||||
source.CreateElement("apiUri").SetText(gitSource.ApiUri)
|
||||
}
|
||||
traits := source.CreateElement("traits")
|
||||
if gitSource.DiscoverBranches != 0 {
|
||||
traits.CreateElement("io.jenkins.plugins.gitlabbranchsource.BranchDiscoveryTrait").
|
||||
@@ -43,7 +40,6 @@ func AppendGitlabSourceToEtree(source *etree.Element, gitSource *devopsv1alpha3.
|
||||
trustClass += "TrustPermission"
|
||||
case 4:
|
||||
trustClass += "TrustNobody"
|
||||
default:
|
||||
}
|
||||
forkTrait.CreateElement("trust").CreateAttr("class", trustClass)
|
||||
}
|
||||
@@ -82,15 +78,12 @@ func GetGitlabSourceFromEtree(source *etree.Element) (gitSource *devopsv1alpha3.
|
||||
if serverName := source.SelectElement("serverName"); serverName != nil {
|
||||
gitSource.ServerName = serverName.Text()
|
||||
}
|
||||
if repoOwner := source.SelectElement("repoOwner"); repoOwner != nil {
|
||||
if repoOwner := source.SelectElement("projectOwner"); repoOwner != nil {
|
||||
gitSource.Owner = repoOwner.Text()
|
||||
}
|
||||
if repository := source.SelectElement("repository"); repository != nil {
|
||||
if repository := source.SelectElement("projectPath"); repository != nil {
|
||||
gitSource.Repo = repository.Text()
|
||||
}
|
||||
if apiUri := source.SelectElement("apiUri"); apiUri != nil {
|
||||
gitSource.ApiUri = apiUri.Text()
|
||||
}
|
||||
traits := source.SelectElement("traits")
|
||||
if branchDiscoverTrait := traits.SelectElement(
|
||||
"io.jenkins.plugins.gitlabbranchsource.BranchDiscoveryTrait"); branchDiscoverTrait != nil {
|
||||
|
||||
@@ -250,6 +250,13 @@ func Test_MultiBranchPipelineConfig(t *testing.T) {
|
||||
SourceType: "svn",
|
||||
SvnSource: &devopsv1alpha3.SvnSource{},
|
||||
},
|
||||
{
|
||||
Name: "",
|
||||
Description: "for test",
|
||||
ScriptPath: "Jenkinsfile",
|
||||
SourceType: "gitlab",
|
||||
GitlabSource: &devopsv1alpha3.GitlabSource{},
|
||||
},
|
||||
}
|
||||
for _, input := range inputs {
|
||||
outputString, err := createMultiBranchPipelineConfigXml("", input)
|
||||
@@ -365,6 +372,73 @@ func Test_MultiBranchPipelineConfig_Source(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "",
|
||||
Description: "for test",
|
||||
ScriptPath: "Jenkinsfile",
|
||||
SourceType: "gitlab",
|
||||
TimerTrigger: &devopsv1alpha3.TimerTrigger{
|
||||
Interval: "12345566",
|
||||
},
|
||||
GitlabSource: &devopsv1alpha3.GitlabSource{
|
||||
Owner: "kubesphere",
|
||||
Repo: "devops",
|
||||
CredentialId: "gitlab",
|
||||
ServerName: "default-gitlab",
|
||||
DiscoverBranches: 1,
|
||||
DiscoverPRFromOrigin: 2,
|
||||
DiscoverTags: true,
|
||||
DiscoverPRFromForks: &devopsv1alpha3.DiscoverPRFromForks{
|
||||
Strategy: 1,
|
||||
Trust: 1,
|
||||
},
|
||||
CloneOption: &devopsv1alpha3.GitCloneOption{
|
||||
Timeout: 10,
|
||||
Depth: 10,
|
||||
},
|
||||
RegexFilter: "*-dev",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "",
|
||||
Description: "for test",
|
||||
ScriptPath: "Jenkinsfile",
|
||||
SourceType: "gitlab",
|
||||
GitlabSource: &devopsv1alpha3.GitlabSource{
|
||||
DiscoverPRFromForks: &devopsv1alpha3.DiscoverPRFromForks{
|
||||
Strategy: 1,
|
||||
Trust: 2,
|
||||
},
|
||||
//CloneOption: &devopsv1alpha3.GitCloneOption{
|
||||
// Depth: -1,
|
||||
// Timeout: -1,
|
||||
//},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "",
|
||||
Description: "for test",
|
||||
ScriptPath: "Jenkinsfile",
|
||||
SourceType: "gitlab",
|
||||
GitlabSource: &devopsv1alpha3.GitlabSource{
|
||||
DiscoverPRFromForks: &devopsv1alpha3.DiscoverPRFromForks{
|
||||
Strategy: 1,
|
||||
Trust: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "",
|
||||
Description: "for test",
|
||||
ScriptPath: "Jenkinsfile",
|
||||
SourceType: "gitlab",
|
||||
GitlabSource: &devopsv1alpha3.GitlabSource{
|
||||
DiscoverPRFromForks: &devopsv1alpha3.DiscoverPRFromForks{
|
||||
Strategy: 1,
|
||||
Trust: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "",
|
||||
Description: "for test",
|
||||
@@ -428,7 +502,7 @@ func Test_MultiBranchPipelineConfig_Source(t *testing.T) {
|
||||
t.Fatalf("should not get error %+v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(input, output) {
|
||||
t.Fatalf("input [%+v] output [%+v] should equal ", input, output)
|
||||
t.Fatalf("\ninput [%+v] \noutput [%+v] \nshould equal ", input.GitlabSource.CloneOption, output.GitlabSource.CloneOption)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -475,6 +549,22 @@ func Test_MultiBranchPipelineCloneConfig(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "",
|
||||
Description: "for test",
|
||||
ScriptPath: "Jenkinsfile",
|
||||
SourceType: "gitlab",
|
||||
GitlabSource: &devopsv1alpha3.GitlabSource{
|
||||
DiscoverPRFromForks: &devopsv1alpha3.DiscoverPRFromForks{
|
||||
Strategy: 1,
|
||||
Trust: 1,
|
||||
},
|
||||
CloneOption: &devopsv1alpha3.GitCloneOption{
|
||||
Depth: -1,
|
||||
Timeout: -1,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, input := range inputs {
|
||||
@@ -487,8 +577,19 @@ func Test_MultiBranchPipelineCloneConfig(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("should not get error %+v", err)
|
||||
}
|
||||
|
||||
// we'll give it a default value if it's negative
|
||||
if input.GitlabSource != nil && input.GitlabSource.CloneOption != nil {
|
||||
if input.GitlabSource.CloneOption.Timeout < 0 {
|
||||
input.GitlabSource.CloneOption.Timeout = 10
|
||||
}
|
||||
if input.GitlabSource.CloneOption.Depth < 0 {
|
||||
input.GitlabSource.CloneOption.Depth = 1
|
||||
}
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(input, output) {
|
||||
t.Fatalf("input [%+v] output [%+v] should equal ", input, output)
|
||||
t.Fatalf("input [%+v] output [%+v] should equal ", input.GitlabSource, output.GitlabSource)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user