Skip to content

Commit

Permalink
Merge pull request #16546 from ahrtr/remove_apiPrefix_20230905
Browse files Browse the repository at this point in the history
test: remove apiPrefix and withApiPrefix
  • Loading branch information
ahrtr authored Sep 5, 2023
2 parents ea9ef76 + b2ee90c commit b57fe9e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 65 deletions.
9 changes: 2 additions & 7 deletions tests/e2e/ctl_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
}
Expand Down
36 changes: 14 additions & 22 deletions tests/e2e/v3_curl_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"`,
},
Expand All @@ -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":"`,
},
Expand All @@ -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),
},
Expand All @@ -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),
},
Expand Down
9 changes: 3 additions & 6 deletions tests/e2e/v3_curl_maintenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package e2e

import (
"math/rand"
"path"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -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)
}
}

Expand Down
47 changes: 17 additions & 30 deletions tests/e2e/v3_curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/json"
"fmt"
"math/rand"
"path"
"strconv"
"testing"

Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}
}

Expand All @@ -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
Expand Down

0 comments on commit b57fe9e

Please sign in to comment.