From 321353644de9c6c44af5e7491fa8b7423ace90c7 Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Fri, 25 Aug 2023 10:10:02 +0100 Subject: [PATCH] test: add v3 curl test to cover all maintainence REST API Signed-off-by: Benjamin Wang --- tests/e2e/v3_curl_test.go | 100 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/tests/e2e/v3_curl_test.go b/tests/e2e/v3_curl_test.go index 455e9492ac1d..a1cd279781e8 100644 --- a/tests/e2e/v3_curl_test.go +++ b/tests/e2e/v3_curl_test.go @@ -29,6 +29,7 @@ import ( "go.etcd.io/etcd/api/v3/authpb" pb "go.etcd.io/etcd/api/v3/etcdserverpb" "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" + "go.etcd.io/etcd/api/v3/version" "go.etcd.io/etcd/client/pkg/v3/testutil" "go.etcd.io/etcd/pkg/v3/expect" epb "go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb" @@ -385,6 +386,105 @@ func testV3CurlMaintenanceAlarmMissiongAlarm(cx ctlCtx) { } } +func TestV3CurlMaintenanceStatus(t *testing.T) { + testCtl(t, testV3CurlMaintenanceStatus, withCfg(*e2e.NewConfigNoTLS())) +} + +func testV3CurlMaintenanceStatus(cx ctlCtx) { + if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + Endpoint: "/v3/maintenance/status", + Value: "{}", + Expected: expect.ExpectedResponse{ + Value: fmt.Sprintf(`.*"version":%q,"dbSize":.*,\s*"leader":.*,\s*"raftIndex":.*,\s*"raftTerm":.*,\s*"raftAppliedIndex":.*,\s*"dbSizeInUse":.*,\s*"storageVersion":.*`, version.Version), + IsRegularExpr: true, + }, + }); err != nil { + cx.t.Fatalf("failed post maintenance status request: (%v)", err) + } +} + +func TestV3CurlMaintenanceDefragment(t *testing.T) { + testCtl(t, testV3CurlMaintenanceDefragment, withCfg(*e2e.NewConfigNoTLS())) +} + +func testV3CurlMaintenanceDefragment(cx ctlCtx) { + if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + Endpoint: "/v3/maintenance/defragment", + Value: "{}", + Expected: expect.ExpectedResponse{ + Value: "{}", + }, + }); err != nil { + cx.t.Fatalf("failed post maintenance defragment request: (%v)", err) + } +} + +func TestV3CurlMaintenanceHash(t *testing.T) { + testCtl(t, testV3CurlMaintenanceHash, withCfg(*e2e.NewConfigNoTLS())) +} + +func testV3CurlMaintenanceHash(cx ctlCtx) { + if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + Endpoint: "/v3/maintenance/hash", + Value: "{}", + Expected: expect.ExpectedResponse{ + Value: `.*"cluster_id":.*"member_id":.*"revision":.*"raft_term".*"hash":.*`, + IsRegularExpr: true, + }, + }); err != nil { + cx.t.Fatalf("failed post maintenance hash request: (%v)", err) + } +} + +func TestV3CurlMaintenanceHashKV(t *testing.T) { + testCtl(t, testV3CurlMaintenanceHashKV, withCfg(*e2e.NewConfigNoTLS())) +} + +func testV3CurlMaintenanceHashKV(cx ctlCtx) { + if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + Endpoint: "/v3/maintenance/hashkv", + Value: `{"revision": 1}`, + Expected: expect.ExpectedResponse{ + Value: `.*"cluster_id":.*"member_id":.*"revision":.*"raft_term".*"hash":.*"compact_revision":.*"hash_revision":.*`, + IsRegularExpr: true, + }, + }); err != nil { + cx.t.Fatalf("failed post maintenance hashKV request: (%v)", err) + } +} + +func TestV3CurlMaintenanceMoveleader(t *testing.T) { + testCtl(t, testV3CurlMaintenanceMoveleader, withCfg(*e2e.NewConfigNoTLS())) +} + +func testV3CurlMaintenanceMoveleader(cx ctlCtx) { + if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + Endpoint: "/v3/maintenance/transfer-leadership", + Value: `{"targetID": 123}`, + Expected: expect.ExpectedResponse{ + Value: `"message":"etcdserver: bad leader transferee"`, + }, + }); err != nil { + cx.t.Fatalf("failed post maintenance moveleader request: (%v)", err) + } +} + +func TestV3CurlMaintenanceDowngrade(t *testing.T) { + testCtl(t, testV3CurlMaintenanceDowngrade, withCfg(*e2e.NewConfigNoTLS())) +} + +func testV3CurlMaintenanceDowngrade(cx ctlCtx) { + if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + Endpoint: "/v3/maintenance/downgrade", + Value: `{"action": 0, "version": "3.0"}`, + Expected: expect.ExpectedResponse{ + Value: `"message":"etcdserver: invalid downgrade target version"`, + }, + }); err != nil { + cx.t.Fatalf("failed post maintenance downgrade request: (%v)", err) + } +} + // to manually decode; JSON marshals integer fields with // string types, so can't unmarshal with epb.CampaignResponse type campaignResponse struct {