From 64bc55ef4e69f33aabfcd25ab4e766856debd717 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Tue, 14 Mar 2023 12:12:32 +0100 Subject: [PATCH] tests: Refactor CURLPrefixArgs Signed-off-by: Marek Siarkowicz --- tests/e2e/v2_curl_test.go | 33 +++++++++++++++++++-------------- tests/e2e/v3_curl_test.go | 4 ++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/tests/e2e/v2_curl_test.go b/tests/e2e/v2_curl_test.go index 0285a7bef..aa7f91d25 100644 --- a/tests/e2e/v2_curl_test.go +++ b/tests/e2e/v2_curl_test.go @@ -132,32 +132,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) @@ -188,13 +193,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) } diff --git a/tests/e2e/v3_curl_test.go b/tests/e2e/v3_curl_test.go index 4c34fda4d..00194af88 100644 --- a/tests/e2e/v3_curl_test.go +++ b/tests/e2e/v3_curl_test.go @@ -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, cx.envMap) testutil.AssertNil(cx.t, err) defer proc.Close() @@ -282,7 +282,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), })