Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: simply the expected output for some curl test cases #16572

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/e2e/v3_curl_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/v3_curl_election_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
35 changes: 26 additions & 9 deletions tests/e2e/v3_curl_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading