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
67e3c784ba
commit
e87abf3f13
@ -232,7 +232,7 @@ func compareMemberVersion(expect version.Versions, target version.Versions) erro
|
||||
}
|
||||
|
||||
func getMemberVersionByCurl(cfg *e2e.EtcdProcessClusterConfig, member e2e.EtcdProcess) (version.Versions, error) {
|
||||
args := e2e.CURLPrefixArgs(cfg, member, "GET", e2e.CURLReq{Endpoint: "/version"})
|
||||
args := e2e.CURLPrefixArgsCluster(cfg, member, "GET", e2e.CURLReq{Endpoint: "/version"})
|
||||
lines, err := e2e.RunUtilCompletion(args, nil)
|
||||
if err != nil {
|
||||
return version.Versions{}, err
|
||||
|
@ -157,7 +157,7 @@ func submitConcurrentWatch(cx ctlCtx, number int, wgDone *sync.WaitGroup, closeC
|
||||
member := cluster.Procs[rand.Intn(cluster.Cfg.ClusterSize)]
|
||||
curlReq := e2e.CURLReq{Endpoint: "/v3/watch", Value: string(watchData)}
|
||||
|
||||
args := e2e.CURLPrefixArgs(cluster.Cfg, member, "POST", curlReq)
|
||||
args := e2e.CURLPrefixArgsCluster(cluster.Cfg, member, "POST", curlReq)
|
||||
proc, err := e2e.SpawnCmd(args, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to spawn: %w", err)
|
||||
|
@ -246,7 +246,7 @@ func testV3CurlAuth(cx ctlCtx) {
|
||||
lineFunc = func(txt string) bool { return true }
|
||||
)
|
||||
|
||||
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)})
|
||||
cmdArgs = e2e.CURLPrefixArgsCluster(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()
|
||||
@ -285,7 +285,7 @@ func testV3CurlCampaign(cx ctlCtx) {
|
||||
if err != nil {
|
||||
cx.t.Fatal(err)
|
||||
}
|
||||
cargs := e2e.CURLPrefixArgs(cx.epc.Cfg, cx.epc.Procs[rand.Intn(cx.epc.Cfg.ClusterSize)], "POST", e2e.CURLReq{
|
||||
cargs := e2e.CURLPrefixArgsCluster(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),
|
||||
})
|
||||
|
@ -47,27 +47,30 @@ func (r CURLReq) timeoutDuration() time.Duration {
|
||||
return 5 * time.Second
|
||||
}
|
||||
|
||||
// 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(cfg *EtcdProcessClusterConfig, member EtcdProcess, method string, req CURLReq) []string {
|
||||
func CURLPrefixArgsCluster(cfg *EtcdProcessClusterConfig, member EtcdProcess, method string, req CURLReq) []string {
|
||||
return CURLPrefixArgs(member.Config().ClientURL, cfg.Client, cfg.CN, method, req)
|
||||
}
|
||||
|
||||
func CURLPrefixArgs(clientURL string, cfg ClientConfig, CN bool, method string, req CURLReq) []string {
|
||||
var (
|
||||
cmdArgs = []string{"curl"}
|
||||
acurl = member.Config().ClientURL
|
||||
)
|
||||
if req.IsTLS {
|
||||
if cfg.Client.ConnectionType != ClientTLSAndNonTLS {
|
||||
if cfg.ConnectionType != ClientTLSAndNonTLS {
|
||||
panic("should not use cURLPrefixArgsUseTLS when serving only TLS or non-TLS")
|
||||
}
|
||||
cmdArgs = append(cmdArgs, "--cacert", CaPath, "--cert", CertPath, "--key", PrivateKeyPath)
|
||||
acurl = ToTLS(member.Config().ClientURL)
|
||||
} else if cfg.Client.ConnectionType == ClientTLS {
|
||||
if cfg.CN {
|
||||
clientURL = ToTLS(clientURL)
|
||||
} else if cfg.ConnectionType == ClientTLS {
|
||||
if CN {
|
||||
cmdArgs = append(cmdArgs, "--cacert", CaPath, "--cert", CertPath, "--key", PrivateKeyPath)
|
||||
} else {
|
||||
cmdArgs = append(cmdArgs, "--cacert", CaPath, "--cert", CertPath3, "--key", PrivateKeyPath3)
|
||||
}
|
||||
}
|
||||
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)
|
||||
@ -100,18 +103,18 @@ func CURLPrefixArgs(cfg *EtcdProcessClusterConfig, member EtcdProcess, method st
|
||||
func CURLPost(clus *EtcdProcessCluster, req CURLReq) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), req.timeoutDuration())
|
||||
defer cancel()
|
||||
return SpawnWithExpectsContext(ctx, CURLPrefixArgs(clus.Cfg, clus.Procs[rand.Intn(clus.Cfg.ClusterSize)], "POST", req), nil, req.Expected)
|
||||
return SpawnWithExpectsContext(ctx, CURLPrefixArgsCluster(clus.Cfg, clus.Procs[rand.Intn(clus.Cfg.ClusterSize)], "POST", req), nil, req.Expected)
|
||||
}
|
||||
|
||||
func CURLPut(clus *EtcdProcessCluster, req CURLReq) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), req.timeoutDuration())
|
||||
defer cancel()
|
||||
return SpawnWithExpectsContext(ctx, CURLPrefixArgs(clus.Cfg, clus.Procs[rand.Intn(clus.Cfg.ClusterSize)], "PUT", req), nil, req.Expected)
|
||||
return SpawnWithExpectsContext(ctx, CURLPrefixArgsCluster(clus.Cfg, clus.Procs[rand.Intn(clus.Cfg.ClusterSize)], "PUT", req), nil, req.Expected)
|
||||
}
|
||||
|
||||
func CURLGet(clus *EtcdProcessCluster, req CURLReq) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), req.timeoutDuration())
|
||||
defer cancel()
|
||||
|
||||
return SpawnWithExpectsContext(ctx, CURLPrefixArgs(clus.Cfg, clus.Procs[rand.Intn(clus.Cfg.ClusterSize)], "GET", req), nil, req.Expected)
|
||||
return SpawnWithExpectsContext(ctx, CURLPrefixArgsCluster(clus.Cfg, clus.Procs[rand.Intn(clus.Cfg.ClusterSize)], "GET", req), nil, req.Expected)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user