Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Jenkins 中文社区
jenkins-cli
提交
e5f8e59c
J
jenkins-cli
项目概览
Jenkins 中文社区
/
jenkins-cli
通知
49
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins-cli
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
e5f8e59c
编写于
8月 28, 2019
作者:
Y
Yanjun Shi
提交者:
GitHub
8月 28, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #128 from LinuxSuRen/add-test-cases
Add more testcases
上级
71b3d05d
4a57ff3d
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
205 addition
and
11 deletion
+205
-11
README-zh.md
README-zh.md
+1
-0
README.md
README.md
+1
-0
app/cmd/config_test.go
app/cmd/config_test.go
+55
-0
app/cmd/plugin_upload.go
app/cmd/plugin_upload.go
+1
-1
app/cmd/root.go
app/cmd/root.go
+11
-8
app/cmd/root_test.go
app/cmd/root_test.go
+114
-2
sonar-project.properties
sonar-project.properties
+2
-0
util/table_test.go
util/table_test.go
+20
-0
未找到文件。
README-zh.md
浏览文件 @
e5f8e59c
# Jenkins CLI
# Jenkins CLI
[
![Go Report Card
](
https://goreportcard.com/badge/jenkins-zh/jenkins-cli
)
](https://goreportcard.com/report/jenkins-zh/jenkins-cli)
[
![Go Report Card
](
https://goreportcard.com/badge/jenkins-zh/jenkins-cli
)
](https://goreportcard.com/report/jenkins-zh/jenkins-cli)
[
![Quality Gate Status
](
https://sonarcloud.io/api/project_badges/measure?project=jenkins-zh_jenkins-cli&metric=alert_status
)
](https://sonarcloud.io/dashboard?id=jenkins-zh_jenkins-cli)
Jenkins CLI 可以帮忙你轻松地管理 Jenkins。不管你是一名插件开发者、管理员或者只是一个普通的 Jenkins 用户,它都是为你而生的!
Jenkins CLI 可以帮忙你轻松地管理 Jenkins。不管你是一名插件开发者、管理员或者只是一个普通的 Jenkins 用户,它都是为你而生的!
...
...
README.md
浏览文件 @
e5f8e59c
# Jenkins CLI
# Jenkins CLI
[
![Go Report Card
](
https://goreportcard.com/badge/jenkins-zh/jenkins-cli
)
](https://goreportcard.com/report/jenkins-zh/jenkins-cli)
[
![Go Report Card
](
https://goreportcard.com/badge/jenkins-zh/jenkins-cli
)
](https://goreportcard.com/report/jenkins-zh/jenkins-cli)
[
![Quality Gate Status
](
https://sonarcloud.io/api/project_badges/measure?project=jenkins-zh_jenkins-cli&metric=alert_status
)
](https://sonarcloud.io/dashboard?id=jenkins-zh_jenkins-cli)
Jenkins CLI allows you manage your Jenkins as an easy way. No matter you're a plugin
Jenkins CLI allows you manage your Jenkins as an easy way. No matter you're a plugin
developer, administrator or just a regular user, it borns for you!
developer, administrator or just a regular user, it borns for you!
...
...
app/cmd/config_test.go
0 → 100644
浏览文件 @
e5f8e59c
package
cmd
import
(
"github.com/golang/mock/gomock"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
)
var
_
=
Describe
(
"Table util test"
,
func
()
{
var
(
ctrl
*
gomock
.
Controller
)
BeforeEach
(
func
()
{
ctrl
=
gomock
.
NewController
(
GinkgoT
())
config
=
nil
})
AfterEach
(
func
()
{
config
=
nil
ctrl
.
Finish
()
})
Context
(
"basic test"
,
func
()
{
It
(
"getJenkinsNames"
,
func
()
{
config
=
&
Config
{
JenkinsServers
:
[]
JenkinsServer
{
JenkinsServer
{
Name
:
"a"
,
},
JenkinsServer
{
Name
:
"b"
,
}},
}
names
:=
getJenkinsNames
()
Expect
(
names
)
.
To
(
Equal
([]
string
{
"a"
,
"b"
}))
config
.
JenkinsServers
=
[]
JenkinsServer
{}
names
=
getJenkinsNames
()
Expect
(
names
)
.
To
(
Equal
([]
string
{}))
})
It
(
"getCurrentJenkins"
,
func
()
{
config
=
&
Config
{}
current
:=
getCurrentJenkins
()
Expect
(
current
)
.
To
(
BeNil
())
config
.
Current
=
"test"
config
.
JenkinsServers
=
[]
JenkinsServer
{
JenkinsServer
{
Name
:
"test"
,
}}
current
=
getCurrentJenkins
()
Expect
(
current
)
.
To
(
Equal
(
&
config
.
JenkinsServers
[
0
]))
})
})
})
app/cmd/plugin_upload.go
浏览文件 @
e5f8e59c
...
@@ -70,7 +70,7 @@ var pluginUploadCmd = &cobra.Command{
...
@@ -70,7 +70,7 @@ var pluginUploadCmd = &cobra.Command{
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
}
}
}
else
if
len
(
args
)
==
0
{
}
else
if
len
(
args
)
==
0
{
executePreCmd
(
cmd
,
args
)
executePreCmd
(
cmd
,
args
,
os
.
Stdout
)
path
,
_
:=
os
.
Getwd
()
path
,
_
:=
os
.
Getwd
()
dirName
:=
filepath
.
Base
(
path
)
dirName
:=
filepath
.
Base
(
path
)
...
...
app/cmd/root.go
浏览文件 @
e5f8e59c
...
@@ -2,6 +2,7 @@ package cmd
...
@@ -2,6 +2,7 @@ package cmd
import
(
import
(
"fmt"
"fmt"
"io"
"log"
"log"
"os"
"os"
"os/exec"
"os/exec"
...
@@ -99,10 +100,10 @@ func getCmdPath(cmd *cobra.Command) string {
...
@@ -99,10 +100,10 @@ func getCmdPath(cmd *cobra.Command) string {
return
""
return
""
}
}
func
executePreCmd
(
cmd
*
cobra
.
Command
,
_
[]
string
)
{
func
executePreCmd
(
cmd
*
cobra
.
Command
,
_
[]
string
,
writer
io
.
Writer
)
(
err
error
)
{
config
:=
getConfig
()
config
:=
getConfig
()
if
config
==
nil
{
if
config
==
nil
{
log
.
Fatal
(
"Cannot find config file"
)
err
=
fmt
.
Errorf
(
"Cannot find config file"
)
return
return
}
}
...
@@ -112,15 +113,17 @@ func executePreCmd(cmd *cobra.Command, _ []string) {
...
@@ -112,15 +113,17 @@ func executePreCmd(cmd *cobra.Command, _ []string) {
continue
continue
}
}
execute
(
preHook
.
Command
)
if
err
=
execute
(
preHook
.
Command
,
writer
);
err
!=
nil
{
return
}
}
}
return
}
}
func
execute
(
command
string
)
{
func
execute
(
command
string
,
writer
io
.
Writer
)
(
err
error
)
{
array
:=
strings
.
Split
(
command
,
" "
)
array
:=
strings
.
Split
(
command
,
" "
)
cmd
:=
exec
.
Command
(
array
[
0
],
array
[
1
:
]
...
)
cmd
:=
exec
.
Command
(
array
[
0
],
array
[
1
:
]
...
)
cmd
.
Stdout
=
os
.
Stdout
cmd
.
Stdout
=
writer
if
err
:=
cmd
.
Run
();
err
!=
nil
{
err
=
cmd
.
Run
()
log
.
Fatal
(
err
)
return
}
}
}
app/cmd/root_test.go
浏览文件 @
e5f8e59c
package
cmd
package
cmd
import
(
import
(
"bytes"
"github.com/golang/mock/gomock"
"github.com/golang/mock/gomock"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
.
"github.com/onsi/gomega"
...
@@ -9,16 +11,22 @@ import (
...
@@ -9,16 +11,22 @@ import (
var
_
=
Describe
(
"Root cmd test"
,
func
()
{
var
_
=
Describe
(
"Root cmd test"
,
func
()
{
var
(
var
(
ctrl
*
gomock
.
Controller
ctrl
*
gomock
.
Controller
rootCmd
*
cobra
.
Command
rootCmd
*
cobra
.
Command
successCmd
string
errorCmd
string
)
)
BeforeEach
(
func
()
{
BeforeEach
(
func
()
{
ctrl
=
gomock
.
NewController
(
GinkgoT
())
ctrl
=
gomock
.
NewController
(
GinkgoT
())
rootCmd
=
&
cobra
.
Command
{
Use
:
"root"
}
rootCmd
=
&
cobra
.
Command
{
Use
:
"root"
}
successCmd
=
"echo 1"
errorCmd
=
"exit 1"
config
=
nil
})
})
AfterEach
(
func
()
{
AfterEach
(
func
()
{
config
=
nil
ctrl
.
Finish
()
ctrl
.
Finish
()
})
})
...
@@ -52,4 +60,108 @@ var _ = Describe("Root cmd test", func() {
...
@@ -52,4 +60,108 @@ var _ = Describe("Root cmd test", func() {
Expect
(
path
)
.
To
(
Equal
(
"sub1.sub2"
))
Expect
(
path
)
.
To
(
Equal
(
"sub1.sub2"
))
})
})
})
})
Context
(
"execute cmd test"
,
func
()
{
It
(
"basic command"
,
func
()
{
var
buf
bytes
.
Buffer
err
:=
execute
(
successCmd
,
&
buf
)
Expect
(
buf
.
String
())
.
To
(
Equal
(
"1
\n
"
))
Expect
(
err
)
.
To
(
BeNil
())
})
It
(
"error command"
,
func
()
{
var
buf
bytes
.
Buffer
err
:=
execute
(
errorCmd
,
&
buf
)
Expect
(
err
)
.
To
(
HaveOccurred
())
})
})
Context
(
"execute pre cmd"
,
func
()
{
It
(
"should error"
,
func
()
{
err
:=
executePreCmd
(
nil
,
nil
,
nil
)
Expect
(
err
)
.
To
(
HaveOccurred
())
})
It
(
"basic use case with one preHook, should success"
,
func
()
{
config
=
&
Config
{
PreHooks
:
[]
PreHook
{
PreHook
{
Path
:
"test"
,
Command
:
successCmd
,
}},
}
rootCmd
:=
&
cobra
.
Command
{}
subCmd
:=
&
cobra
.
Command
{
Use
:
"test"
,
}
rootCmd
.
AddCommand
(
subCmd
)
var
buf
bytes
.
Buffer
err
:=
executePreCmd
(
subCmd
,
nil
,
&
buf
)
Expect
(
err
)
.
To
(
BeNil
())
Expect
(
buf
.
String
())
.
To
(
Equal
(
"1
\n
"
))
})
It
(
"basic use case with many preHooks, should success"
,
func
()
{
config
=
&
Config
{
PreHooks
:
[]
PreHook
{
PreHook
{
Path
:
"test"
,
Command
:
successCmd
,
},
PreHook
{
Path
:
"test"
,
Command
:
"echo 2"
,
},
PreHook
{
Path
:
"fake"
,
Command
:
successCmd
,
}},
}
rootCmd
:=
&
cobra
.
Command
{}
subCmd
:=
&
cobra
.
Command
{
Use
:
"test"
,
}
rootCmd
.
AddCommand
(
subCmd
)
var
buf
bytes
.
Buffer
err
:=
executePreCmd
(
subCmd
,
nil
,
&
buf
)
Expect
(
err
)
.
To
(
BeNil
())
Expect
(
buf
.
String
())
.
To
(
Equal
(
"1
\n
2
\n
"
))
})
It
(
"basic use case without preHooks, should success"
,
func
()
{
config
=
&
Config
{}
rootCmd
:=
&
cobra
.
Command
{}
subCmd
:=
&
cobra
.
Command
{
Use
:
"test"
,
}
rootCmd
.
AddCommand
(
subCmd
)
var
buf
bytes
.
Buffer
err
:=
executePreCmd
(
subCmd
,
nil
,
&
buf
)
Expect
(
err
)
.
To
(
BeNil
())
Expect
(
buf
.
String
())
.
To
(
Equal
(
""
))
})
It
(
"basic use case with error command, should success"
,
func
()
{
config
=
&
Config
{
PreHooks
:
[]
PreHook
{
PreHook
{
Path
:
"test"
,
Command
:
errorCmd
,
}},
}
rootCmd
:=
&
cobra
.
Command
{}
subCmd
:=
&
cobra
.
Command
{
Use
:
"test"
,
}
rootCmd
.
AddCommand
(
subCmd
)
var
buf
bytes
.
Buffer
err
:=
executePreCmd
(
subCmd
,
nil
,
&
buf
)
Expect
(
err
)
.
To
(
HaveOccurred
())
})
})
})
})
sonar-project.properties
浏览文件 @
e5f8e59c
...
@@ -9,3 +9,5 @@ sonar.sources=.
...
@@ -9,3 +9,5 @@ sonar.sources=.
# Encoding of the source code. Default is default system encoding
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
#sonar.sourceEncoding=UTF-8
sonar.go.exclusions
=
**/vendor/**,**/**/*_test.go
util/table_test.go
浏览文件 @
e5f8e59c
...
@@ -106,4 +106,24 @@ var _ = Describe("Table util test", func() {
...
@@ -106,4 +106,24 @@ var _ = Describe("Table util test", func() {
Expect
(
buffer
.
String
())
.
To
(
Equal
(
comp
))
Expect
(
buffer
.
String
())
.
To
(
Equal
(
comp
))
})
})
})
})
Context
(
"basic function"
,
func
()
{
It
(
"shoud success"
,
func
()
{
var
buffer
bytes
.
Buffer
table
:=
CreateTable
(
&
buffer
)
table
.
Render
()
Expect
(
buffer
.
String
())
.
To
(
Equal
(
""
))
table
.
AddRow
(
"fake"
)
buffer
.
Reset
()
table
.
Render
()
Expect
(
buffer
.
String
())
.
To
(
Equal
(
"fake
\n
"
))
table
.
Clear
()
buffer
.
Reset
()
table
.
Render
()
Expect
(
buffer
.
String
())
.
To
(
Equal
(
""
))
})
})
})
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录