Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
KubeSphere
kubesphere
提交
af471bce
K
kubesphere
项目概览
KubeSphere
/
kubesphere
通知
138
Star
32
Fork
5
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
af471bce
编写于
11月 24, 2020
作者:
LinuxSuRen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add unit test cases for gitlab multi-branch pipeline
Signed-off-by:
rick
<
rick@jenkins-zh.cn
>
上级
52c6f5f4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
106 addition
and
12 deletion
+106
-12
pkg/simple/client/devops/jenkins/internal/gitlab.go
pkg/simple/client/devops/jenkins/internal/gitlab.go
+3
-10
pkg/simple/client/devops/jenkins/pipeline_internal_test.go
pkg/simple/client/devops/jenkins/pipeline_internal_test.go
+103
-2
未找到文件。
pkg/simple/client/devops/jenkins/internal/gitlab.go
浏览文件 @
af471bce
...
...
@@ -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
(
"
repo
Owner"
);
repoOwner
!=
nil
{
if
repoOwner
:=
source
.
SelectElement
(
"
project
Owner"
);
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
{
...
...
pkg/simple/client/devops/jenkins/pipeline_internal_test.go
浏览文件 @
af471bce
...
...
@@ -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
(
"
\n
input [%+v]
\n
output [%+v]
\n
should 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
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录