Skip to content

Commit

Permalink
tests: Allow sepecting member to in curl commands
Browse files Browse the repository at this point in the history
  • Loading branch information
serathius committed May 6, 2022
1 parent 923096a commit 75449c0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
5 changes: 3 additions & 2 deletions tests/e2e/cluster_downgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package e2e

import (
"fmt"
"math/rand"
"testing"
"time"

Expand Down Expand Up @@ -105,13 +106,13 @@ func validateVersion(t *testing.T, epc *e2e.EtcdProcessCluster, expect version.V
// Two separate calls to expect as it doesn't support multiple matches on the same line
testutils.ExecuteWithTimeout(t, 20*time.Second, func() {
if expect.Server != "" {
err := e2e.SpawnWithExpects(e2e.CURLPrefixArgs(epc, "GET", e2e.CURLReq{Endpoint: "/version"}), nil, `"etcdserver":"`+expect.Server)
err := e2e.SpawnWithExpects(e2e.CURLPrefixArgs(epc.Cfg, epc.Procs[rand.Intn(epc.Cfg.ClusterSize)], "GET", e2e.CURLReq{Endpoint: "/version"}), nil, `"etcdserver":"`+expect.Server)
if err != nil {
t.Fatal(err)
}
}
if expect.Cluster != "" {
err := e2e.SpawnWithExpects(e2e.CURLPrefixArgs(epc, "GET", e2e.CURLReq{Endpoint: "/version"}), nil, `"etcdcluster":"`+expect.Cluster)
err := e2e.SpawnWithExpects(e2e.CURLPrefixArgs(epc.Cfg, epc.Procs[rand.Intn(epc.Cfg.ClusterSize)], "GET", e2e.CURLReq{Endpoint: "/version"}), nil, `"etcdcluster":"`+expect.Cluster)
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 3 additions & 2 deletions tests/e2e/v3_curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"math/rand"
"path"
"strconv"
"testing"
Expand Down Expand Up @@ -243,7 +244,7 @@ func testV3CurlAuth(cx ctlCtx) {
lineFunc = func(txt string) bool { return true }
)

cmdArgs = e2e.CURLPrefixArgs(cx.epc, "POST", e2e.CURLReq{Endpoint: path.Join(p, "/auth/authenticate"), Value: string(authreq)})
cmdArgs = e2e.CURLPrefixArgs(cx.epc.Cfg, cx.epc.Procs[rand.Intn(cx.epc.Cfg.ClusterSize)], "POST", e2e.CURLReq{Endpoint: path.Join(p, "/auth/authenticate"), Value: string(authreq)})
proc, err := e2e.SpawnCmd(cmdArgs, cx.envMap)
testutil.AssertNil(cx.t, err)
defer proc.Close()
Expand Down Expand Up @@ -282,7 +283,7 @@ func testV3CurlCampaign(cx ctlCtx) {
if err != nil {
cx.t.Fatal(err)
}
cargs := e2e.CURLPrefixArgs(cx.epc, "POST", e2e.CURLReq{
cargs := e2e.CURLPrefixArgs(cx.epc.Cfg, cx.epc.Procs[rand.Intn(cx.epc.Cfg.ClusterSize)], "POST", e2e.CURLReq{
Endpoint: path.Join(cx.apiPrefix, "/election/campaign"),
Value: string(cdata),
})
Expand Down
20 changes: 10 additions & 10 deletions tests/framework/e2e/curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@ type CURLReq struct {

// CURLPrefixArgs 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 CURLPrefixArgs(cfg *EtcdProcessClusterConfig, member EtcdProcess, method string, req CURLReq) []string {
var (
cmdArgs = []string{"curl"}
acurl = clus.Procs[rand.Intn(clus.Cfg.ClusterSize)].Config().Acurl
acurl = member.Config().Acurl
)
if req.MetricsURLScheme != "https" {
if req.IsTLS {
if clus.Cfg.ClientTLS != ClientTLSAndNonTLS {
if cfg.ClientTLS != 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 {
acurl = ToTLS(member.Config().Acurl)
} else if cfg.ClientTLS == ClientTLS {
if !cfg.NoCN {
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]
acurl = member.EndpointsMetrics()[0]
}
ep := acurl + req.Endpoint

Expand Down Expand Up @@ -94,13 +94,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(CURLPrefixArgs(clus.Cfg, clus.Procs[rand.Intn(clus.Cfg.ClusterSize)], "POST", req), req.Expected)
}

func CURLPut(clus *EtcdProcessCluster, req CURLReq) error {
return SpawnWithExpect(CURLPrefixArgs(clus, "PUT", req), req.Expected)
return SpawnWithExpect(CURLPrefixArgs(clus.Cfg, clus.Procs[rand.Intn(clus.Cfg.ClusterSize)], "PUT", req), req.Expected)
}

func CURLGet(clus *EtcdProcessCluster, req CURLReq) error {
return SpawnWithExpect(CURLPrefixArgs(clus, "GET", req), req.Expected)
return SpawnWithExpect(CURLPrefixArgs(clus.Cfg, clus.Procs[rand.Intn(clus.Cfg.ClusterSize)], "GET", req), req.Expected)
}

0 comments on commit 75449c0

Please sign in to comment.