@@ -101,6 +101,47 @@ func TestNewConfigurationNodeMap(t *testing.T) {
101101 }
102102}
103103
104+ type testNode struct {
105+ addr string
106+ }
107+
108+ func (n testNode ) Addr () string {
109+ return n .addr
110+ }
111+
112+ func TestNewConfigurationWithNodes (t * testing.T ) {
113+ mgr := gorums .NewManager (gorums .InsecureDialOptions (t ))
114+ t .Cleanup (gorums .Closer (t , mgr ))
115+
116+ nodes := map [uint32 ]testNode {
117+ 1 : {addr : "127.0.0.1:9080" },
118+ 2 : {addr : "127.0.0.1:9081" },
119+ 3 : {addr : "127.0.0.1:9082" },
120+ 4 : {addr : "127.0.0.1:9083" },
121+ }
122+
123+ cfg , err := gorums .NewConfiguration (mgr , gorums .WithNodes (nodes ))
124+ if err != nil {
125+ t .Fatal (err )
126+ }
127+ if cfg .Size () != len (nodes ) {
128+ t .Errorf ("cfg.Size() = %d, expected %d" , cfg .Size (), len (nodes ))
129+ }
130+ for _ , node := range cfg .Nodes () {
131+ if nodes [node .ID ()].addr != node .Address () {
132+ t .Errorf ("cfg.Nodes()[%d] = %s, expected %s" , node .ID (), node .Address (), nodes [node .ID ()].addr )
133+ }
134+ }
135+ if mgr .Size () != len (nodes ) {
136+ t .Errorf ("mgr.Size() = %d, expected %d" , mgr .Size (), len (nodes ))
137+ }
138+ for _ , node := range mgr .Nodes () {
139+ if nodes [node .ID ()].addr != node .Address () {
140+ t .Errorf ("mgr.Nodes()[%d] = %s, expected %s" , node .ID (), node .Address (), nodes [node .ID ()].addr )
141+ }
142+ }
143+ }
144+
104145func TestNewConfigurationNodeIDs (t * testing.T ) {
105146 mgr := gorums .NewManager (gorums .InsecureDialOptions (t ))
106147 t .Cleanup (gorums .Closer (t , mgr ))
0 commit comments