mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests: Refactor CURLPrefixArgs
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
parent
11ca1d356a
commit
64bc55ef4e
@ -132,32 +132,37 @@ type cURLReq struct {
|
|||||||
ciphers string
|
ciphers string
|
||||||
}
|
}
|
||||||
|
|
||||||
// cURLPrefixArgs builds the beginning of a curl command for a given key
|
// cURLPrefixArgsCluster builds the beginning of a curl command for a given key
|
||||||
// addressed to a random URL in the given cluster.
|
// addressed to a random URL in the given cluster.
|
||||||
func cURLPrefixArgs(clus *etcdProcessCluster, method string, req cURLReq) []string {
|
func cURLPrefixArgsCluster(clus *etcdProcessCluster, method string, req cURLReq) []string {
|
||||||
|
member := clus.procs[rand.Intn(clus.cfg.clusterSize)]
|
||||||
|
clientURL := member.Config().acurl
|
||||||
|
if req.metricsURLScheme != "" {
|
||||||
|
clientURL = member.EndpointsMetrics()[0]
|
||||||
|
}
|
||||||
|
return cURLPrefixArgs(clientURL, clus.cfg.clientTLS, !clus.cfg.noCN, method, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func cURLPrefixArgs(clientURL string, connType clientConnType, CN bool, method string, req cURLReq) []string {
|
||||||
var (
|
var (
|
||||||
cmdArgs = []string{"curl"}
|
cmdArgs = []string{"curl"}
|
||||||
acurl = clus.procs[rand.Intn(clus.cfg.clusterSize)].Config().acurl
|
|
||||||
)
|
)
|
||||||
if req.metricsURLScheme != "https" {
|
if req.metricsURLScheme != "https" {
|
||||||
if req.isTLS {
|
if req.isTLS {
|
||||||
if clus.cfg.clientTLS != clientTLSAndNonTLS {
|
if connType != clientTLSAndNonTLS {
|
||||||
panic("should not use cURLPrefixArgsUseTLS when serving only TLS or non-TLS")
|
panic("should not use cURLPrefixArgsUseTLS when serving only TLS or non-TLS")
|
||||||
}
|
}
|
||||||
cmdArgs = append(cmdArgs, "--cacert", caPath, "--cert", certPath, "--key", privateKeyPath)
|
cmdArgs = append(cmdArgs, "--cacert", caPath, "--cert", certPath, "--key", privateKeyPath)
|
||||||
acurl = toTLS(clus.procs[rand.Intn(clus.cfg.clusterSize)].Config().acurl)
|
clientURL = toTLS(clientURL)
|
||||||
} else if clus.cfg.clientTLS == clientTLS {
|
} else if connType == clientTLS {
|
||||||
if !clus.cfg.noCN {
|
if CN {
|
||||||
cmdArgs = append(cmdArgs, "--cacert", caPath, "--cert", certPath, "--key", privateKeyPath)
|
cmdArgs = append(cmdArgs, "--cacert", caPath, "--cert", certPath, "--key", privateKeyPath)
|
||||||
} else {
|
} else {
|
||||||
cmdArgs = append(cmdArgs, "--cacert", caPath, "--cert", certPath3, "--key", privateKeyPath3)
|
cmdArgs = append(cmdArgs, "--cacert", caPath, "--cert", certPath3, "--key", privateKeyPath3)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if req.metricsURLScheme != "" {
|
ep := clientURL + req.endpoint
|
||||||
acurl = clus.procs[rand.Intn(clus.cfg.clusterSize)].EndpointsMetrics()[0]
|
|
||||||
}
|
|
||||||
ep := acurl + req.endpoint
|
|
||||||
|
|
||||||
if req.username != "" || req.password != "" {
|
if req.username != "" || req.password != "" {
|
||||||
cmdArgs = append(cmdArgs, "-L", "-u", fmt.Sprintf("%s:%s", req.username, req.password), ep)
|
cmdArgs = append(cmdArgs, "-L", "-u", fmt.Sprintf("%s:%s", req.username, req.password), ep)
|
||||||
@ -188,13 +193,13 @@ func cURLPrefixArgs(clus *etcdProcessCluster, method string, req cURLReq) []stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cURLPost(clus *etcdProcessCluster, req cURLReq) error {
|
func cURLPost(clus *etcdProcessCluster, req cURLReq) error {
|
||||||
return spawnWithExpect(cURLPrefixArgs(clus, "POST", req), req.expected)
|
return spawnWithExpect(cURLPrefixArgsCluster(clus, "POST", req), req.expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cURLPut(clus *etcdProcessCluster, req cURLReq) error {
|
func cURLPut(clus *etcdProcessCluster, req cURLReq) error {
|
||||||
return spawnWithExpect(cURLPrefixArgs(clus, "PUT", req), req.expected)
|
return spawnWithExpect(cURLPrefixArgsCluster(clus, "PUT", req), req.expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cURLGet(clus *etcdProcessCluster, req cURLReq) error {
|
func cURLGet(clus *etcdProcessCluster, req cURLReq) error {
|
||||||
return spawnWithExpect(cURLPrefixArgs(clus, "GET", req), req.expected)
|
return spawnWithExpect(cURLPrefixArgsCluster(clus, "GET", req), req.expected)
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ func testV3CurlAuth(cx ctlCtx) {
|
|||||||
lineFunc = func(txt string) bool { return true }
|
lineFunc = func(txt string) bool { return true }
|
||||||
)
|
)
|
||||||
|
|
||||||
cmdArgs = cURLPrefixArgs(cx.epc, "POST", cURLReq{endpoint: path.Join(p, "/auth/authenticate"), value: string(authreq)})
|
cmdArgs = cURLPrefixArgsCluster(cx.epc, "POST", cURLReq{endpoint: path.Join(p, "/auth/authenticate"), value: string(authreq)})
|
||||||
proc, err := spawnCmd(cmdArgs, cx.envMap)
|
proc, err := spawnCmd(cmdArgs, cx.envMap)
|
||||||
testutil.AssertNil(cx.t, err)
|
testutil.AssertNil(cx.t, err)
|
||||||
defer proc.Close()
|
defer proc.Close()
|
||||||
@ -282,7 +282,7 @@ func testV3CurlCampaign(cx ctlCtx) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
cx.t.Fatal(err)
|
cx.t.Fatal(err)
|
||||||
}
|
}
|
||||||
cargs := cURLPrefixArgs(cx.epc, "POST", cURLReq{
|
cargs := cURLPrefixArgsCluster(cx.epc, "POST", cURLReq{
|
||||||
endpoint: path.Join(cx.apiPrefix, "/election/campaign"),
|
endpoint: path.Join(cx.apiPrefix, "/election/campaign"),
|
||||||
value: string(cdata),
|
value: string(cdata),
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user