mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
e2e: test /v3alpha,beta in v3 curl tests
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
This commit is contained in:
parent
c706c6e238
commit
0f9f452722
@ -16,6 +16,7 @@ package e2e
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
|
||||
@ -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)
|
||||
@ -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)
|
||||
@ -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"
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -179,7 +205,7 @@ 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)
|
||||
}
|
||||
|
||||
@ -187,7 +213,7 @@ func TestV3CurlAuth(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
|
||||
@ -195,12 +221,12 @@ func TestV3CurlAuth(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user