Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jenkinsci
sub-group
Jenkins Cli
提交
4675156e
J
Jenkins Cli
项目概览
jenkinsci
/
sub-group
/
Jenkins Cli
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
Jenkins Cli
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4675156e
编写于
9月 04, 2019
作者:
LinuxSuRen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the issue that cannot uninstall pluing
上级
4d136021
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
145 addition
and
57 deletion
+145
-57
app/cmd/plugin_uninstall.go
app/cmd/plugin_uninstall.go
+15
-9
app/cmd/plugin_uninstall_test.go
app/cmd/plugin_uninstall_test.go
+81
-0
client/common_test.go
client/common_test.go
+0
-15
client/pluginManager_test.go
client/pluginManager_test.go
+2
-28
client/pluginManger.go
client/pluginManger.go
+2
-4
client/test_methods.go
client/test_methods.go
+44
-0
sonar-project.properties
sonar-project.properties
+1
-1
未找到文件。
app/cmd/plugin_uninstall.go
浏览文件 @
4675156e
package
cmd
import
(
"
log
"
"
net/http
"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra"
)
// PluginUninstallOption the option of uninstall a plugin
type
PluginUninstallOption
struct
{
RoundTripper
http
.
RoundTripper
}
var
pluginUninstallOption
PluginUninstallOption
func
init
()
{
pluginCmd
.
AddCommand
(
pluginUninstallCmd
)
}
...
...
@@ -24,16 +31,15 @@ var pluginUninstallCmd = &cobra.Command{
pluginName
=
args
[
0
]
jenkins
:=
getCurrentJenkinsFromOptionsOrDie
()
jclient
:=
&
client
.
PluginManager
{}
jclient
.
URL
=
jenkins
.
URL
jclient
.
UserName
=
jenkins
.
UserName
jclient
.
Token
=
jenkins
.
Token
jclient
.
Proxy
=
jenkins
.
Proxy
jclient
.
ProxyAuth
=
jenkins
.
ProxyAuth
jclient
:=
&
client
.
PluginManager
{
JenkinsCore
:
client
.
JenkinsCore
{
RoundTripper
:
pluginUninstallOption
.
RoundTripper
,
},
}
getCurrentJenkinsAndClient
(
&
(
jclient
.
JenkinsCore
))
if
err
:=
jclient
.
UninstallPlugin
(
pluginName
);
err
!=
nil
{
log
.
Fatal
(
err
)
cmd
.
PrintErr
(
err
)
}
},
}
app/cmd/plugin_uninstall_test.go
0 → 100644
浏览文件 @
4675156e
package
cmd
import
(
"bytes"
"io/ioutil"
"os"
"github.com/golang/mock/gomock"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/jenkins-zh/jenkins-cli/mock/mhttp"
)
var
_
=
Describe
(
"plugin uninstall command"
,
func
()
{
var
(
ctrl
*
gomock
.
Controller
roundTripper
*
mhttp
.
MockRoundTripper
pluginName
string
)
BeforeEach
(
func
()
{
ctrl
=
gomock
.
NewController
(
GinkgoT
())
roundTripper
=
mhttp
.
NewMockRoundTripper
(
ctrl
)
pluginUninstallOption
.
RoundTripper
=
roundTripper
rootCmd
.
SetArgs
([]
string
{})
rootOptions
.
Jenkins
=
""
rootOptions
.
ConfigFile
=
"test.yaml"
pluginName
=
"fake"
})
AfterEach
(
func
()
{
rootCmd
.
SetArgs
([]
string
{})
os
.
Remove
(
rootOptions
.
ConfigFile
)
rootOptions
.
ConfigFile
=
""
ctrl
.
Finish
()
})
Context
(
"basic cases"
,
func
()
{
It
(
"should success"
,
func
()
{
data
,
err
:=
generateSampleConfig
()
Expect
(
err
)
.
To
(
BeNil
())
err
=
ioutil
.
WriteFile
(
rootOptions
.
ConfigFile
,
data
,
0664
)
Expect
(
err
)
.
To
(
BeNil
())
request
,
_
,
requestCrumb
,
_
:=
client
.
PrepareForUninstallPlugin
(
roundTripper
,
"http://localhost:8080/jenkins"
,
pluginName
)
request
.
SetBasicAuth
(
"admin"
,
"111e3a2f0231198855dceaff96f20540a9"
)
requestCrumb
.
SetBasicAuth
(
"admin"
,
"111e3a2f0231198855dceaff96f20540a9"
)
rootCmd
.
SetArgs
([]
string
{
"plugin"
,
"uninstall"
,
pluginName
})
buf
:=
new
(
bytes
.
Buffer
)
rootCmd
.
SetOutput
(
buf
)
_
,
err
=
rootCmd
.
ExecuteC
()
Expect
(
err
)
.
To
(
BeNil
())
Expect
(
buf
.
String
())
.
To
(
Equal
(
""
))
})
It
(
"with error"
,
func
()
{
data
,
err
:=
generateSampleConfig
()
Expect
(
err
)
.
To
(
BeNil
())
err
=
ioutil
.
WriteFile
(
rootOptions
.
ConfigFile
,
data
,
0664
)
Expect
(
err
)
.
To
(
BeNil
())
request
,
_
,
requestCrumb
,
_
:=
client
.
PrepareForUninstallPluginWith500
(
roundTripper
,
"http://localhost:8080/jenkins"
,
pluginName
)
request
.
SetBasicAuth
(
"admin"
,
"111e3a2f0231198855dceaff96f20540a9"
)
requestCrumb
.
SetBasicAuth
(
"admin"
,
"111e3a2f0231198855dceaff96f20540a9"
)
rootCmd
.
SetArgs
([]
string
{
"plugin"
,
"uninstall"
,
pluginName
})
buf
:=
new
(
bytes
.
Buffer
)
rootCmd
.
SetOutput
(
buf
)
_
,
err
=
rootCmd
.
ExecuteC
()
Expect
(
err
)
.
To
(
BeNil
())
Expect
(
buf
.
String
())
.
To
(
Equal
(
"unexpected status code: 500"
))
})
})
})
client/common_test.go
浏览文件 @
4675156e
...
...
@@ -141,18 +141,3 @@ var _ = Describe("common test", func() {
})
})
})
// RequestCrumb only for the test case
func
RequestCrumb
(
roundTripper
*
mhttp
.
MockRoundTripper
,
rootURL
string
)
{
requestCrumb
,
_
:=
http
.
NewRequest
(
"GET"
,
fmt
.
Sprintf
(
"%s%s"
,
rootURL
,
"/crumbIssuer/api/json"
),
nil
)
responseCrumb
:=
&
http
.
Response
{
StatusCode
:
200
,
Proto
:
"HTTP/1.1"
,
Request
:
requestCrumb
,
Body
:
ioutil
.
NopCloser
(
bytes
.
NewBufferString
(
`
{"crumbRequestField":"CrumbRequestField","crumb":"Crumb"}
`
)),
}
roundTripper
.
EXPECT
()
.
RoundTrip
(
requestCrumb
)
.
Return
(
responseCrumb
,
nil
)
}
client/pluginManager_test.go
浏览文件 @
4675156e
...
...
@@ -113,48 +113,22 @@ var _ = Describe("PluginManager test", func() {
Context
(
"UninstallPlugin"
,
func
()
{
var
(
api
string
pluginName
string
)
BeforeEach
(
func
()
{
pluginName
=
"fake"
api
=
fmt
.
Sprintf
(
"%s/pluginManager/plugin/%s/uninstall"
,
pluginMgr
.
URL
,
pluginName
)
})
It
(
"normal case, should success"
,
func
()
{
request
,
_
:=
http
.
NewRequest
(
"POST"
,
api
,
nil
)
request
.
Header
.
Add
(
"CrumbRequestField"
,
"Crumb"
)
response
:=
&
http
.
Response
{
StatusCode
:
200
,
Proto
:
"HTTP/1.1"
,
Request
:
request
,
Body
:
ioutil
.
NopCloser
(
bytes
.
NewBufferString
(
""
)),
}
roundTripper
.
EXPECT
()
.
RoundTrip
(
request
)
.
Return
(
response
,
nil
)
// common crumb request
RequestCrumb
(
roundTripper
,
pluginMgr
.
URL
)
PrepareForUninstallPlugin
(
roundTripper
,
pluginMgr
.
URL
,
pluginName
)
err
:=
pluginMgr
.
UninstallPlugin
(
pluginName
)
Expect
(
err
)
.
To
(
BeNil
())
})
It
(
"response with 500"
,
func
()
{
request
,
_
:=
http
.
NewRequest
(
"POST"
,
api
,
nil
)
request
.
Header
.
Add
(
"CrumbRequestField"
,
"Crumb"
)
response
:=
&
http
.
Response
{
StatusCode
:
500
,
Proto
:
"HTTP/1.1"
,
Request
:
request
,
Body
:
ioutil
.
NopCloser
(
bytes
.
NewBufferString
(
""
)),
}
roundTripper
.
EXPECT
()
.
RoundTrip
(
request
)
.
Return
(
response
,
nil
)
// common crumb request
RequestCrumb
(
roundTripper
,
pluginMgr
.
URL
)
PrepareForUninstallPluginWith500
(
roundTripper
,
pluginMgr
.
URL
,
pluginName
)
err
:=
pluginMgr
.
UninstallPlugin
(
pluginName
)
Expect
(
err
)
.
To
(
HaveOccurred
())
...
...
client/pluginManger.go
浏览文件 @
4675156e
...
...
@@ -189,16 +189,14 @@ func (p *PluginManager) InstallPlugin(names []string) (err error) {
// UninstallPlugin uninstall a plugin by name
func
(
p
*
PluginManager
)
UninstallPlugin
(
name
string
)
(
err
error
)
{
api
:=
fmt
.
Sprintf
(
"/pluginManager/plugin/%s/
u
ninstall"
,
name
)
api
:=
fmt
.
Sprintf
(
"/pluginManager/plugin/%s/
doU
ninstall"
,
name
)
var
(
statusCode
int
data
[]
byte
)
if
statusCode
,
data
,
err
=
p
.
Request
(
"POST"
,
api
,
nil
,
nil
);
err
==
nil
{
if
statusCode
==
200
{
fmt
.
Println
(
"uninstall succeed."
)
}
else
{
if
statusCode
!=
200
{
err
=
fmt
.
Errorf
(
"unexpected status code: %d"
,
statusCode
)
if
p
.
Debug
{
ioutil
.
WriteFile
(
"debug.html"
,
data
,
0664
)
...
...
client/test_methods.go
浏览文件 @
4675156e
...
...
@@ -88,3 +88,47 @@ func PrepareFor500InstalledPluginList(roundTripper *mhttp.MockRoundTripper, root
response
.
StatusCode
=
500
return
}
// PrepareForUninstallPlugin only for test
func
PrepareForUninstallPlugin
(
roundTripper
*
mhttp
.
MockRoundTripper
,
rootURL
,
pluginName
string
)
(
request
*
http
.
Request
,
response
*
http
.
Response
,
requestCrumb
*
http
.
Request
,
responseCrumb
*
http
.
Response
)
{
request
,
_
=
http
.
NewRequest
(
"POST"
,
fmt
.
Sprintf
(
"%s/pluginManager/plugin/%s/doUninstall"
,
rootURL
,
pluginName
),
nil
)
request
.
Header
.
Add
(
"CrumbRequestField"
,
"Crumb"
)
response
=
&
http
.
Response
{
StatusCode
:
200
,
Proto
:
"HTTP/1.1"
,
Request
:
request
,
Body
:
ioutil
.
NopCloser
(
bytes
.
NewBufferString
(
""
)),
}
roundTripper
.
EXPECT
()
.
RoundTrip
(
request
)
.
Return
(
response
,
nil
)
// common crumb request
requestCrumb
,
responseCrumb
=
RequestCrumb
(
roundTripper
,
rootURL
)
return
}
// PrepareForUninstallPluginWith500 only for test
func
PrepareForUninstallPluginWith500
(
roundTripper
*
mhttp
.
MockRoundTripper
,
rootURL
,
pluginName
string
)
(
request
*
http
.
Request
,
response
*
http
.
Response
,
requestCrumb
*
http
.
Request
,
responseCrumb
*
http
.
Response
)
{
request
,
response
,
requestCrumb
,
responseCrumb
=
PrepareForUninstallPlugin
(
roundTripper
,
rootURL
,
pluginName
)
response
.
StatusCode
=
500
return
}
// RequestCrumb only for the test case
func
RequestCrumb
(
roundTripper
*
mhttp
.
MockRoundTripper
,
rootURL
string
)
(
requestCrumb
*
http
.
Request
,
responseCrumb
*
http
.
Response
)
{
requestCrumb
,
_
=
http
.
NewRequest
(
"GET"
,
fmt
.
Sprintf
(
"%s%s"
,
rootURL
,
"/crumbIssuer/api/json"
),
nil
)
responseCrumb
=
&
http
.
Response
{
StatusCode
:
200
,
Proto
:
"HTTP/1.1"
,
Request
:
requestCrumb
,
Body
:
ioutil
.
NopCloser
(
bytes
.
NewBufferString
(
`
{"crumbRequestField":"CrumbRequestField","crumb":"Crumb"}
`
)),
}
roundTripper
.
EXPECT
()
.
RoundTrip
(
requestCrumb
)
.
Return
(
responseCrumb
,
nil
)
return
}
sonar-project.properties
浏览文件 @
4675156e
...
...
@@ -10,4 +10,4 @@ sonar.sources=.
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
sonar.go.exclusions
=
**/vendor/**,**/**/*_test.go,
mock/**/**
sonar.go.exclusions
=
**/vendor/**,**/**/*_test.go,
client/test_methods.go
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录