From b2ee90c1629fceb146a04f097dbdd3835cfd300b Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Tue, 5 Sep 2023 14:29:31 +0100 Subject: [PATCH] test: remove apiPrefix and withApiPrefix Signed-off-by: Benjamin Wang --- tests/e2e/ctl_v3_test.go | 9 ++--- tests/e2e/v3_curl_lease_test.go | 36 ++++++++------------ tests/e2e/v3_curl_maintenance_test.go | 9 ++--- tests/e2e/v3_curl_test.go | 47 ++++++++++----------------- 4 files changed, 36 insertions(+), 65 deletions(-) diff --git a/tests/e2e/ctl_v3_test.go b/tests/e2e/ctl_v3_test.go index 07158a734fe..ea8085bba70 100644 --- a/tests/e2e/ctl_v3_test.go +++ b/tests/e2e/ctl_v3_test.go @@ -119,9 +119,8 @@ func dialWithSchemeTest(cx ctlCtx) { } type ctlCtx struct { - t *testing.T - apiPrefix string - cfg e2e.EtcdProcessClusterConfig + t *testing.T + cfg e2e.EtcdProcessClusterConfig corruptFunc func(string) error disableStrictReconfigCheck bool @@ -187,10 +186,6 @@ func withDisableStrictReconfig() ctlOption { return func(cx *ctlCtx) { cx.disableStrictReconfigCheck = true } } -func withApiPrefix(p string) ctlOption { - return func(cx *ctlCtx) { cx.apiPrefix = p } -} - func withFlagByEnv() ctlOption { return func(cx *ctlCtx) { cx.envMap = make(map[string]string) } } diff --git a/tests/e2e/v3_curl_lease_test.go b/tests/e2e/v3_curl_lease_test.go index 671643c4362..67ef64e2240 100644 --- a/tests/e2e/v3_curl_lease_test.go +++ b/tests/e2e/v3_curl_lease_test.go @@ -23,24 +23,16 @@ import ( ) func TestCurlV3LeaseGrantNoTLS(t *testing.T) { - for _, p := range apiPrefix { - testCtl(t, testCurlV3LeaseGrant, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS())) - } + testCtl(t, testCurlV3LeaseGrant, withCfg(*e2e.NewConfigNoTLS())) } func TestCurlV3LeaseRevokeNoTLS(t *testing.T) { - for _, p := range apiPrefix { - testCtl(t, testCurlV3LeaseRevoke, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS())) - } + testCtl(t, testCurlV3LeaseRevoke, withCfg(*e2e.NewConfigNoTLS())) } func TestCurlV3LeaseLeasesNoTLS(t *testing.T) { - for _, p := range apiPrefix { - testCtl(t, testCurlV3LeaseLeases, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS())) - } + testCtl(t, testCurlV3LeaseLeases, withCfg(*e2e.NewConfigNoTLS())) } func TestCurlV3LeaseKeepAliveNoTLS(t *testing.T) { - for _, p := range apiPrefix { - testCtl(t, testCurlV3LeaseKeepAlive, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS())) - } + testCtl(t, testCurlV3LeaseKeepAlive, withCfg(*e2e.NewConfigNoTLS())) } type v3cURLTest struct { @@ -54,22 +46,22 @@ func testCurlV3LeaseGrant(cx ctlCtx) { tests := []v3cURLTest{ { - endpoint: "/lease/grant", + endpoint: "/v3/lease/grant", value: gwLeaseGrant(cx, leaseID, 0), expected: gwLeaseIDExpected(leaseID), }, { - endpoint: "/lease/grant", + endpoint: "/v3/lease/grant", value: gwLeaseGrant(cx, 0, 20), expected: `"TTL":"20"`, }, { - endpoint: "/kv/put", + endpoint: "/v3/kv/put", value: gwKVPutLease(cx, "foo", "bar", leaseID), expected: `"revision":"`, }, { - endpoint: "/lease/timetolive", + endpoint: "/v3/lease/timetolive", value: gwLeaseTTLWithKeys(cx, leaseID), expected: `"grantedTTL"`, }, @@ -84,12 +76,12 @@ func testCurlV3LeaseRevoke(cx ctlCtx) { tests := []v3cURLTest{ { - endpoint: "/lease/grant", + endpoint: "/v3/lease/grant", value: gwLeaseGrant(cx, leaseID, 0), expected: gwLeaseIDExpected(leaseID), }, { - endpoint: "/lease/revoke", + endpoint: "/v3/lease/revoke", value: gwLeaseRevoke(cx, leaseID), expected: `"revision":"`, }, @@ -104,12 +96,12 @@ func testCurlV3LeaseLeases(cx ctlCtx) { tests := []v3cURLTest{ { - endpoint: "/lease/grant", + endpoint: "/v3/lease/grant", value: gwLeaseGrant(cx, leaseID, 0), expected: gwLeaseIDExpected(leaseID), }, { - endpoint: "/lease/leases", + endpoint: "/v3/lease/leases", value: "{}", expected: gwLeaseIDExpected(leaseID), }, @@ -124,12 +116,12 @@ func testCurlV3LeaseKeepAlive(cx ctlCtx) { tests := []v3cURLTest{ { - endpoint: "/lease/grant", + endpoint: "/v3/lease/grant", value: gwLeaseGrant(cx, leaseID, 0), expected: gwLeaseIDExpected(leaseID), }, { - endpoint: "/lease/keepalive", + endpoint: "/v3/lease/keepalive", value: gwLeaseKeepAlive(cx, leaseID), expected: gwLeaseIDExpected(leaseID), }, diff --git a/tests/e2e/v3_curl_maintenance_test.go b/tests/e2e/v3_curl_maintenance_test.go index ec773c2a89d..e94a3d9611f 100644 --- a/tests/e2e/v3_curl_maintenance_test.go +++ b/tests/e2e/v3_curl_maintenance_test.go @@ -16,7 +16,6 @@ package e2e import ( "math/rand" - "path" "testing" "github.com/stretchr/testify/require" @@ -27,17 +26,15 @@ import ( ) func TestCurlV3MaintenanceAlarmMissiongAlarm(t *testing.T) { - for _, p := range apiPrefix { - testCtl(t, testCurlV3MaintenanceAlarmMissiongAlarm, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS())) - } + testCtl(t, testCurlV3MaintenanceAlarmMissiongAlarm, withCfg(*e2e.NewConfigNoTLS())) } func testCurlV3MaintenanceAlarmMissiongAlarm(cx ctlCtx) { if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ - Endpoint: path.Join(cx.apiPrefix, "/maintenance/alarm"), + Endpoint: "/v3/maintenance/alarm", Value: `{"action": "ACTIVATE"}`, }); err != nil { - cx.t.Fatalf("failed post maintenance alarm (%s) (%v)", cx.apiPrefix, err) + cx.t.Fatalf("failed post maintenance alarm (%v)", err) } } diff --git a/tests/e2e/v3_curl_test.go b/tests/e2e/v3_curl_test.go index 2bda0631a86..e21e9372917 100644 --- a/tests/e2e/v3_curl_test.go +++ b/tests/e2e/v3_curl_test.go @@ -20,7 +20,6 @@ import ( "encoding/json" "fmt" "math/rand" - "path" "strconv" "testing" @@ -32,12 +31,8 @@ import ( "go.etcd.io/etcd/tests/v3/framework/e2e" ) -var apiPrefix = []string{"/v3"} - func TestCurlV3Watch(t *testing.T) { - for _, p := range apiPrefix { - testCtl(t, testCurlV3Watch, withApiPrefix(p)) - } + testCtl(t, testCurlV3Watch) } func testCurlV3Watch(cx ctlCtx) { @@ -56,20 +51,17 @@ func testCurlV3Watch(cx ctlCtx) { // "{"RequestUnion":{"CreateRequest":{"key":"Zm9v","start_revision":1}}}" // but the gprc-gateway expects a different format.. wstr := `{"create_request" : ` + string(wreq) + "}" - p := cx.apiPrefix - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: path.Join(p, "/kv/put"), Value: string(putreq), Expected: expect.ExpectedResponse{Value: "revision"}}); err != nil { - cx.t.Fatalf("failed testCurlV3Watch put with curl using prefix (%s) (%v)", p, err) + if err = e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: "/v3/kv/put", Value: string(putreq), Expected: expect.ExpectedResponse{Value: "revision"}}); err != nil { + cx.t.Fatalf("failed testCurlV3Watch put with curl (%v)", err) } // expects "bar", timeout after 2 seconds since stream waits forever - err = e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: path.Join(p, "/watch"), Value: wstr, Expected: expect.ExpectedResponse{Value: `"YmFy"`}, Timeout: 2}) + err = e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: "/v3/watch", Value: wstr, Expected: expect.ExpectedResponse{Value: `"YmFy"`}, Timeout: 2}) require.ErrorContains(cx.t, err, "unexpected exit code") } func TestCurlV3CampaignNoTLS(t *testing.T) { - for _, p := range apiPrefix { - testCtl(t, testCurlV3Campaign, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS())) - } + testCtl(t, testCurlV3Campaign, withCfg(*e2e.NewConfigNoTLS())) } func testCurlV3Campaign(cx ctlCtx) { @@ -81,12 +73,12 @@ func testCurlV3Campaign(cx ctlCtx) { cx.t.Fatal(err) } 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"), + Endpoint: "/v3/election/campaign", Value: string(cdata), }) lines, err := e2e.SpawnWithExpectLines(context.TODO(), cargs, cx.envMap, expect.ExpectedResponse{Value: `"leader":{"name":"`}) if err != nil { - cx.t.Fatalf("failed post campaign request (%s) (%v)", cx.apiPrefix, err) + cx.t.Fatalf("failed post campaign request (%v)", err) } if len(lines) != 1 { cx.t.Fatalf("len(lines) expected 1, got %+v", lines) @@ -120,18 +112,16 @@ func testCurlV3Campaign(cx ctlCtx) { cx.t.Fatal(err) } if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ - Endpoint: path.Join(cx.apiPrefix, "/election/proclaim"), + Endpoint: "/v3/election/proclaim", Value: string(pdata), Expected: expect.ExpectedResponse{Value: `"revision":`}, }); err != nil { - cx.t.Fatalf("failed post proclaim request (%s) (%v)", cx.apiPrefix, err) + cx.t.Fatalf("failed post proclaim request (%v)", err) } } func TestCurlV3ProclaimMissiongLeaderKeyNoTLS(t *testing.T) { - for _, p := range apiPrefix { - testCtl(t, testCurlV3ProclaimMissiongLeaderKey, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS())) - } + testCtl(t, testCurlV3ProclaimMissiongLeaderKey, withCfg(*e2e.NewConfigNoTLS())) } func testCurlV3ProclaimMissiongLeaderKey(cx ctlCtx) { @@ -140,27 +130,25 @@ func testCurlV3ProclaimMissiongLeaderKey(cx ctlCtx) { cx.t.Fatal(err) } if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ - Endpoint: path.Join(cx.apiPrefix, "/election/proclaim"), + Endpoint: "/v3/election/proclaim", Value: string(pdata), Expected: expect.ExpectedResponse{Value: `{"error":"\"leader\" field must be provided","code":2,"message":"\"leader\" field must be provided"}`}, }); err != nil { - cx.t.Fatalf("failed post proclaim request (%s) (%v)", cx.apiPrefix, err) + cx.t.Fatalf("failed post proclaim request (%v)", err) } } func TestCurlV3ResignMissiongLeaderKeyNoTLS(t *testing.T) { - for _, p := range apiPrefix { - testCtl(t, testCurlV3ResignMissiongLeaderKey, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS())) - } + testCtl(t, testCurlV3ResignMissiongLeaderKey, withCfg(*e2e.NewConfigNoTLS())) } func testCurlV3ResignMissiongLeaderKey(cx ctlCtx) { if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ - Endpoint: path.Join(cx.apiPrefix, "/election/resign"), + Endpoint: "/v3/election/resign", Value: `{}`, Expected: expect.ExpectedResponse{Value: `{"error":"\"leader\" field must be provided","code":2,"message":"\"leader\" field must be provided"}`}, }); err != nil { - cx.t.Fatalf("failed post resign request (%s) (%v)", cx.apiPrefix, err) + cx.t.Fatalf("failed post resign request (%v)", err) } } @@ -176,11 +164,10 @@ type campaignResponse struct { } func CURLWithExpected(cx ctlCtx, tests []v3cURLTest) error { - p := cx.apiPrefix for _, t := range tests { value := fmt.Sprintf("%v", t.value) - if err := e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: path.Join(p, t.endpoint), Value: value, Expected: expect.ExpectedResponse{Value: t.expected}}); err != nil { - return fmt.Errorf("prefix (%s) endpoint (%s): error (%v), wanted %v", p, t.endpoint, err, t.expected) + if err := e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: t.endpoint, Value: value, Expected: expect.ExpectedResponse{Value: t.expected}}); err != nil { + return fmt.Errorf("endpoint (%s): error (%v), wanted %v", t.endpoint, err, t.expected) } } return nil