Browse Source

tableize the test

Barak Michener 11 years ago
parent
commit
1a0195e07e
1 changed files with 22 additions and 20 deletions
  1. 22 20
      etcdserver/config_test.go

+ 22 - 20
etcdserver/config_test.go

@@ -5,28 +5,30 @@ import (
 )
 
 func TestConfigVerify(t *testing.T) {
-	cluster := &Cluster{}
-	cfg := ServerConfig{
-		Name:         "node1",
-		Cluster:      cluster,
-		ClusterState: ClusterStateValueNew,
-	}
-
-	err := cfg.Verify()
-	if err == nil {
-		t.Error("Did not get error for lacking self in cluster.")
-	}
 
-	cluster.Set("node1=http://localhost:7001,node2=http://localhost:7001")
-	err = cfg.Verify()
-	if err == nil {
-		t.Error("Did not get error for double URL in cluster.")
+	tests := []struct {
+		clusterSetting string
+		shouldError    bool
+	}{
+		{"", true},
+		{"node1=http://localhost:7001,node2=http://localhost:7001", true},
+		{"node1=http://localhost:7001,node2=http://localhost:7002", false},
 	}
 
-	cluster.Set("node1=http://localhost:7001,node2=http://localhost:7002")
-	err = cfg.Verify()
-	if err != nil {
-		t.Errorf("Got unexpected error %v", err)
+	for i, tt := range tests {
+		cluster := &Cluster{}
+		cluster.Set(tt.clusterSetting)
+		cfg := ServerConfig{
+			Name:         "node1",
+			Cluster:      cluster,
+			ClusterState: ClusterStateValueNew,
+		}
+		err := cfg.Verify()
+		if (err == nil) && tt.shouldError {
+			t.Errorf("#%d: Got no error where one was expected", i)
+		}
+		if (err != nil) && !tt.shouldError {
+			t.Errorf("#%d: Got unexpected error: %v", i, err)
+		}
 	}
-
 }