Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins-cli
提交
65acba59
J
jenkins-cli
项目概览
LinuxSuRen
/
jenkins-cli
与 Fork 源项目一致
Fork自
Jenkins 中文社区 / jenkins-cli
通知
1
Star
0
Fork
0
代码
文件
提交
分支
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 搜索 >>
提交
65acba59
编写于
8月 27, 2019
作者:
LinuxSuRen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add more testcases
上级
33900add
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
99 addition
and
9 deletion
+99
-9
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
+87
-0
未找到文件。
app/cmd/plugin_upload.go
浏览文件 @
65acba59
...
@@ -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
浏览文件 @
65acba59
...
@@ -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
浏览文件 @
65acba59
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"
...
@@ -52,4 +54,89 @@ var _ = Describe("Root cmd test", func() {
...
@@ -52,4 +54,89 @@ 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
(
"echo 1"
,
&
buf
)
Expect
(
buf
.
String
())
.
To
(
Equal
(
"1
\n
"
))
Expect
(
err
)
.
To
(
BeNil
())
})
It
(
"error command"
,
func
()
{
var
buf
bytes
.
Buffer
err
:=
execute
(
"exit 1"
,
&
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
:
"echo 1"
,
}},
}
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
:
"echo 1"
,
},
PreHook
{
Path
:
"test"
,
Command
:
"echo 2"
,
},
PreHook
{
Path
:
"fake"
,
Command
:
"echo 1"
,
}},
}
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
(
""
))
})
})
})
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录