Skip to content

Commit

Permalink
Merge pull request etcd-io#16572 from ahrtr/fix_curl_test_20230911
Browse files Browse the repository at this point in the history
test: simply the expected output for some curl test cases
  • Loading branch information
ahrtr authored Sep 12, 2023
2 parents d506a72 + d687bd0 commit cc282a8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
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

0 comments on commit cc282a8

Please sign in to comment.