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
bf22b350b0
commit
1bafc86b42
@ -137,32 +137,37 @@ type cURLReq struct {
|
||||
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.
|
||||
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 (
|
||||
cmdArgs = []string{"curl"}
|
||||
acurl = clus.procs[rand.Intn(clus.cfg.clusterSize)].Config().acurl
|
||||
)
|
||||
if req.metricsURLScheme != "https" {
|
||||
if req.isTLS {
|
||||
if clus.cfg.clientTLS != clientTLSAndNonTLS {
|
||||
if connType != clientTLSAndNonTLS {
|
||||
panic("should not use cURLPrefixArgsUseTLS when serving only TLS or non-TLS")
|
||||
}
|
||||
cmdArgs = append(cmdArgs, "--cacert", caPath, "--cert", certPath, "--key", privateKeyPath)
|
||||
acurl = toTLS(clus.procs[rand.Intn(clus.cfg.clusterSize)].Config().acurl)
|
||||
} else if clus.cfg.clientTLS == clientTLS {
|
||||
if !clus.cfg.noCN {
|
||||
clientURL = toTLS(clientURL)
|
||||
} else if connType == clientTLS {
|
||||
if CN {
|
||||
cmdArgs = append(cmdArgs, "--cacert", caPath, "--cert", certPath, "--key", privateKeyPath)
|
||||
} else {
|
||||
cmdArgs = append(cmdArgs, "--cacert", caPath, "--cert", certPath3, "--key", privateKeyPath3)
|
||||
}
|
||||
}
|
||||
}
|
||||
if req.metricsURLScheme != "" {
|
||||
acurl = clus.procs[rand.Intn(clus.cfg.clusterSize)].EndpointsMetrics()[0]
|
||||
}
|
||||
ep := acurl + req.endpoint
|
||||
ep := clientURL + req.endpoint
|
||||
|
||||
if req.username != "" || req.password != "" {
|
||||
cmdArgs = append(cmdArgs, "-L", "-u", fmt.Sprintf("%s:%s", req.username, req.password), ep)
|
||||
@ -193,13 +198,13 @@ func cURLPrefixArgs(clus *etcdProcessCluster, method string, req cURLReq) []stri
|
||||
}
|
||||
|
||||
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 {
|
||||
return spawnWithExpect(cURLPrefixArgs(clus, "PUT", req), req.expected)
|
||||
return spawnWithExpect(cURLPrefixArgsCluster(clus, "PUT", req), req.expected)
|
||||
}
|
||||
|
||||
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 }
|
||||
)
|
||||
|
||||
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)
|
||||
testutil.AssertNil(cx.t, err)
|
||||
|
||||
@ -281,7 +281,7 @@ func testV3CurlCampaign(cx ctlCtx) {
|
||||
if err != nil {
|
||||
cx.t.Fatal(err)
|
||||
}
|
||||
cargs := cURLPrefixArgs(cx.epc, "POST", cURLReq{
|
||||
cargs := cURLPrefixArgsCluster(cx.epc, "POST", cURLReq{
|
||||
endpoint: path.Join(cx.apiPrefix, "/election/campaign"),
|
||||
value: string(cdata),
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user