未验证 提交 be300f6a 编写于 作者: LinuxSuRen's avatar LinuxSuRen 提交者: GitHub

Add test cases for user command (#181)

* Add test cases for user command

* Add test cases with error condition

* Add more error conditions
上级 c7434778
package cmd package cmd
import ( import (
"fmt" "net/http"
"log"
"github.com/jenkins-zh/jenkins-cli/client" "github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -11,6 +10,8 @@ import ( ...@@ -11,6 +10,8 @@ import (
// UserOption is the user cmd option // UserOption is the user cmd option
type UserOption struct { type UserOption struct {
OutputOption OutputOption
RoundTripper http.RoundTripper
} }
var userOption UserOption var userOption UserOption
...@@ -24,23 +25,23 @@ var userCmd = &cobra.Command{ ...@@ -24,23 +25,23 @@ var userCmd = &cobra.Command{
Use: "user", Use: "user",
Short: "Print the user of your Jenkins", Short: "Print the user of your Jenkins",
Long: `Print the user of your Jenkins`, Long: `Print the user of your Jenkins`,
Run: func(_ *cobra.Command, _ []string) { Run: func(cmd *cobra.Command, _ []string) {
jenkins := getCurrentJenkinsFromOptionsOrDie() jclient := &client.UserClient{
jclient := &client.UserClient{} JenkinsCore: client.JenkinsCore{
jclient.URL = jenkins.URL RoundTripper: userOption.RoundTripper,
jclient.UserName = jenkins.UserName Debug: rootOptions.Debug,
jclient.Token = jenkins.Token },
jclient.Proxy = jenkins.Proxy }
jclient.ProxyAuth = jenkins.ProxyAuth getCurrentJenkinsAndClient(&(jclient.JenkinsCore))
if status, err := jclient.Get(); err == nil { if status, err := jclient.Get(); err == nil {
if data, err := userOption.Output(status); err == nil { if data, err := userOption.Output(status); err == nil {
fmt.Println(string(data)) cmd.Println(string(data))
} else { } else {
log.Fatal(err) cmd.PrintErrln(err)
} }
} else { } else {
log.Fatal(err) cmd.PrintErrln(err)
} }
}, },
} }
package cmd package cmd
import ( import (
"fmt" "net/http"
"log"
"github.com/jenkins-zh/jenkins-cli/client" "github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -10,6 +9,7 @@ import ( ...@@ -10,6 +9,7 @@ import (
// UserCreateOption is user create cmd option // UserCreateOption is user create cmd option
type UserCreateOption struct { type UserCreateOption struct {
RoundTripper http.RoundTripper
} }
var userCreateOption UserCreateOption var userCreateOption UserCreateOption
...@@ -19,7 +19,7 @@ func init() { ...@@ -19,7 +19,7 @@ func init() {
} }
var userCreateCmd = &cobra.Command{ var userCreateCmd = &cobra.Command{
Use: "create", Use: "create <username>",
Short: "Create a user for your Jenkins", Short: "Create a user for your Jenkins",
Long: `Create a user for your Jenkins`, Long: `Create a user for your Jenkins`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
...@@ -30,18 +30,18 @@ var userCreateCmd = &cobra.Command{ ...@@ -30,18 +30,18 @@ var userCreateCmd = &cobra.Command{
username := args[0] username := args[0]
jenkins := getCurrentJenkinsFromOptionsOrDie() jclient := &client.UserClient{
jclient := &client.UserClient{} JenkinsCore: client.JenkinsCore{
jclient.URL = jenkins.URL RoundTripper: userCreateOption.RoundTripper,
jclient.UserName = jenkins.UserName Debug: rootOptions.Debug,
jclient.Token = jenkins.Token },
jclient.Proxy = jenkins.Proxy }
jclient.ProxyAuth = jenkins.ProxyAuth getCurrentJenkinsAndClient(&(jclient.JenkinsCore))
if user, err := jclient.Create(username); err == nil { if user, err := jclient.Create(username); err == nil {
fmt.Printf("create user success. Password is: %s\n", user.Password1) cmd.Println("create user success. Password is:", user.Password1)
} else { } else {
log.Fatal(err) cmd.PrintErrln(err)
} }
}, },
} }
package cmd
import (
"bytes"
"io/ioutil"
"os"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/spf13/cobra"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/jenkins-zh/jenkins-cli/mock/mhttp"
)
var _ = Describe("user create command", func() {
var (
ctrl *gomock.Controller
roundTripper *mhttp.MockRoundTripper
)
BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
rootCmd.SetArgs([]string{})
rootOptions.Jenkins = ""
rootOptions.ConfigFile = "test.yaml"
})
AfterEach(func() {
rootCmd.SetArgs([]string{})
os.Remove(rootOptions.ConfigFile)
rootOptions.ConfigFile = ""
ctrl.Finish()
})
Context("with http requests", func() {
BeforeEach(func() {
roundTripper = mhttp.NewMockRoundTripper(ctrl)
userCreateOption.RoundTripper = roundTripper
})
It("lack of arguments", func() {
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
userCreateCmd.SetHelpFunc(func(cmd *cobra.Command, _ []string) {
cmd.Print("help")
})
rootCmd.SetArgs([]string{"user", "create"})
_, err := rootCmd.ExecuteC()
Expect(err).To(BeNil())
Expect(buf.String()).To(Equal("help"))
})
It("should success", func() {
data, err := generateSampleConfig()
Expect(err).To(BeNil())
err = ioutil.WriteFile(rootOptions.ConfigFile, data, 0664)
Expect(err).To(BeNil())
targetUserName := "fakename"
client.PrepareCreateUser(roundTripper, "http://localhost:8080/jenkins", "admin", "111e3a2f0231198855dceaff96f20540a9", targetUserName)
rootCmd.SetArgs([]string{"user", "create", targetUserName})
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
_, err = rootCmd.ExecuteC()
Expect(err).To(BeNil())
Expect(buf.String()).NotTo(Equal(""))
})
It("with status code 500", func() {
data, err := generateSampleConfig()
Expect(err).To(BeNil())
err = ioutil.WriteFile(rootOptions.ConfigFile, data, 0664)
Expect(err).To(BeNil())
targetUserName := "fakename"
response := client.PrepareCreateUser(roundTripper, "http://localhost:8080/jenkins", "admin", "111e3a2f0231198855dceaff96f20540a9", targetUserName)
response.StatusCode = 500
rootCmd.SetArgs([]string{"user", "create", targetUserName})
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
_, err = rootCmd.ExecuteC()
Expect(err).To(BeNil())
Expect(buf.String()).To(Equal("unexpected status code: 500\n"))
})
})
})
...@@ -2,7 +2,7 @@ package cmd ...@@ -2,7 +2,7 @@ package cmd
import ( import (
"fmt" "fmt"
"log" "net/http"
"github.com/jenkins-zh/jenkins-cli/client" "github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -11,6 +11,8 @@ import ( ...@@ -11,6 +11,8 @@ import (
// UserDeleteOption is user delete cmd option // UserDeleteOption is user delete cmd option
type UserDeleteOption struct { type UserDeleteOption struct {
BatchOption BatchOption
RoundTripper http.RoundTripper
} }
var userDeleteOption UserDeleteOption var userDeleteOption UserDeleteOption
...@@ -21,7 +23,7 @@ func init() { ...@@ -21,7 +23,7 @@ func init() {
} }
var userDeleteCmd = &cobra.Command{ var userDeleteCmd = &cobra.Command{
Use: "delete", Use: "delete <username>",
Short: "Delete a user for your Jenkins", Short: "Delete a user for your Jenkins",
Long: `Delete a user for your Jenkins`, Long: `Delete a user for your Jenkins`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
...@@ -36,18 +38,16 @@ var userDeleteCmd = &cobra.Command{ ...@@ -36,18 +38,16 @@ var userDeleteCmd = &cobra.Command{
return return
} }
jenkins := getCurrentJenkinsFromOptionsOrDie() jclient := &client.UserClient{
jclient := &client.UserClient{} JenkinsCore: client.JenkinsCore{
jclient.URL = jenkins.URL RoundTripper: userDeleteOption.RoundTripper,
jclient.UserName = jenkins.UserName Debug: rootOptions.Debug,
jclient.Token = jenkins.Token },
jclient.Proxy = jenkins.Proxy }
jclient.ProxyAuth = jenkins.ProxyAuth getCurrentJenkinsAndClient(&(jclient.JenkinsCore))
if err := jclient.Delete(username); err == nil { if err := jclient.Delete(username); err != nil {
fmt.Printf("delete user success.\n") cmd.PrintErrln(err)
} else {
log.Fatal(err)
} }
}, },
} }
package cmd
import (
"bytes"
"io/ioutil"
"os"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/spf13/cobra"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/jenkins-zh/jenkins-cli/mock/mhttp"
)
var _ = Describe("user delete command", func() {
var (
ctrl *gomock.Controller
roundTripper *mhttp.MockRoundTripper
)
BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
rootCmd.SetArgs([]string{})
rootOptions.Jenkins = ""
rootOptions.ConfigFile = "test.yaml"
})
AfterEach(func() {
rootCmd.SetArgs([]string{})
os.Remove(rootOptions.ConfigFile)
rootOptions.ConfigFile = ""
ctrl.Finish()
})
Context("with http requests", func() {
BeforeEach(func() {
roundTripper = mhttp.NewMockRoundTripper(ctrl)
userDeleteOption.RoundTripper = roundTripper
})
It("lack of arguments", func() {
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
userDeleteCmd.SetHelpFunc(func(cmd *cobra.Command, _ []string) {
cmd.Print("help")
})
rootCmd.SetArgs([]string{"user", "delete"})
_, err := rootCmd.ExecuteC()
Expect(err).To(BeNil())
Expect(buf.String()).To(Equal("help"))
})
It("should success", func() {
data, err := generateSampleConfig()
Expect(err).To(BeNil())
err = ioutil.WriteFile(rootOptions.ConfigFile, data, 0664)
Expect(err).To(BeNil())
targetUserName := "fakename"
client.PrepareForDeleteUser(roundTripper, "http://localhost:8080/jenkins", targetUserName, "admin", "111e3a2f0231198855dceaff96f20540a9")
rootCmd.SetArgs([]string{"user", "delete", targetUserName, "-b", "true"})
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
_, err = rootCmd.ExecuteC()
Expect(err).To(BeNil())
Expect(buf.String()).To(Equal(""))
})
It("with status code 500", func() {
data, err := generateSampleConfig()
Expect(err).To(BeNil())
err = ioutil.WriteFile(rootOptions.ConfigFile, data, 0664)
Expect(err).To(BeNil())
targetUserName := "fakename"
response := client.PrepareForDeleteUser(roundTripper, "http://localhost:8080/jenkins", targetUserName, "admin", "111e3a2f0231198855dceaff96f20540a9")
response.StatusCode = 500
rootCmd.SetArgs([]string{"user", "delete", targetUserName, "-b", "true"})
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
_, err = rootCmd.ExecuteC()
Expect(err).To(BeNil())
Expect(buf.String()).To(Equal("unexpected status code: 500\n"))
})
})
})
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("user command", func() {
var (
ctrl *gomock.Controller
roundTripper *mhttp.MockRoundTripper
)
BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
rootCmd.SetArgs([]string{})
rootOptions.Jenkins = ""
rootOptions.ConfigFile = "test.yaml"
})
AfterEach(func() {
rootCmd.SetArgs([]string{})
os.Remove(rootOptions.ConfigFile)
rootOptions.ConfigFile = ""
ctrl.Finish()
})
Context("with http requests", func() {
BeforeEach(func() {
roundTripper = mhttp.NewMockRoundTripper(ctrl)
userOption.RoundTripper = roundTripper
})
It("should success", func() {
data, err := generateSampleConfig()
Expect(err).To(BeNil())
err = ioutil.WriteFile(rootOptions.ConfigFile, data, 0664)
Expect(err).To(BeNil())
client.PrepareGetUser(roundTripper, "http://localhost:8080/jenkins",
"admin", "111e3a2f0231198855dceaff96f20540a9")
rootCmd.SetArgs([]string{"user"})
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
_, err = rootCmd.ExecuteC()
Expect(err).To(BeNil())
Expect(buf.String()).To(Equal("{\n \"absoluteUrl\": \"\",\n \"Description\": \"\",\n \"fullname\": \"admin\",\n \"ID\": \"\"\n}\n"))
})
It("with status code 500", func() {
data, err := generateSampleConfig()
Expect(err).To(BeNil())
err = ioutil.WriteFile(rootOptions.ConfigFile, data, 0664)
Expect(err).To(BeNil())
response := client.PrepareGetUser(roundTripper, "http://localhost:8080/jenkins",
"admin", "111e3a2f0231198855dceaff96f20540a9")
response.StatusCode = 500
rootCmd.SetArgs([]string{"user"})
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
_, err = rootCmd.ExecuteC()
Expect(err).To(BeNil())
Expect(buf.String()).To(Equal("unexpected status code: 500\n"))
})
})
})
package cmd package cmd
import ( import (
"fmt" "net/http"
"log"
"github.com/jenkins-zh/jenkins-cli/client" "github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -12,6 +11,8 @@ import ( ...@@ -12,6 +11,8 @@ import (
type UserTokenOption struct { type UserTokenOption struct {
Generate bool Generate bool
Name string Name string
RoundTripper http.RoundTripper
} }
var userTokenOption UserTokenOption var userTokenOption UserTokenOption
...@@ -23,7 +24,7 @@ func init() { ...@@ -23,7 +24,7 @@ func init() {
} }
var userTokenCmd = &cobra.Command{ var userTokenCmd = &cobra.Command{
Use: "token", Use: "token -g",
Short: "Token the user of your Jenkins", Short: "Token the user of your Jenkins",
Long: `Token the user of your Jenkins`, Long: `Token the user of your Jenkins`,
Run: func(cmd *cobra.Command, _ []string) { Run: func(cmd *cobra.Command, _ []string) {
...@@ -32,24 +33,24 @@ var userTokenCmd = &cobra.Command{ ...@@ -32,24 +33,24 @@ var userTokenCmd = &cobra.Command{
return return
} }
jenkins := getCurrentJenkinsFromOptionsOrDie() jclient := &client.UserClient{
jclient := &client.UserClient{} JenkinsCore: client.JenkinsCore{
jclient.URL = jenkins.URL RoundTripper: userTokenOption.RoundTripper,
jclient.UserName = jenkins.UserName Debug: rootOptions.Debug,
jclient.Token = jenkins.Token },
jclient.Proxy = jenkins.Proxy }
jclient.ProxyAuth = jenkins.ProxyAuth getCurrentJenkinsAndClient(&(jclient.JenkinsCore))
tokenName := userTokenOption.Name tokenName := userTokenOption.Name
if status, err := jclient.CreateToken(tokenName); err == nil { if status, err := jclient.CreateToken(tokenName); err == nil {
var data []byte var data []byte
if data, err = userOption.Output(status); err == nil { if data, err = userOption.Output(status); err == nil {
fmt.Printf("%s\n", string(data)) cmd.Println(string(data))
} else { } else {
log.Fatal(err) cmd.PrintErrln(err)
} }
} else { } else {
log.Fatal(err) cmd.PrintErrln(err)
} }
}, },
} }
package cmd
import (
"bytes"
"io/ioutil"
"os"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/spf13/cobra"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/jenkins-zh/jenkins-cli/mock/mhttp"
)
var _ = Describe("user token command", func() {
var (
ctrl *gomock.Controller
roundTripper *mhttp.MockRoundTripper
)
BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
rootCmd.SetArgs([]string{})
rootOptions.Jenkins = ""
rootOptions.ConfigFile = "test.yaml"
})
AfterEach(func() {
rootCmd.SetArgs([]string{})
os.Remove(rootOptions.ConfigFile)
rootOptions.ConfigFile = ""
ctrl.Finish()
})
Context("with http requests", func() {
BeforeEach(func() {
roundTripper = mhttp.NewMockRoundTripper(ctrl)
userTokenOption.RoundTripper = roundTripper
})
It("lack of arguments", func() {
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
userTokenCmd.SetHelpFunc(func(cmd *cobra.Command, _ []string) {
cmd.Print("help")
})
rootCmd.SetArgs([]string{"user", "token"})
_, err := rootCmd.ExecuteC()
Expect(err).To(BeNil())
Expect(buf.String()).To(Equal("help"))
})
It("should success", func() {
data, err := generateSampleConfig()
Expect(err).To(BeNil())
err = ioutil.WriteFile(rootOptions.ConfigFile, data, 0664)
Expect(err).To(BeNil())
tokenName := "fakename"
client.PrepareCreateToken(roundTripper, "http://localhost:8080/jenkins",
"admin", "111e3a2f0231198855dceaff96f20540a9", tokenName)
rootCmd.SetArgs([]string{"user", "token", "-g", "-n", tokenName})
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
_, err = rootCmd.ExecuteC()
Expect(err).To(BeNil())
Expect(buf.String()).To(Equal("{\n \"Status\": \"ok\",\n \"Data\": {\n \"TokenName\": \"\",\n \"TokenUUID\": \"\",\n \"TokenValue\": \"\"\n }\n}\n"))
})
It("with status code 500", func() {
data, err := generateSampleConfig()
Expect(err).To(BeNil())
err = ioutil.WriteFile(rootOptions.ConfigFile, data, 0664)
Expect(err).To(BeNil())
tokenName := "fakename"
response := client.PrepareCreateToken(roundTripper, "http://localhost:8080/jenkins",
"admin", "111e3a2f0231198855dceaff96f20540a9", tokenName)
response.StatusCode = 500
rootCmd.SetArgs([]string{"user", "token", "-g", "-n", tokenName})
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
_, err = rootCmd.ExecuteC()
Expect(err).To(BeNil())
Expect(buf.String()).To(Equal("unexpected status code: 500\n"))
})
})
})
...@@ -482,24 +482,6 @@ func PrepareForCreatePipelineJob(roundTripper *mhttp.MockRoundTripper, rootURL, ...@@ -482,24 +482,6 @@ func PrepareForCreatePipelineJob(roundTripper *mhttp.MockRoundTripper, rootURL,
return return
} }
// PrepareForEditUserDesc only for test
func PrepareForEditUserDesc(roundTripper *mhttp.MockRoundTripper, rootURL, userName, description, user, passwd string) {
formData := url.Values{}
formData.Add("description", description)
payload := strings.NewReader(formData.Encode())
request, _ := http.NewRequest("POST", fmt.Sprintf("%s/user/%s/submitDescription", rootURL, userName), payload)
PrepareCommonPost(request, roundTripper, user, passwd, rootURL)
return
}
// PrepareForDeleteUser only for test
func PrepareForDeleteUser(roundTripper *mhttp.MockRoundTripper, rootURL, userName, user, passwd string) {
request, _ := http.NewRequest("POST", fmt.Sprintf("%s/securityRealm/user/%s/doDelete", rootURL, userName), nil)
PrepareCommonPost(request, roundTripper, user, passwd, rootURL)
return
}
// PrepareCommonPost only for test // PrepareCommonPost only for test
func PrepareCommonPost(request *http.Request, roundTripper *mhttp.MockRoundTripper, user, passwd, rootURL string) ( func PrepareCommonPost(request *http.Request, roundTripper *mhttp.MockRoundTripper, user, passwd, rootURL string) (
response *http.Response) { response *http.Response) {
......
...@@ -11,9 +11,10 @@ import ( ...@@ -11,9 +11,10 @@ import (
) )
// PrepareGetUser only for test // PrepareGetUser only for test
func PrepareGetUser(roundTripper *mhttp.MockRoundTripper, rootURL, user, passwd string) { func PrepareGetUser(roundTripper *mhttp.MockRoundTripper, rootURL, user, passwd string) (
response *http.Response) {
request, _ := http.NewRequest("GET", fmt.Sprintf("%s/user/%s/api/json", rootURL, user), nil) request, _ := http.NewRequest("GET", fmt.Sprintf("%s/user/%s/api/json", rootURL, user), nil)
response := &http.Response{ response = &http.Response{
StatusCode: 200, StatusCode: 200,
Request: request, Request: request,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"fullName":"admin"}`)), Body: ioutil.NopCloser(bytes.NewBufferString(`{"fullName":"admin"}`)),
...@@ -29,22 +30,43 @@ func PrepareGetUser(roundTripper *mhttp.MockRoundTripper, rootURL, user, passwd ...@@ -29,22 +30,43 @@ func PrepareGetUser(roundTripper *mhttp.MockRoundTripper, rootURL, user, passwd
// PrepareCreateUser only for test // PrepareCreateUser only for test
func PrepareCreateUser(roundTripper *mhttp.MockRoundTripper, rootURL, func PrepareCreateUser(roundTripper *mhttp.MockRoundTripper, rootURL,
user, passwd, targetUserName string) { user, passwd, targetUserName string) (response *http.Response) {
payload, _ := genSimpleUserAsPayload(targetUserName) payload, _ := genSimpleUserAsPayload(targetUserName)
request, _ := http.NewRequest("POST", fmt.Sprintf("%s/securityRealm/createAccountByAdmin", rootURL), payload) request, _ := http.NewRequest("POST", fmt.Sprintf("%s/securityRealm/createAccountByAdmin", rootURL), payload)
PrepareCommonPost(request, roundTripper, user, passwd, rootURL) response = PrepareCommonPost(request, roundTripper, user, passwd, rootURL)
return
} }
// PrepareCreateToken only for test // PrepareCreateToken only for test
func PrepareCreateToken(roundTripper *mhttp.MockRoundTripper, rootURL, func PrepareCreateToken(roundTripper *mhttp.MockRoundTripper, rootURL,
user, passwd, newTokenName string) { user, passwd, newTokenName string) (response *http.Response) {
formData := url.Values{} formData := url.Values{}
formData.Add("newTokenName", newTokenName) formData.Add("newTokenName", newTokenName)
payload := strings.NewReader(formData.Encode()) payload := strings.NewReader(formData.Encode())
request, _ := http.NewRequest("POST", fmt.Sprintf("%s/user/%s/descriptorByName/jenkins.security.ApiTokenProperty/generateNewToken", rootURL, user), payload) request, _ := http.NewRequest("POST", fmt.Sprintf("%s/user/%s/descriptorByName/jenkins.security.ApiTokenProperty/generateNewToken", rootURL, user), payload)
response := PrepareCommonPost(request, roundTripper, user, passwd, rootURL) response = PrepareCommonPost(request, roundTripper, user, passwd, rootURL)
response.Body = ioutil.NopCloser(bytes.NewBufferString(` response.Body = ioutil.NopCloser(bytes.NewBufferString(`
{"status":"ok"} {"status":"ok"}
`)) `))
return
}
// PrepareForEditUserDesc only for test
func PrepareForEditUserDesc(roundTripper *mhttp.MockRoundTripper, rootURL, userName, description, user, passwd string) {
formData := url.Values{}
formData.Add("description", description)
payload := strings.NewReader(formData.Encode())
request, _ := http.NewRequest("POST", fmt.Sprintf("%s/user/%s/submitDescription", rootURL, userName), payload)
PrepareCommonPost(request, roundTripper, user, passwd, rootURL)
return
}
// PrepareForDeleteUser only for test
func PrepareForDeleteUser(roundTripper *mhttp.MockRoundTripper, rootURL, userName, user, passwd string) (
response *http.Response) {
request, _ := http.NewRequest("POST", fmt.Sprintf("%s/securityRealm/user/%s/doDelete", rootURL, userName), nil)
response = PrepareCommonPost(request, roundTripper, user, passwd, rootURL)
return
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册