Skip to content

Commit

Permalink
e2e: test /v3alpha,beta in v3 curl tests
Browse files Browse the repository at this point in the history
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Nov 15, 2017
1 parent c706c6e commit 0f9f452
Showing 1 changed file with 49 additions and 23 deletions.
72 changes: 49 additions & 23 deletions e2e/v3_curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package e2e

import (
"encoding/json"
"path"
"testing"

pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
Expand All @@ -24,12 +25,31 @@ import (
"github.com/grpc-ecosystem/grpc-gateway/runtime"
)

func TestV3CurlPutGetNoTLS(t *testing.T) { testCurlPutGetGRPCGateway(t, &configNoTLS) }
func TestV3CurlPutGetAutoTLS(t *testing.T) { testCurlPutGetGRPCGateway(t, &configAutoTLS) }
func TestV3CurlPutGetAllTLS(t *testing.T) { testCurlPutGetGRPCGateway(t, &configTLS) }
func TestV3CurlPutGetPeerTLS(t *testing.T) { testCurlPutGetGRPCGateway(t, &configPeerTLS) }
func TestV3CurlPutGetClientTLS(t *testing.T) { testCurlPutGetGRPCGateway(t, &configClientTLS) }
func testCurlPutGetGRPCGateway(t *testing.T, cfg *etcdProcessClusterConfig) {
// TODO: remove /v3alpha tests in 3.4 release

func TestV3CurlPutGetNoTLSAlpha(t *testing.T) { testCurlPutGetGRPCGateway(t, &configNoTLS, "/v3alpha") }
func TestV3CurlPutGetNoTLSBeta(t *testing.T) { testCurlPutGetGRPCGateway(t, &configNoTLS, "/v3beta") }
func TestV3CurlPutGetAutoTLSAlpha(t *testing.T) {
testCurlPutGetGRPCGateway(t, &configAutoTLS, "/v3alpha")
}
func TestV3CurlPutGetAutoTLSBeta(t *testing.T) {
testCurlPutGetGRPCGateway(t, &configAutoTLS, "/v3beta")
}
func TestV3CurlPutGetAllTLSAlpha(t *testing.T) { testCurlPutGetGRPCGateway(t, &configTLS, "/v3alpha") }
func TestV3CurlPutGetAllTLSBeta(t *testing.T) { testCurlPutGetGRPCGateway(t, &configTLS, "/v3beta") }
func TestV3CurlPutGetPeerTLSAlpha(t *testing.T) {
testCurlPutGetGRPCGateway(t, &configPeerTLS, "/v3alpha")
}
func TestV3CurlPutGetPeerTLSBeta(t *testing.T) {
testCurlPutGetGRPCGateway(t, &configPeerTLS, "/v3beta")
}
func TestV3CurlPutGetClientTLSAlpha(t *testing.T) {
testCurlPutGetGRPCGateway(t, &configClientTLS, "/v3alpha")
}
func TestV3CurlPutGetClientTLSBeta(t *testing.T) {
testCurlPutGetGRPCGateway(t, &configClientTLS, "/v3beta")
}
func testCurlPutGetGRPCGateway(t *testing.T, cfg *etcdProcessClusterConfig, pathPrefix string) {
defer testutil.AfterTest(t)

epc, err := newEtcdProcessCluster(cfg)
Expand Down Expand Up @@ -63,21 +83,23 @@ func testCurlPutGetGRPCGateway(t *testing.T, cfg *etcdProcessClusterConfig) {
t.Fatal(err)
}

if err := cURLPost(epc, cURLReq{endpoint: "/v3beta/kv/put", value: string(putData), expected: expectPut}); err != nil {
if err := cURLPost(epc, cURLReq{endpoint: path.Join(pathPrefix, "/kv/put"), value: string(putData), expected: expectPut}); err != nil {
t.Fatalf("failed put with curl (%v)", err)
}
if err := cURLPost(epc, cURLReq{endpoint: "/v3beta/kv/range", value: string(rangeData), expected: expectGet}); err != nil {
if err := cURLPost(epc, cURLReq{endpoint: path.Join(pathPrefix, "/kv/range"), value: string(rangeData), expected: expectGet}); err != nil {
t.Fatalf("failed get with curl (%v)", err)
}

if cfg.clientTLS == clientTLSAndNonTLS {
if err := cURLPost(epc, cURLReq{endpoint: "/v3beta/kv/range", value: string(rangeData), expected: expectGet, isTLS: true}); err != nil {
if err := cURLPost(epc, cURLReq{endpoint: path.Join(pathPrefix, "/kv/range"), value: string(rangeData), expected: expectGet, isTLS: true}); err != nil {
t.Fatalf("failed get with curl (%v)", err)
}
}
}

func TestV3CurlWatch(t *testing.T) {
func TestV3CurlWatchAlpha(t *testing.T) { testV3CurlWatch(t, "/v3alpha") }
func TestV3CurlWatchBeta(t *testing.T) { testV3CurlWatch(t, "/v3beta") }
func testV3CurlWatch(t *testing.T, pathPrefix string) {
defer testutil.AfterTest(t)

epc, err := newEtcdProcessCluster(&configNoTLS)
Expand All @@ -95,7 +117,7 @@ func TestV3CurlWatch(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err = cURLPost(epc, cURLReq{endpoint: "/v3beta/kv/put", value: string(putreq), expected: "revision"}); err != nil {
if err = cURLPost(epc, cURLReq{endpoint: path.Join(pathPrefix, "/kv/put"), value: string(putreq), expected: "revision"}); err != nil {
t.Fatalf("failed put with curl (%v)", err)
}
// watch for first update to "foo"
Expand All @@ -109,12 +131,14 @@ func TestV3CurlWatch(t *testing.T) {
// but the gprc-gateway expects a different format..
wstr := `{"create_request" : ` + string(wreq) + "}"
// expects "bar", timeout after 2 seconds since stream waits forever
if err = cURLPost(epc, cURLReq{endpoint: "/v3beta/watch", value: wstr, expected: `"YmFy"`, timeout: 2}); err != nil {
if err = cURLPost(epc, cURLReq{endpoint: path.Join(pathPrefix, "/watch"), value: wstr, expected: `"YmFy"`, timeout: 2}); err != nil {
t.Fatal(err)
}
}

func TestV3CurlTxn(t *testing.T) {
func TestV3CurlTxnAlpha(t *testing.T) { testV3CurlTxn(t, "/v3alpha") }
func TestV3CurlTxnBeta(t *testing.T) { testV3CurlTxn(t, "/v3beta") }
func testV3CurlTxn(t *testing.T, pathPrefix string) {
defer testutil.AfterTest(t)
epc, err := newEtcdProcessCluster(&configNoTLS)
if err != nil {
Expand Down Expand Up @@ -152,18 +176,20 @@ func TestV3CurlTxn(t *testing.T) {
t.Fatal(jerr)
}
expected := `"succeeded":true,"responses":[{"response_put":{"header":{"revision":"2"}}}]`
if err = cURLPost(epc, cURLReq{endpoint: "/v3beta/kv/txn", value: string(jsonDat), expected: expected}); err != nil {
if err = cURLPost(epc, cURLReq{endpoint: path.Join(pathPrefix, "/kv/txn"), value: string(jsonDat), expected: expected}); err != nil {
t.Fatalf("failed txn with curl (%v)", err)
}

// was crashing etcd server
malformed := `{"compare":[{"result":0,"target":1,"key":"Zm9v","TargetUnion":null}],"success":[{"Request":{"RequestPut":{"key":"Zm9v","value":"YmFy"}}}]}`
if err = cURLPost(epc, cURLReq{endpoint: "/v3beta/kv/txn", value: malformed, expected: "error"}); err != nil {
if err = cURLPost(epc, cURLReq{endpoint: path.Join(pathPrefix, "/kv/txn"), value: malformed, expected: "error"}); err != nil {
t.Fatalf("failed put with curl (%v)", err)
}
}

func TestV3CurlAuth(t *testing.T) {
func TestV3CurlAuthAlpha(t *testing.T) { testV3CurlAuth(t, "/v3alpha") }
func TestV3CurlAuthBeta(t *testing.T) { testV3CurlAuth(t, "/v3beta") }
func testV3CurlAuth(t *testing.T, pathPrefix string) {
defer testutil.AfterTest(t)
epc, err := newEtcdProcessCluster(&configNoTLS)
if err != nil {
Expand All @@ -179,28 +205,28 @@ func TestV3CurlAuth(t *testing.T) {
userreq, err := json.Marshal(&pb.AuthUserAddRequest{Name: string("root"), Password: string("toor")})
testutil.AssertNil(t, err)

if err = cURLPost(epc, cURLReq{endpoint: "/v3beta/auth/user/add", value: string(userreq), expected: "revision"}); err != nil {
if err = cURLPost(epc, cURLReq{endpoint: path.Join(pathPrefix, "/auth/user/add"), value: string(userreq), expected: "revision"}); err != nil {
t.Fatalf("failed add user with curl (%v)", err)
}

// create root role
rolereq, err := json.Marshal(&pb.AuthRoleAddRequest{Name: string("root")})
testutil.AssertNil(t, err)

if err = cURLPost(epc, cURLReq{endpoint: "/v3beta/auth/role/add", value: string(rolereq), expected: "revision"}); err != nil {
if err = cURLPost(epc, cURLReq{endpoint: path.Join(pathPrefix, "/auth/role/add"), value: string(rolereq), expected: "revision"}); err != nil {
t.Fatalf("failed create role with curl (%v)", err)
}

// grant root role
grantrolereq, err := json.Marshal(&pb.AuthUserGrantRoleRequest{User: string("root"), Role: string("root")})
testutil.AssertNil(t, err)

if err = cURLPost(epc, cURLReq{endpoint: "/v3beta/auth/user/grant", value: string(grantrolereq), expected: "revision"}); err != nil {
if err = cURLPost(epc, cURLReq{endpoint: path.Join(pathPrefix, "/auth/user/grant"), value: string(grantrolereq), expected: "revision"}); err != nil {
t.Fatalf("failed grant role with curl (%v)", err)
}

// enable auth
if err = cURLPost(epc, cURLReq{endpoint: "/v3beta/auth/enable", value: string("{}"), expected: "revision"}); err != nil {
if err = cURLPost(epc, cURLReq{endpoint: path.Join(pathPrefix, "/auth/enable"), value: string("{}"), expected: "revision"}); err != nil {
t.Fatalf("failed enable auth with curl (%v)", err)
}

Expand All @@ -209,7 +235,7 @@ func TestV3CurlAuth(t *testing.T) {
testutil.AssertNil(t, err)

// fail put no auth
if err = cURLPost(epc, cURLReq{endpoint: "/v3beta/kv/put", value: string(putreq), expected: "error"}); err != nil {
if err = cURLPost(epc, cURLReq{endpoint: path.Join(pathPrefix, "/kv/put"), value: string(putreq), expected: "error"}); err != nil {
t.Fatalf("failed no auth put with curl (%v)", err)
}

Expand All @@ -223,7 +249,7 @@ func TestV3CurlAuth(t *testing.T) {
lineFunc = func(txt string) bool { return true }
)

cmdArgs = cURLPrefixArgs(epc, "POST", cURLReq{endpoint: "/v3beta/auth/authenticate", value: string(authreq)})
cmdArgs = cURLPrefixArgs(epc, "POST", cURLReq{endpoint: path.Join(pathPrefix, "/auth/authenticate"), value: string(authreq)})
proc, err := spawnCmd(cmdArgs)
testutil.AssertNil(t, err)

Expand All @@ -241,7 +267,7 @@ func TestV3CurlAuth(t *testing.T) {
authHeader = "Authorization : " + token

// put with auth
if err = cURLPost(epc, cURLReq{endpoint: "/v3beta/kv/put", value: string(putreq), header: authHeader, expected: "revision"}); err != nil {
if err = cURLPost(epc, cURLReq{endpoint: path.Join(pathPrefix, "/kv/put"), value: string(putreq), header: authHeader, expected: "revision"}); err != nil {
t.Fatalf("failed auth put with curl (%v)", err)
}
}

0 comments on commit 0f9f452

Please sign in to comment.