From d687bd098981aac122c6581a3e0184bd8551c846 Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Mon, 11 Sep 2023 12:38:16 +0100 Subject: [PATCH] test: simply the expected output for some curl test cases" Signed-off-by: Benjamin Wang --- tests/e2e/v3_curl_auth_test.go | 2 +- tests/e2e/v3_curl_election_test.go | 4 ++-- tests/e2e/v3_curl_kv_test.go | 35 ++++++++++++++++++++++-------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/tests/e2e/v3_curl_auth_test.go b/tests/e2e/v3_curl_auth_test.go index 59a68efea13..8ce8c61377f 100644 --- a/tests/e2e/v3_curl_auth_test.go +++ b/tests/e2e/v3_curl_auth_test.go @@ -121,7 +121,7 @@ func testCurlV3Auth(cx ctlCtx) { if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/kv/put", Value: string(putreq), - Expected: expect.ExpectedResponse{Value: "error"}, + Expected: expect.ExpectedResponse{Value: "etcdserver: user name is empty"}, }); err != nil { cx.t.Fatalf("testCurlV3Auth failed to put without token (%v)", err) } diff --git a/tests/e2e/v3_curl_election_test.go b/tests/e2e/v3_curl_election_test.go index 8904da0f86b..01c7194ed3b 100644 --- a/tests/e2e/v3_curl_election_test.go +++ b/tests/e2e/v3_curl_election_test.go @@ -124,7 +124,7 @@ func testCurlV3ProclaimMissiongLeaderKey(cx ctlCtx) { if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ 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"}`}, + Expected: expect.ExpectedResponse{Value: `"message":"\"leader\" field must be provided"`}, }); err != nil { cx.t.Fatalf("failed post proclaim request (%v)", err) } @@ -138,7 +138,7 @@ func testCurlV3ResignMissiongLeaderKey(cx ctlCtx) { if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/election/resign", Value: `{}`, - Expected: expect.ExpectedResponse{Value: `{"error":"\"leader\" field must be provided","code":2,"message":"\"leader\" field must be provided"}`}, + Expected: expect.ExpectedResponse{Value: `"message":"\"leader\" field must be provided"`}, }); err != nil { cx.t.Fatalf("failed post resign request (%v)", err) } diff --git a/tests/e2e/v3_curl_kv_test.go b/tests/e2e/v3_curl_kv_test.go index ce5b475f744..4bee2d585a5 100644 --- a/tests/e2e/v3_curl_kv_test.go +++ b/tests/e2e/v3_curl_kv_test.go @@ -155,24 +155,41 @@ func testCurlV3KVTxn(cx ctlCtx) { jsonDat, jerr := m.Marshal(txn) require.NoError(cx.t, jerr) - expected := `"succeeded":true,"responses":[{"response_put":{"header":{"revision":"2"}}}]` - err := e2e.CURLPost(cx.epc, e2e.CURLReq{ - Endpoint: "/v3/kv/txn", - Value: string(jsonDat), - Expected: expect.ExpectedResponse{Value: expected}, - }) - require.NoErrorf(cx.t, err, "testCurlV3Txn failed") + succeeded, responses := mustExecuteTxn(cx, string(jsonDat)) + require.True(cx.t, succeeded) + require.Equal(cx.t, 1, len(responses)) + putResponse := responses[0].(map[string]interface{}) + _, ok := putResponse["response_put"] + require.True(cx.t, ok) // was crashing etcd server malformed := `{"compare":[{"result":0,"target":1,"key":"Zm9v","TargetUnion":null}],"success":[{"Request":{"RequestPut":{"key":"Zm9v","value":"YmFy"}}}]}` - err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err := e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/kv/txn", Value: malformed, - Expected: expect.ExpectedResponse{Value: "error"}, + Expected: expect.ExpectedResponse{Value: "etcdserver: key not found"}, }) require.NoErrorf(cx.t, err, "testCurlV3Txn with malformed request failed") } +func mustExecuteTxn(cx ctlCtx, reqData string) (bool, []interface{}) { + clus := cx.epc + args := e2e.CURLPrefixArgsCluster(clus.Cfg, clus.Procs[0], "POST", e2e.CURLReq{ + Endpoint: "/v3/kv/txn", + Value: string(reqData), + }) + resp, err := runCommandAndReadJsonOutput(args) + require.NoError(cx.t, err) + + succeeded, ok := resp["succeeded"] + require.True(cx.t, ok) + + responses, ok := resp["responses"] + require.True(cx.t, ok) + + return succeeded.(bool), responses.([]interface{}) +} + func testCurlV3KVCompact(cx ctlCtx) { compactRequest, err := json.Marshal(&pb.CompactionRequest{ Revision: 10000,