mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests: Backport tls for etcdctl
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
@@ -112,7 +112,7 @@ func TestPeriodicCheckDetectsCorruption(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
cc := NewEtcdctl(epc.EndpointsV3())
|
||||
cc := NewEtcdctl(epc.EndpointsV3(), clientNonTLS, false)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
err := cc.Put(testutil.PickKey(int64(i)), fmt.Sprint(i))
|
||||
@@ -158,7 +158,7 @@ func TestCompactHashCheckDetectCorruption(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
cc := NewEtcdctl(epc.EndpointsV3())
|
||||
cc := NewEtcdctl(epc.EndpointsV3(), clientNonTLS, false)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
err := cc.Put(testutil.PickKey(int64(i)), fmt.Sprint(i))
|
||||
|
||||
@@ -20,18 +20,29 @@ import (
|
||||
"strings"
|
||||
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
"go.etcd.io/etcd/tests/v3/integration"
|
||||
)
|
||||
|
||||
type EtcdctlV3 struct {
|
||||
connType clientConnType
|
||||
isAutoTLS bool
|
||||
endpoints []string
|
||||
}
|
||||
|
||||
func NewEtcdctl(endpoints []string) *EtcdctlV3 {
|
||||
func NewEtcdctl(endpoints []string, connType clientConnType, isAutoTLS bool) *EtcdctlV3 {
|
||||
return &EtcdctlV3{
|
||||
endpoints: endpoints,
|
||||
connType: connType,
|
||||
isAutoTLS: isAutoTLS,
|
||||
}
|
||||
}
|
||||
|
||||
func (ctl *EtcdctlV3) Get(key string) (*clientv3.GetResponse, error) {
|
||||
var resp clientv3.GetResponse
|
||||
err := ctl.spawnJsonCmd(&resp, "get", key)
|
||||
return &resp, err
|
||||
}
|
||||
|
||||
func (ctl *EtcdctlV3) Put(key, value string) error {
|
||||
args := ctl.cmdArgs()
|
||||
args = append(args, "put", key, value)
|
||||
@@ -78,6 +89,16 @@ func (ctl *EtcdctlV3) cmdArgs(args ...string) []string {
|
||||
|
||||
func (ctl *EtcdctlV3) flags() map[string]string {
|
||||
fmap := make(map[string]string)
|
||||
if ctl.connType == clientTLS {
|
||||
if ctl.isAutoTLS {
|
||||
fmap["insecure-transport"] = "false"
|
||||
fmap["insecure-skip-tls-verify"] = "true"
|
||||
} else {
|
||||
fmap["cacert"] = integration.TestTLSInfo.TrustedCAFile
|
||||
fmap["cert"] = integration.TestTLSInfo.CertFile
|
||||
fmap["key"] = integration.TestTLSInfo.KeyFile
|
||||
}
|
||||
}
|
||||
fmap["endpoints"] = strings.Join(ctl.endpoints, ",")
|
||||
return fmap
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.etcd.io/etcd/tests/v3/integration"
|
||||
"go.uber.org/zap"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"google.golang.org/grpc"
|
||||
@@ -76,7 +77,7 @@ func tlsInfo(t testing.TB, connType clientConnType, isAutoTLS bool) (*transport.
|
||||
}
|
||||
return &tls, nil
|
||||
}
|
||||
panic("Unsupported non-auto tls")
|
||||
return &integration.TestTLSInfo, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("config %v not supported", connType)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user