mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
test: add test case to cover all election REST APIs
Signed-off-by: Benjamin Wang <wachao@vmware.com>
This commit is contained in:
parent
9e7f83799f
commit
18f70c2553
@ -23,6 +23,8 @@ import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.etcd.io/etcd/pkg/v3/expect"
|
||||
epb "go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb"
|
||||
"go.etcd.io/etcd/tests/v3/framework/e2e"
|
||||
@ -33,6 +35,7 @@ func TestCurlV3CampaignNoTLS(t *testing.T) {
|
||||
}
|
||||
|
||||
func testCurlV3Campaign(cx ctlCtx) {
|
||||
// campaign
|
||||
cdata, err := json.Marshal(&epb.CampaignRequest{
|
||||
Name: []byte("/election-prefix"),
|
||||
Value: []byte("v1"),
|
||||
@ -65,6 +68,27 @@ func testCurlV3Campaign(cx ctlCtx) {
|
||||
cx.t.Fatalf("failed to decode leader key %v", err)
|
||||
}
|
||||
|
||||
// observe
|
||||
observeReq, err := json.Marshal(&epb.LeaderRequest{
|
||||
Name: []byte("/election-prefix"),
|
||||
})
|
||||
require.NoError(cx.t, err)
|
||||
|
||||
clus := cx.epc
|
||||
args := e2e.CURLPrefixArgsCluster(clus.Cfg, clus.Procs[0], "POST", e2e.CURLReq{
|
||||
Endpoint: "/v3/election/observe",
|
||||
Value: string(observeReq),
|
||||
})
|
||||
proc, err := e2e.SpawnCmd(args, nil)
|
||||
require.NoError(cx.t, err)
|
||||
|
||||
proc.ExpectWithContext(context.TODO(), expect.ExpectedResponse{
|
||||
Value: fmt.Sprintf(`"key":"%s"`, cresp.Leader.Key),
|
||||
})
|
||||
err = proc.Stop()
|
||||
require.NoError(cx.t, err)
|
||||
|
||||
// proclaim
|
||||
rev, _ := strconv.ParseInt(cresp.Leader.Rev, 10, 64)
|
||||
lease, _ := strconv.ParseInt(cresp.Leader.Lease, 10, 64)
|
||||
pdata, err := json.Marshal(&epb.ProclaimRequest{
|
||||
@ -120,6 +144,20 @@ func testCurlV3ResignMissiongLeaderKey(cx ctlCtx) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCurlV3ElectionLeader(t *testing.T) {
|
||||
testCtl(t, testCurlV3ElectionLeader, withCfg(*e2e.NewConfigNoTLS()))
|
||||
}
|
||||
|
||||
func testCurlV3ElectionLeader(cx ctlCtx) {
|
||||
if err := e2e.CURLPost(cx.epc, e2e.CURLReq{
|
||||
Endpoint: "/v3/election/leader",
|
||||
Value: `{"name": "aGVsbG8="}`, // base64 encoded string "hello"
|
||||
Expected: expect.ExpectedResponse{Value: `election: no leader`},
|
||||
}); err != nil {
|
||||
cx.t.Fatalf("testCurlV3ElectionLeader failed to get leader (%v)", err)
|
||||
}
|
||||
}
|
||||
|
||||
// to manually decode; JSON marshals integer fields with
|
||||
// string types, so can't unmarshal with epb.CampaignResponse
|
||||
type campaignResponse struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user