-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jose Luis Lucas
committed
Nov 27, 2018
1 parent
db25d9c
commit 673ca18
Showing
4 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package gossip | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/bbva/qed/gossip/member" | ||
) | ||
|
||
func TestStart(t *testing.T) { | ||
|
||
} | ||
|
||
func TestJoin(t *testing.T) { | ||
conf := DefaultConfig() | ||
conf.NodeName = "testNode" | ||
conf.Role = member.Auditor | ||
a, _ := NewAgent(conf, []Processor{FakeProcessor{}}) | ||
|
||
testCases := []struct { | ||
agentState member.Status | ||
addrs []string | ||
expectedContactedHosts int | ||
expectedErr error | ||
}{ | ||
{ | ||
member.Alive, | ||
[]string{}, | ||
0, | ||
nil, | ||
}, | ||
{ | ||
member.Failed, | ||
[]string{}, | ||
0, | ||
fmt.Errorf("Agent can't join after Leave or Shutdown"), | ||
}, | ||
{ | ||
member.Alive, | ||
[]string{"127.0.0.1:12345"}, | ||
1, | ||
nil, | ||
}, | ||
} | ||
|
||
for i, c := range testCases { | ||
a.Self.Status = c.agentState | ||
result, err := a.Join(c.addrs) | ||
require.Equal(t, c.expectedContactedHosts, result, "Wrong expected contacted hosts in test %d.", i) | ||
require.Equal(t, c.expectedErr, err, "Wrong expected error in test %d.", i) | ||
} | ||
} | ||
|
||
func TestLeave(t *testing.T) { | ||
conf := DefaultConfig() | ||
conf.NodeName = "testNode" | ||
conf.Role = member.Auditor | ||
conf.BindAddr = "0.0.0.0:12346" | ||
a, _ := NewAgent(conf, []Processor{FakeProcessor{}}) | ||
|
||
testCases := []struct { | ||
agentState member.Status | ||
expectedErr error | ||
finalStatus member.Status | ||
}{ | ||
{ | ||
member.Left, | ||
nil, | ||
member.Left, | ||
}, | ||
{ | ||
member.Leaving, | ||
fmt.Errorf("Leave already in progress"), | ||
member.Leaving, | ||
}, | ||
{ | ||
member.Shutdown, | ||
fmt.Errorf("Leave called after Shutdown"), | ||
member.Shutdown, | ||
}, | ||
{ | ||
member.Alive, | ||
nil, | ||
member.Left, | ||
}, | ||
{ | ||
member.Failed, | ||
nil, | ||
member.Left, | ||
}, | ||
} | ||
|
||
for i, c := range testCases { | ||
a.Self.Status = c.agentState | ||
err := a.Leave() | ||
require.Equal(t, c.expectedErr, err, "Wrong expected error in test %d.", i) | ||
require.Equal(t, c.finalStatus, a.Self.Status, "Wrong expected status in test %d.", i) | ||
} | ||
} | ||
|
||
func TestShutdown(t *testing.T) { | ||
|
||
conf := DefaultConfig() | ||
conf.NodeName = "testNode" | ||
conf.Role = member.Auditor | ||
conf.BindAddr = "0.0.0.0:12347" | ||
a, _ := NewAgent(conf, []Processor{FakeProcessor{}}) | ||
|
||
testCases := []struct { | ||
agentState member.Status | ||
expectedErr error | ||
finalStatus member.Status | ||
}{ | ||
{ | ||
member.Shutdown, | ||
nil, | ||
member.Shutdown, | ||
}, | ||
{ | ||
member.Left, | ||
nil, | ||
member.Shutdown, | ||
}, | ||
{ | ||
member.Alive, | ||
nil, | ||
member.Shutdown, | ||
}, | ||
{ | ||
member.Failed, | ||
nil, | ||
member.Shutdown, | ||
}, | ||
{ | ||
member.Leaving, | ||
nil, | ||
member.Shutdown, | ||
}, | ||
} | ||
|
||
for i, c := range testCases { | ||
a.Self.Status = c.agentState | ||
err := a.Shutdown() | ||
require.Equal(t, c.expectedErr, err, "Wrong expected error in test %d.", i) | ||
require.Equal(t, c.finalStatus, a.Self.Status, "Wrong expected status in test %d.", i) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters