tableize the test

This commit is contained in:
Barak Michener 2014-10-06 20:05:53 -04:00
parent 120b088723
commit 1a0195e07e

View File

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