mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00

Marked all 'integrational, e2e' as skipped in the --short mode. Thanks to this we will be able to significantly simplify ./test script. The run currently takes ~23s. With (follow up) move of ~clientv3/snapshot to integration tests (as part of modularization), we can expect this to fall to 5-10s. ``` % time go test --short ./... --count=1 ok go.etcd.io/etcd/v3 0.098s ? go.etcd.io/etcd/v3/Documentation/learning/lock/client [no test files] ? go.etcd.io/etcd/v3/Documentation/learning/lock/storage [no test files] ok go.etcd.io/etcd/v3/auth 0.724s ? go.etcd.io/etcd/v3/auth/authpb [no test files] ok go.etcd.io/etcd/v3/client 0.166s ok go.etcd.io/etcd/v3/client/integration 0.166s ok go.etcd.io/etcd/v3/clientv3 3.219s ok go.etcd.io/etcd/v3/clientv3/balancer 1.102s ? go.etcd.io/etcd/v3/clientv3/balancer/connectivity [no test files] ? go.etcd.io/etcd/v3/clientv3/balancer/picker [no test files] ? go.etcd.io/etcd/v3/clientv3/balancer/resolver/endpoint [no test files] ok go.etcd.io/etcd/v3/clientv3/clientv3util 0.096s [no tests to run] ok go.etcd.io/etcd/v3/clientv3/concurrency 3.323s ? go.etcd.io/etcd/v3/clientv3/credentials [no test files] ok go.etcd.io/etcd/v3/clientv3/integration 0.131s ? go.etcd.io/etcd/v3/clientv3/leasing [no test files] ? go.etcd.io/etcd/v3/clientv3/mirror [no test files] ok go.etcd.io/etcd/v3/clientv3/namespace 0.041s ok go.etcd.io/etcd/v3/clientv3/naming 0.115s ok go.etcd.io/etcd/v3/clientv3/ordering 0.121s ok go.etcd.io/etcd/v3/clientv3/snapshot 19.325s ok go.etcd.io/etcd/v3/clientv3/yaml 0.090s ok go.etcd.io/etcd/v3/contrib/raftexample 7.572s ? go.etcd.io/etcd/v3/contrib/recipes [no test files] ok go.etcd.io/etcd/v3/embed 0.282s ok go.etcd.io/etcd/v3/etcdctl 0.054s ? go.etcd.io/etcd/v3/etcdctl/ctlv2 [no test files] ok go.etcd.io/etcd/v3/etcdctl/ctlv2/command 0.117s ? go.etcd.io/etcd/v3/etcdctl/ctlv3 [no test files] ok go.etcd.io/etcd/v3/etcdctl/ctlv3/command 0.070s ok go.etcd.io/etcd/v3/etcdmain 0.172s ok go.etcd.io/etcd/v3/etcdserver 1.698s ? go.etcd.io/etcd/v3/etcdserver/api [no test files] ok go.etcd.io/etcd/v3/etcdserver/api/etcdhttp 0.075s ok go.etcd.io/etcd/v3/etcdserver/api/membership 0.104s ? go.etcd.io/etcd/v3/etcdserver/api/membership/membershippb [no test files] ok go.etcd.io/etcd/v3/etcdserver/api/rafthttp 0.181s ok go.etcd.io/etcd/v3/etcdserver/api/snap 0.078s ? go.etcd.io/etcd/v3/etcdserver/api/snap/snappb [no test files] ok go.etcd.io/etcd/v3/etcdserver/api/v2auth 0.142s ok go.etcd.io/etcd/v3/etcdserver/api/v2discovery 0.035s ok go.etcd.io/etcd/v3/etcdserver/api/v2error 0.043s ok go.etcd.io/etcd/v3/etcdserver/api/v2http 0.070s ok go.etcd.io/etcd/v3/etcdserver/api/v2http/httptypes 0.031s ? go.etcd.io/etcd/v3/etcdserver/api/v2stats [no test files] ok go.etcd.io/etcd/v3/etcdserver/api/v2store 0.645s ok go.etcd.io/etcd/v3/etcdserver/api/v2v3 0.218s ? go.etcd.io/etcd/v3/etcdserver/api/v3alarm [no test files] ? go.etcd.io/etcd/v3/etcdserver/api/v3client [no test files] ok go.etcd.io/etcd/v3/etcdserver/api/v3compactor 1.765s ? go.etcd.io/etcd/v3/etcdserver/api/v3election [no test files] ? go.etcd.io/etcd/v3/etcdserver/api/v3election/v3electionpb [no test files] ? go.etcd.io/etcd/v3/etcdserver/api/v3election/v3electionpb/gw [no test files] ? go.etcd.io/etcd/v3/etcdserver/api/v3lock [no test files] ? go.etcd.io/etcd/v3/etcdserver/api/v3lock/v3lockpb [no test files] ? go.etcd.io/etcd/v3/etcdserver/api/v3lock/v3lockpb/gw [no test files] ok go.etcd.io/etcd/v3/etcdserver/api/v3rpc 0.091s ok go.etcd.io/etcd/v3/etcdserver/api/v3rpc/rpctypes 0.012s ok go.etcd.io/etcd/v3/etcdserver/cindex 0.054s ok go.etcd.io/etcd/v3/etcdserver/etcdserverpb 0.039s ? go.etcd.io/etcd/v3/etcdserver/etcdserverpb/gw [no test files] ok go.etcd.io/etcd/v3/functional/agent 0.094s ? go.etcd.io/etcd/v3/functional/cmd/etcd-agent [no test files] ? go.etcd.io/etcd/v3/functional/cmd/etcd-proxy [no test files] ? go.etcd.io/etcd/v3/functional/cmd/etcd-runner [no test files] ? go.etcd.io/etcd/v3/functional/cmd/etcd-tester [no test files] ok go.etcd.io/etcd/v3/functional/rpcpb 0.060s ? go.etcd.io/etcd/v3/functional/runner [no test files] ok go.etcd.io/etcd/v3/functional/tester 0.079s ok go.etcd.io/etcd/v3/integration 0.684s ok go.etcd.io/etcd/v3/integration/embed 0.101s ok go.etcd.io/etcd/v3/lease 3.455s ok go.etcd.io/etcd/v3/lease/leasehttp 2.185s ? go.etcd.io/etcd/v3/lease/leasepb [no test files] ok go.etcd.io/etcd/v3/mvcc 7.246s ok go.etcd.io/etcd/v3/mvcc/backend 0.354s ? go.etcd.io/etcd/v3/mvcc/mvccpb [no test files] ok go.etcd.io/etcd/v3/pkg/adt 0.025s ? go.etcd.io/etcd/v3/pkg/contention [no test files] ? go.etcd.io/etcd/v3/pkg/cpuutil [no test files] ok go.etcd.io/etcd/v3/pkg/crc 0.008s ? go.etcd.io/etcd/v3/pkg/debugutil [no test files] ok go.etcd.io/etcd/v3/pkg/expect 0.015s ok go.etcd.io/etcd/v3/pkg/fileutil 0.268s ok go.etcd.io/etcd/v3/pkg/flags 0.021s ok go.etcd.io/etcd/v3/pkg/httputil 0.020s ok go.etcd.io/etcd/v3/pkg/idutil 0.008s ok go.etcd.io/etcd/v3/pkg/ioutil 0.025s ok go.etcd.io/etcd/v3/pkg/logutil 0.047s ? go.etcd.io/etcd/v3/pkg/mock/mockserver [no test files] ? go.etcd.io/etcd/v3/pkg/mock/mockstorage [no test files] ? go.etcd.io/etcd/v3/pkg/mock/mockstore [no test files] ? go.etcd.io/etcd/v3/pkg/mock/mockwait [no test files] ok go.etcd.io/etcd/v3/pkg/netutil 1.024s ok go.etcd.io/etcd/v3/pkg/osutil 0.021s ok go.etcd.io/etcd/v3/pkg/pathutil 0.008s ok go.etcd.io/etcd/v3/pkg/pbutil 0.008s ok go.etcd.io/etcd/v3/pkg/proxy 4.081s ok go.etcd.io/etcd/v3/pkg/report 0.008s ? go.etcd.io/etcd/v3/pkg/runtime [no test files] ok go.etcd.io/etcd/v3/pkg/schedule 0.009s ok go.etcd.io/etcd/v3/pkg/srv 0.019s ok go.etcd.io/etcd/v3/pkg/stringutil 0.008s ? go.etcd.io/etcd/v3/pkg/systemd [no test files] ok go.etcd.io/etcd/v3/pkg/testutil 0.023s ok go.etcd.io/etcd/v3/pkg/tlsutil 3.965s ok go.etcd.io/etcd/v3/pkg/traceutil 0.034s ok go.etcd.io/etcd/v3/pkg/transport 0.532s ok go.etcd.io/etcd/v3/pkg/types 0.028s ok go.etcd.io/etcd/v3/pkg/wait 0.023s ok go.etcd.io/etcd/v3/proxy/grpcproxy 0.101s ? go.etcd.io/etcd/v3/proxy/grpcproxy/adapter [no test files] ? go.etcd.io/etcd/v3/proxy/grpcproxy/cache [no test files] ok go.etcd.io/etcd/v3/proxy/httpproxy 0.044s ok go.etcd.io/etcd/v3/proxy/tcpproxy 0.047s ok go.etcd.io/etcd/v3/raft 0.312s ok go.etcd.io/etcd/v3/raft/confchange 0.183s ok go.etcd.io/etcd/v3/raft/quorum 0.316s ok go.etcd.io/etcd/v3/raft/raftpb 0.024s ok go.etcd.io/etcd/v3/raft/rafttest 0.640s ok go.etcd.io/etcd/v3/raft/tracker 0.026s ok go.etcd.io/etcd/v3/tests/e2e 0.077s ? go.etcd.io/etcd/v3/tools/benchmark [no test files] ? go.etcd.io/etcd/v3/tools/benchmark/cmd [no test files] ? go.etcd.io/etcd/v3/tools/etcd-dump-db [no test files] ok go.etcd.io/etcd/v3/tools/etcd-dump-logs 0.088s ? go.etcd.io/etcd/v3/tools/etcd-dump-metrics [no test files] ? go.etcd.io/etcd/v3/tools/local-tester/bridge [no test files] ? go.etcd.io/etcd/v3/version [no test files] ok go.etcd.io/etcd/v3/wal 1.517s ? go.etcd.io/etcd/v3/wal/walpb [no test files] go test --short ./... --count=1 76.12s user 12.57s system 375% cpu 23.635 total ```
206 lines
6.6 KiB
Go
206 lines
6.6 KiB
Go
// 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 (
|
|
"fmt"
|
|
"math/rand"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"go.etcd.io/etcd/v3/pkg/testutil"
|
|
)
|
|
|
|
func TestV2CurlNoTLS(t *testing.T) { testCurlPutGet(t, &configNoTLS) }
|
|
func TestV2CurlAutoTLS(t *testing.T) { testCurlPutGet(t, &configAutoTLS) }
|
|
func TestV2CurlAllTLS(t *testing.T) { testCurlPutGet(t, &configTLS) }
|
|
func TestV2CurlPeerTLS(t *testing.T) { testCurlPutGet(t, &configPeerTLS) }
|
|
func TestV2CurlClientTLS(t *testing.T) { testCurlPutGet(t, &configClientTLS) }
|
|
func TestV2CurlClientBoth(t *testing.T) { testCurlPutGet(t, &configClientBoth) }
|
|
func testCurlPutGet(t *testing.T, cfg *etcdProcessClusterConfig) {
|
|
defer testutil.AfterTest(t)
|
|
|
|
// test doesn't use quorum gets, so ensure there are no followers to avoid
|
|
// stale reads that will break the test
|
|
cfg = configStandalone(*cfg)
|
|
|
|
cfg.enableV2 = true
|
|
epc, err := newEtcdProcessCluster(t, cfg)
|
|
if err != nil {
|
|
t.Fatalf("could not start etcd process cluster (%v)", err)
|
|
}
|
|
defer func() {
|
|
if err := epc.Close(); err != nil {
|
|
t.Fatalf("error closing etcd processes (%v)", err)
|
|
}
|
|
}()
|
|
|
|
var (
|
|
expectPut = `{"action":"set","node":{"key":"/foo","value":"bar","`
|
|
expectGet = `{"action":"get","node":{"key":"/foo","value":"bar","`
|
|
)
|
|
if err := cURLPut(epc, cURLReq{endpoint: "/v2/keys/foo", value: "bar", expected: expectPut}); err != nil {
|
|
t.Fatalf("failed put with curl (%v)", err)
|
|
}
|
|
if err := cURLGet(epc, cURLReq{endpoint: "/v2/keys/foo", expected: expectGet}); err != nil {
|
|
t.Fatalf("failed get with curl (%v)", err)
|
|
}
|
|
if cfg.clientTLS == clientTLSAndNonTLS {
|
|
if err := cURLGet(epc, cURLReq{endpoint: "/v2/keys/foo", expected: expectGet, isTLS: true}); err != nil {
|
|
t.Fatalf("failed get with curl (%v)", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestV2CurlIssue5182(t *testing.T) {
|
|
os.Setenv("ETCDCTL_API", "2")
|
|
defer os.Unsetenv("ETCDCTL_API")
|
|
defer testutil.AfterTest(t)
|
|
|
|
copied := configNoTLS
|
|
copied.enableV2 = true
|
|
epc := setupEtcdctlTest(t, &copied, false)
|
|
defer func() {
|
|
if err := epc.Close(); err != nil {
|
|
t.Fatalf("error closing etcd processes (%v)", err)
|
|
}
|
|
}()
|
|
|
|
expectPut := `{"action":"set","node":{"key":"/foo","value":"bar","`
|
|
if err := cURLPut(epc, cURLReq{endpoint: "/v2/keys/foo", value: "bar", expected: expectPut}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
expectUserAdd := `{"user":"foo","roles":null}`
|
|
if err := cURLPut(epc, cURLReq{endpoint: "/v2/auth/users/foo", value: `{"user":"foo", "password":"pass"}`, expected: expectUserAdd}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
expectRoleAdd := `{"role":"foo","permissions":{"kv":{"read":["/foo/*"],"write":null}}`
|
|
if err := cURLPut(epc, cURLReq{endpoint: "/v2/auth/roles/foo", value: `{"role":"foo", "permissions": {"kv": {"read": ["/foo/*"]}}}`, expected: expectRoleAdd}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
expectUserUpdate := `{"user":"foo","roles":["foo"]}`
|
|
if err := cURLPut(epc, cURLReq{endpoint: "/v2/auth/users/foo", value: `{"user": "foo", "grant": ["foo"]}`, expected: expectUserUpdate}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := etcdctlUserAdd(epc, "root", "a"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := etcdctlAuthEnable(epc); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := cURLGet(epc, cURLReq{endpoint: "/v2/keys/foo/", username: "root", password: "a", expected: "bar"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := cURLGet(epc, cURLReq{endpoint: "/v2/keys/foo/", username: "foo", password: "pass", expected: "bar"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := cURLGet(epc, cURLReq{endpoint: "/v2/keys/foo/", username: "foo", password: "", expected: "bar"}); err != nil {
|
|
if !strings.Contains(err.Error(), `The request requires user authentication`) {
|
|
t.Fatalf("expected 'The request requires user authentication' error, got %v", err)
|
|
}
|
|
} else {
|
|
t.Fatalf("expected 'The request requires user authentication' error")
|
|
}
|
|
}
|
|
|
|
type cURLReq struct {
|
|
username string
|
|
password string
|
|
|
|
isTLS bool
|
|
timeout int
|
|
|
|
endpoint string
|
|
|
|
value string
|
|
expected string
|
|
header string
|
|
|
|
metricsURLScheme string
|
|
|
|
ciphers string
|
|
}
|
|
|
|
// cURLPrefixArgs builds the beginning of a curl command for a given key
|
|
// addressed to a random URL in the given cluster.
|
|
func cURLPrefixArgs(clus *etcdProcessCluster, method string, req cURLReq) []string {
|
|
var (
|
|
cmdArgs = []string{"curl"}
|
|
acurl = clus.procs[rand.Intn(clus.cfg.clusterSize)].Config().acurl
|
|
)
|
|
if req.metricsURLScheme != "https" {
|
|
if req.isTLS {
|
|
if clus.cfg.clientTLS != clientTLSAndNonTLS {
|
|
panic("should not use cURLPrefixArgsUseTLS when serving only TLS or non-TLS")
|
|
}
|
|
cmdArgs = append(cmdArgs, "--cacert", caPath, "--cert", certPath, "--key", privateKeyPath)
|
|
acurl = toTLS(clus.procs[rand.Intn(clus.cfg.clusterSize)].Config().acurl)
|
|
} else if clus.cfg.clientTLS == clientTLS {
|
|
if !clus.cfg.noCN {
|
|
cmdArgs = append(cmdArgs, "--cacert", caPath, "--cert", certPath, "--key", privateKeyPath)
|
|
} else {
|
|
cmdArgs = append(cmdArgs, "--cacert", caPath, "--cert", certPath3, "--key", privateKeyPath3)
|
|
}
|
|
}
|
|
}
|
|
if req.metricsURLScheme != "" {
|
|
acurl = clus.procs[rand.Intn(clus.cfg.clusterSize)].EndpointsMetrics()[0]
|
|
}
|
|
ep := acurl + req.endpoint
|
|
|
|
if req.username != "" || req.password != "" {
|
|
cmdArgs = append(cmdArgs, "-L", "-u", fmt.Sprintf("%s:%s", req.username, req.password), ep)
|
|
} else {
|
|
cmdArgs = append(cmdArgs, "-L", ep)
|
|
}
|
|
if req.timeout != 0 {
|
|
cmdArgs = append(cmdArgs, "-m", fmt.Sprintf("%d", req.timeout))
|
|
}
|
|
|
|
if req.header != "" {
|
|
cmdArgs = append(cmdArgs, "-H", req.header)
|
|
}
|
|
|
|
if req.ciphers != "" {
|
|
cmdArgs = append(cmdArgs, "--ciphers", req.ciphers)
|
|
}
|
|
|
|
switch method {
|
|
case "POST", "PUT":
|
|
dt := req.value
|
|
if !strings.HasPrefix(dt, "{") { // for non-JSON value
|
|
dt = "value=" + 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)
|
|
}
|
|
|
|
func cURLGet(clus *etcdProcessCluster, req cURLReq) error {
|
|
return spawnWithExpect(cURLPrefixArgs(clus, "GET", req), req.expected)
|
|
}
|