Browse Source

e2e: grpc-gateway cURL tests

Gyu-Ho Lee 9 years ago
parent
commit
b4f0a8853b
2 changed files with 82 additions and 2 deletions
  1. 6 2
      e2e/v2_curl_test.go
  2. 76 0
      e2e/v3_curl_test.go

+ 6 - 2
e2e/v2_curl_test.go

@@ -153,16 +153,20 @@ func cURLPrefixArgs(clus *etcdProcessCluster, method string, req cURLReq) []stri
 	}
 
 	switch method {
-	case "PUT":
+	case "POST", "PUT":
 		dt := req.value
 		if !strings.HasPrefix(dt, "{") { // for non-JSON value
 			dt = "value=" + dt
 		}
-		cmdArgs = append(cmdArgs, "-XPUT", "-d", dt)
+		cmdArgs = append(cmdArgs, "-X", method, "-d", dt)
 	}
 	return cmdArgs
 }
 
+func cURLPost(clus *etcdProcessCluster, req cURLReq) error {
+	return spawnWithExpect(cURLPrefixArgs(clus, "POST", req), req.expected)
+}
+
 func cURLPut(clus *etcdProcessCluster, req cURLReq) error {
 	return spawnWithExpect(cURLPrefixArgs(clus, "PUT", req), req.expected)
 }

+ 76 - 0
e2e/v3_curl_test.go

@@ -0,0 +1,76 @@
+// Copyright 2016 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/coreos/etcd/etcdserver/etcdserverpb"
+	"github.com/coreos/etcd/pkg/testutil"
+)
+
+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) {
+	defer testutil.AfterTest(t)
+
+	epc, err := newEtcdProcessCluster(cfg)
+	if err != nil {
+		t.Fatalf("could not start etcd process cluster (%v)", err)
+	}
+	defer func() {
+		if cerr := epc.Close(); err != nil {
+			t.Fatalf("error closing etcd processes (%v)", cerr)
+		}
+	}()
+
+	var (
+		key   = []byte("foo")
+		value = []byte("bar") // this will be automatically base64-encoded by Go
+
+		expectPut = `"revision":"`
+		expectGet = `"value":"`
+	)
+	putData, err := json.Marshal(&etcdserverpb.PutRequest{
+		Key:   key,
+		Value: value,
+	})
+	if err != nil {
+		t.Fatal(err)
+	}
+	rangeData, err := json.Marshal(&etcdserverpb.RangeRequest{
+		Key: key,
+	})
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if err := cURLPost(epc, cURLReq{endpoint: "/v3alpha/kv/put", value: string(putData), expected: expectPut}); err != nil {
+		t.Fatalf("failed put with curl (%v)", err)
+	}
+	if err := cURLPost(epc, cURLReq{endpoint: "/v3alpha/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: "/v3alpha/kv/range", value: string(rangeData), expected: expectGet, isTLS: true}); err != nil {
+			t.Fatalf("failed get with curl (%v)", err)
+		}
+	}
+}