test: remove apiPrefix and withApiPrefix

Signed-off-by: Benjamin Wang <wachao@vmware.com>
This commit is contained in:
Benjamin Wang 2023-09-05 14:29:31 +01:00
parent ea9ef764a6
commit b2ee90c162
4 changed files with 36 additions and 65 deletions

View File

@ -119,9 +119,8 @@ func dialWithSchemeTest(cx ctlCtx) {
} }
type ctlCtx struct { type ctlCtx struct {
t *testing.T t *testing.T
apiPrefix string cfg e2e.EtcdProcessClusterConfig
cfg e2e.EtcdProcessClusterConfig
corruptFunc func(string) error corruptFunc func(string) error
disableStrictReconfigCheck bool disableStrictReconfigCheck bool
@ -187,10 +186,6 @@ func withDisableStrictReconfig() ctlOption {
return func(cx *ctlCtx) { cx.disableStrictReconfigCheck = true } return func(cx *ctlCtx) { cx.disableStrictReconfigCheck = true }
} }
func withApiPrefix(p string) ctlOption {
return func(cx *ctlCtx) { cx.apiPrefix = p }
}
func withFlagByEnv() ctlOption { func withFlagByEnv() ctlOption {
return func(cx *ctlCtx) { cx.envMap = make(map[string]string) } return func(cx *ctlCtx) { cx.envMap = make(map[string]string) }
} }

View File

@ -23,24 +23,16 @@ import (
) )
func TestCurlV3LeaseGrantNoTLS(t *testing.T) { func TestCurlV3LeaseGrantNoTLS(t *testing.T) {
for _, p := range apiPrefix { testCtl(t, testCurlV3LeaseGrant, withCfg(*e2e.NewConfigNoTLS()))
testCtl(t, testCurlV3LeaseGrant, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS()))
}
} }
func TestCurlV3LeaseRevokeNoTLS(t *testing.T) { func TestCurlV3LeaseRevokeNoTLS(t *testing.T) {
for _, p := range apiPrefix { testCtl(t, testCurlV3LeaseRevoke, withCfg(*e2e.NewConfigNoTLS()))
testCtl(t, testCurlV3LeaseRevoke, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS()))
}
} }
func TestCurlV3LeaseLeasesNoTLS(t *testing.T) { func TestCurlV3LeaseLeasesNoTLS(t *testing.T) {
for _, p := range apiPrefix { testCtl(t, testCurlV3LeaseLeases, withCfg(*e2e.NewConfigNoTLS()))
testCtl(t, testCurlV3LeaseLeases, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS()))
}
} }
func TestCurlV3LeaseKeepAliveNoTLS(t *testing.T) { func TestCurlV3LeaseKeepAliveNoTLS(t *testing.T) {
for _, p := range apiPrefix { testCtl(t, testCurlV3LeaseKeepAlive, withCfg(*e2e.NewConfigNoTLS()))
testCtl(t, testCurlV3LeaseKeepAlive, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS()))
}
} }
type v3cURLTest struct { type v3cURLTest struct {
@ -54,22 +46,22 @@ func testCurlV3LeaseGrant(cx ctlCtx) {
tests := []v3cURLTest{ tests := []v3cURLTest{
{ {
endpoint: "/lease/grant", endpoint: "/v3/lease/grant",
value: gwLeaseGrant(cx, leaseID, 0), value: gwLeaseGrant(cx, leaseID, 0),
expected: gwLeaseIDExpected(leaseID), expected: gwLeaseIDExpected(leaseID),
}, },
{ {
endpoint: "/lease/grant", endpoint: "/v3/lease/grant",
value: gwLeaseGrant(cx, 0, 20), value: gwLeaseGrant(cx, 0, 20),
expected: `"TTL":"20"`, expected: `"TTL":"20"`,
}, },
{ {
endpoint: "/kv/put", endpoint: "/v3/kv/put",
value: gwKVPutLease(cx, "foo", "bar", leaseID), value: gwKVPutLease(cx, "foo", "bar", leaseID),
expected: `"revision":"`, expected: `"revision":"`,
}, },
{ {
endpoint: "/lease/timetolive", endpoint: "/v3/lease/timetolive",
value: gwLeaseTTLWithKeys(cx, leaseID), value: gwLeaseTTLWithKeys(cx, leaseID),
expected: `"grantedTTL"`, expected: `"grantedTTL"`,
}, },
@ -84,12 +76,12 @@ func testCurlV3LeaseRevoke(cx ctlCtx) {
tests := []v3cURLTest{ tests := []v3cURLTest{
{ {
endpoint: "/lease/grant", endpoint: "/v3/lease/grant",
value: gwLeaseGrant(cx, leaseID, 0), value: gwLeaseGrant(cx, leaseID, 0),
expected: gwLeaseIDExpected(leaseID), expected: gwLeaseIDExpected(leaseID),
}, },
{ {
endpoint: "/lease/revoke", endpoint: "/v3/lease/revoke",
value: gwLeaseRevoke(cx, leaseID), value: gwLeaseRevoke(cx, leaseID),
expected: `"revision":"`, expected: `"revision":"`,
}, },
@ -104,12 +96,12 @@ func testCurlV3LeaseLeases(cx ctlCtx) {
tests := []v3cURLTest{ tests := []v3cURLTest{
{ {
endpoint: "/lease/grant", endpoint: "/v3/lease/grant",
value: gwLeaseGrant(cx, leaseID, 0), value: gwLeaseGrant(cx, leaseID, 0),
expected: gwLeaseIDExpected(leaseID), expected: gwLeaseIDExpected(leaseID),
}, },
{ {
endpoint: "/lease/leases", endpoint: "/v3/lease/leases",
value: "{}", value: "{}",
expected: gwLeaseIDExpected(leaseID), expected: gwLeaseIDExpected(leaseID),
}, },
@ -124,12 +116,12 @@ func testCurlV3LeaseKeepAlive(cx ctlCtx) {
tests := []v3cURLTest{ tests := []v3cURLTest{
{ {
endpoint: "/lease/grant", endpoint: "/v3/lease/grant",
value: gwLeaseGrant(cx, leaseID, 0), value: gwLeaseGrant(cx, leaseID, 0),
expected: gwLeaseIDExpected(leaseID), expected: gwLeaseIDExpected(leaseID),
}, },
{ {
endpoint: "/lease/keepalive", endpoint: "/v3/lease/keepalive",
value: gwLeaseKeepAlive(cx, leaseID), value: gwLeaseKeepAlive(cx, leaseID),
expected: gwLeaseIDExpected(leaseID), expected: gwLeaseIDExpected(leaseID),
}, },

View File

@ -16,7 +16,6 @@ package e2e
import ( import (
"math/rand" "math/rand"
"path"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -27,17 +26,15 @@ import (
) )
func TestCurlV3MaintenanceAlarmMissiongAlarm(t *testing.T) { func TestCurlV3MaintenanceAlarmMissiongAlarm(t *testing.T) {
for _, p := range apiPrefix { testCtl(t, testCurlV3MaintenanceAlarmMissiongAlarm, withCfg(*e2e.NewConfigNoTLS()))
testCtl(t, testCurlV3MaintenanceAlarmMissiongAlarm, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS()))
}
} }
func testCurlV3MaintenanceAlarmMissiongAlarm(cx ctlCtx) { func testCurlV3MaintenanceAlarmMissiongAlarm(cx ctlCtx) {
if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ if err := e2e.CURLPost(cx.epc, e2e.CURLReq{
Endpoint: path.Join(cx.apiPrefix, "/maintenance/alarm"), Endpoint: "/v3/maintenance/alarm",
Value: `{"action": "ACTIVATE"}`, Value: `{"action": "ACTIVATE"}`,
}); err != nil { }); err != nil {
cx.t.Fatalf("failed post maintenance alarm (%s) (%v)", cx.apiPrefix, err) cx.t.Fatalf("failed post maintenance alarm (%v)", err)
} }
} }

View File

@ -20,7 +20,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"math/rand" "math/rand"
"path"
"strconv" "strconv"
"testing" "testing"
@ -32,12 +31,8 @@ import (
"go.etcd.io/etcd/tests/v3/framework/e2e" "go.etcd.io/etcd/tests/v3/framework/e2e"
) )
var apiPrefix = []string{"/v3"}
func TestCurlV3Watch(t *testing.T) { func TestCurlV3Watch(t *testing.T) {
for _, p := range apiPrefix { testCtl(t, testCurlV3Watch)
testCtl(t, testCurlV3Watch, withApiPrefix(p))
}
} }
func testCurlV3Watch(cx ctlCtx) { func testCurlV3Watch(cx ctlCtx) {
@ -56,20 +51,17 @@ func testCurlV3Watch(cx ctlCtx) {
// "{"RequestUnion":{"CreateRequest":{"key":"Zm9v","start_revision":1}}}" // "{"RequestUnion":{"CreateRequest":{"key":"Zm9v","start_revision":1}}}"
// but the gprc-gateway expects a different format.. // but the gprc-gateway expects a different format..
wstr := `{"create_request" : ` + string(wreq) + "}" 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 { 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 using prefix (%s) (%v)", p, err) cx.t.Fatalf("failed testCurlV3Watch put with curl (%v)", err)
} }
// expects "bar", timeout after 2 seconds since stream waits forever // 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") require.ErrorContains(cx.t, err, "unexpected exit code")
} }
func TestCurlV3CampaignNoTLS(t *testing.T) { func TestCurlV3CampaignNoTLS(t *testing.T) {
for _, p := range apiPrefix { testCtl(t, testCurlV3Campaign, withCfg(*e2e.NewConfigNoTLS()))
testCtl(t, testCurlV3Campaign, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS()))
}
} }
func testCurlV3Campaign(cx ctlCtx) { func testCurlV3Campaign(cx ctlCtx) {
@ -81,12 +73,12 @@ func testCurlV3Campaign(cx ctlCtx) {
cx.t.Fatal(err) cx.t.Fatal(err)
} }
cargs := e2e.CURLPrefixArgsCluster(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"), Endpoint: "/v3/election/campaign",
Value: string(cdata), Value: string(cdata),
}) })
lines, err := e2e.SpawnWithExpectLines(context.TODO(), cargs, cx.envMap, expect.ExpectedResponse{Value: `"leader":{"name":"`}) lines, err := e2e.SpawnWithExpectLines(context.TODO(), cargs, cx.envMap, expect.ExpectedResponse{Value: `"leader":{"name":"`})
if err != nil { 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 { if len(lines) != 1 {
cx.t.Fatalf("len(lines) expected 1, got %+v", lines) cx.t.Fatalf("len(lines) expected 1, got %+v", lines)
@ -120,18 +112,16 @@ func testCurlV3Campaign(cx ctlCtx) {
cx.t.Fatal(err) cx.t.Fatal(err)
} }
if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ if err = e2e.CURLPost(cx.epc, e2e.CURLReq{
Endpoint: path.Join(cx.apiPrefix, "/election/proclaim"), Endpoint: "/v3/election/proclaim",
Value: string(pdata), Value: string(pdata),
Expected: expect.ExpectedResponse{Value: `"revision":`}, Expected: expect.ExpectedResponse{Value: `"revision":`},
}); err != nil { }); 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) { func TestCurlV3ProclaimMissiongLeaderKeyNoTLS(t *testing.T) {
for _, p := range apiPrefix { testCtl(t, testCurlV3ProclaimMissiongLeaderKey, withCfg(*e2e.NewConfigNoTLS()))
testCtl(t, testCurlV3ProclaimMissiongLeaderKey, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS()))
}
} }
func testCurlV3ProclaimMissiongLeaderKey(cx ctlCtx) { func testCurlV3ProclaimMissiongLeaderKey(cx ctlCtx) {
@ -140,27 +130,25 @@ func testCurlV3ProclaimMissiongLeaderKey(cx ctlCtx) {
cx.t.Fatal(err) cx.t.Fatal(err)
} }
if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ if err = e2e.CURLPost(cx.epc, e2e.CURLReq{
Endpoint: path.Join(cx.apiPrefix, "/election/proclaim"), Endpoint: "/v3/election/proclaim",
Value: string(pdata), Value: string(pdata),
Expected: expect.ExpectedResponse{Value: `{"error":"\"leader\" field must be provided","code":2,"message":"\"leader\" field must be provided"}`}, Expected: expect.ExpectedResponse{Value: `{"error":"\"leader\" field must be provided","code":2,"message":"\"leader\" field must be provided"}`},
}); err != nil { }); 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) { func TestCurlV3ResignMissiongLeaderKeyNoTLS(t *testing.T) {
for _, p := range apiPrefix { testCtl(t, testCurlV3ResignMissiongLeaderKey, withCfg(*e2e.NewConfigNoTLS()))
testCtl(t, testCurlV3ResignMissiongLeaderKey, withApiPrefix(p), withCfg(*e2e.NewConfigNoTLS()))
}
} }
func testCurlV3ResignMissiongLeaderKey(cx ctlCtx) { func testCurlV3ResignMissiongLeaderKey(cx ctlCtx) {
if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ if err := e2e.CURLPost(cx.epc, e2e.CURLReq{
Endpoint: path.Join(cx.apiPrefix, "/election/resign"), Endpoint: "/v3/election/resign",
Value: `{}`, Value: `{}`,
Expected: expect.ExpectedResponse{Value: `{"error":"\"leader\" field must be provided","code":2,"message":"\"leader\" field must be provided"}`}, Expected: expect.ExpectedResponse{Value: `{"error":"\"leader\" field must be provided","code":2,"message":"\"leader\" field must be provided"}`},
}); err != nil { }); 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 { func CURLWithExpected(cx ctlCtx, tests []v3cURLTest) error {
p := cx.apiPrefix
for _, t := range tests { for _, t := range tests {
value := fmt.Sprintf("%v", t.value) 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 { if err := e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: 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) return fmt.Errorf("endpoint (%s): error (%v), wanted %v", t.endpoint, err, t.expected)
} }
} }
return nil return nil