Skip to content

Commit

Permalink
test: split watch and election tests to separate files
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Sep 9, 2023
1 parent 8011a53 commit 7f2949b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 32 deletions.
32 changes: 0 additions & 32 deletions tests/e2e/v3_curl_test.go → tests/e2e/v3_curl_election_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,11 @@ import (
"strconv"
"testing"

"github.com/stretchr/testify/require"

pb "go.etcd.io/etcd/api/v3/etcdserverpb"
"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"
)

func TestCurlV3Watch(t *testing.T) {
testCtl(t, testCurlV3Watch)
}

func testCurlV3Watch(cx ctlCtx) {
// store "bar" into "foo"
putreq, err := json.Marshal(&pb.PutRequest{Key: []byte("foo"), Value: []byte("bar")})
if err != nil {
cx.t.Fatal(err)
}
// watch for first update to "foo"
wcr := &pb.WatchCreateRequest{Key: []byte("foo"), StartRevision: 1}
wreq, err := json.Marshal(wcr)
if err != nil {
cx.t.Fatal(err)
}
// marshaling the grpc to json gives:
// "{"RequestUnion":{"CreateRequest":{"key":"Zm9v","start_revision":1}}}"
// but the gprc-gateway expects a different format..
wstr := `{"create_request" : ` + string(wreq) + "}"

if err = e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: "/v3/kv/put", Value: string(putreq), Expected: expect.ExpectedResponse{Value: "revision"}}); err != nil {
cx.t.Fatalf("failed testCurlV3Watch put with curl (%v)", err)
}
// expects "bar", timeout after 2 seconds since stream waits forever
err = e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: "/v3/watch", Value: wstr, Expected: expect.ExpectedResponse{Value: `"YmFy"`}, Timeout: 2})
require.ErrorContains(cx.t, err, "unexpected exit code")
}

func TestCurlV3CampaignNoTLS(t *testing.T) {
testCtl(t, testCurlV3Campaign, withCfg(*e2e.NewConfigNoTLS()))
}
Expand Down
55 changes: 55 additions & 0 deletions tests/e2e/v3_curl_watch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2023 The etcd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package e2e

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/require"

pb "go.etcd.io/etcd/api/v3/etcdserverpb"
"go.etcd.io/etcd/pkg/v3/expect"
"go.etcd.io/etcd/tests/v3/framework/e2e"
)

func TestCurlV3Watch(t *testing.T) {
testCtl(t, testCurlV3Watch)
}

func testCurlV3Watch(cx ctlCtx) {
// store "bar" into "foo"
putreq, err := json.Marshal(&pb.PutRequest{Key: []byte("foo"), Value: []byte("bar")})
if err != nil {
cx.t.Fatal(err)
}
// watch for first update to "foo"
wcr := &pb.WatchCreateRequest{Key: []byte("foo"), StartRevision: 1}
wreq, err := json.Marshal(wcr)
if err != nil {
cx.t.Fatal(err)
}
// marshaling the grpc to json gives:
// "{"RequestUnion":{"CreateRequest":{"key":"Zm9v","start_revision":1}}}"
// but the gprc-gateway expects a different format..
wstr := `{"create_request" : ` + string(wreq) + "}"

if err = e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: "/v3/kv/put", Value: string(putreq), Expected: expect.ExpectedResponse{Value: "revision"}}); err != nil {
cx.t.Fatalf("failed testCurlV3Watch put with curl (%v)", err)
}
// expects "bar", timeout after 2 seconds since stream waits forever
err = e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: "/v3/watch", Value: wstr, Expected: expect.ExpectedResponse{Value: `"YmFy"`}, Timeout: 2})
require.ErrorContains(cx.t, err, "unexpected exit code")
}

0 comments on commit 7f2949b

Please sign in to comment.