mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
feat(test): add TLS tests
add some basic TLS tests
This commit is contained in:
@@ -18,7 +18,7 @@ func TestKillLeader(t *testing.T) {
|
||||
procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
|
||||
|
||||
clusterSize := 5
|
||||
argGroup, etcds, err := createCluster(clusterSize, procAttr)
|
||||
argGroup, etcds, err := createCluster(clusterSize, procAttr, false)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("cannot create cluster")
|
||||
@@ -70,7 +70,7 @@ func TestKillRandom(t *testing.T) {
|
||||
procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
|
||||
|
||||
clusterSize := 9
|
||||
argGroup, etcds, err := createCluster(clusterSize, procAttr)
|
||||
argGroup, etcds, err := createCluster(clusterSize, procAttr, false)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("cannot create cluster")
|
||||
@@ -122,12 +122,12 @@ func TestKillRandom(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkEtcdDirectCall(b *testing.B) {
|
||||
func templateBenchmarkEtcdDirectCall(b *testing.B, tls bool) {
|
||||
procAttr := new(os.ProcAttr)
|
||||
procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
|
||||
|
||||
clusterSize := 3
|
||||
_, etcds, _ := createCluster(clusterSize, procAttr)
|
||||
_, etcds, _ := createCluster(clusterSize, procAttr, tls)
|
||||
|
||||
defer destroyCluster(etcds)
|
||||
|
||||
@@ -140,3 +140,11 @@ func BenchmarkEtcdDirectCall(b *testing.B) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkEtcdDirectCall(b *testing.B) {
|
||||
templateBenchmarkEtcdDirectCall(b, false)
|
||||
}
|
||||
|
||||
func BenchmarkEtcdDirectCallTls(b *testing.B) {
|
||||
templateBenchmarkEtcdDirectCall(b, true)
|
||||
}
|
||||
|
||||
14
etcd_test.go
14
etcd_test.go
@@ -110,13 +110,13 @@ func TestSingleNodeRecovery(t *testing.T) {
|
||||
}
|
||||
|
||||
// Create a three nodes and try to set value
|
||||
func TestSimpleMultiNode(t *testing.T) {
|
||||
func templateTestSimpleMultiNode(t *testing.T, tls bool) {
|
||||
procAttr := new(os.ProcAttr)
|
||||
procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
|
||||
|
||||
clusterSize := 3
|
||||
|
||||
_, etcds, err := createCluster(clusterSize, procAttr)
|
||||
_, etcds, err := createCluster(clusterSize, procAttr, tls)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("cannot create cluster")
|
||||
@@ -154,6 +154,14 @@ func TestSimpleMultiNode(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestSimpleMultiNode(t *testing.T) {
|
||||
templateTestSimpleMultiNode(t, false)
|
||||
}
|
||||
|
||||
func TestSimpleMultiNodeTls(t *testing.T) {
|
||||
templateTestSimpleMultiNode(t, true)
|
||||
}
|
||||
|
||||
// Create a five nodes
|
||||
// Randomly kill one of the node and keep on sending set command to the cluster
|
||||
func TestMultiNodeRecovery(t *testing.T) {
|
||||
@@ -161,7 +169,7 @@ func TestMultiNodeRecovery(t *testing.T) {
|
||||
procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
|
||||
|
||||
clusterSize := 5
|
||||
argGroup, etcds, err := createCluster(clusterSize, procAttr)
|
||||
argGroup, etcds, err := createCluster(clusterSize, procAttr, false)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("cannot create cluster")
|
||||
|
||||
21
test.go
21
test.go
@@ -55,14 +55,31 @@ func set(stop chan bool) {
|
||||
}
|
||||
|
||||
// Create a cluster of etcd nodes
|
||||
func createCluster(size int, procAttr *os.ProcAttr) ([][]string, []*os.Process, error) {
|
||||
func createCluster(size int, procAttr *os.ProcAttr, ssl bool) ([][]string, []*os.Process, error) {
|
||||
argGroup := make([][]string, size)
|
||||
|
||||
sslServer1 := []string{"-serverCAFile=./fixtures/ca/ca.crt",
|
||||
"-serverCert=./fixtures/ca/server.crt",
|
||||
"-serverKey=./fixtures/ca/server.key.insecure",
|
||||
}
|
||||
|
||||
sslServer2 := []string{"-serverCAFile=./fixtures/ca/ca.crt",
|
||||
"-serverCert=./fixtures/ca/server2.crt",
|
||||
"-serverKey=./fixtures/ca/server2.key.insecure",
|
||||
}
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
if i == 0 {
|
||||
argGroup[i] = []string{"etcd", "-d=/tmp/node1", "-n=node1"}
|
||||
argGroup[i] = []string{"etcd", "-d=/tmp/node1", "-n=node1", "-vv"}
|
||||
if ssl {
|
||||
argGroup[i] = append(argGroup[i], sslServer1...)
|
||||
}
|
||||
} else {
|
||||
strI := strconv.Itoa(i + 1)
|
||||
argGroup[i] = []string{"etcd", "-n=node" + strI, "-c=127.0.0.1:400" + strI, "-s=127.0.0.1:700" + strI, "-d=/tmp/node" + strI, "-C=127.0.0.1:7001"}
|
||||
if ssl {
|
||||
argGroup[i] = append(argGroup[i], sslServer2...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user