Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
4604ccac
Commit
4604ccac
authored
Mar 30, 2021
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Update tests in hostpool
parent
affb3cb4
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
network/gateway/gateway_test.go
+14
-14
14 additions, 14 deletions
network/gateway/gateway_test.go
network/gateway/utils_test.go
+7
-27
7 additions, 27 deletions
network/gateway/utils_test.go
with
21 additions
and
41 deletions
network/gateway/gateway_test.go
+
14
−
14
View file @
4604ccac
...
...
@@ -22,7 +22,7 @@ import (
// Unit test
func
TestNewHostPool
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
rng
:=
csprng
.
NewSystemRNG
()
testNdf
:=
getTestNdf
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
...
...
@@ -56,7 +56,7 @@ func TestNewHostPool(t *testing.T) {
// Unit test
func
TestHostPool_ManageHostPool
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
rng
:=
csprng
.
NewSystemRNG
()
testNdf
:=
getTestNdf
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
...
...
@@ -131,7 +131,7 @@ func TestHostPool_ManageHostPool(t *testing.T) {
// Full happy path test
func
TestHostPool_ReplaceHost
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
testNdf
:=
getTestNdf
(
t
)
newIndex
:=
uint32
(
20
)
...
...
@@ -238,7 +238,7 @@ func TestHostPool_ReplaceHost(t *testing.T) {
// Error path, could not get host
func
TestHostPool_ReplaceHost_Error
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
// Construct a manager (bypass business logic in constructor)
hostPool
:=
&
HostPool
{
...
...
@@ -259,7 +259,7 @@ func TestHostPool_ReplaceHost_Error(t *testing.T) {
// Happy path
func
TestHostPool_PruneHostPool
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
testNdf
:=
getTestNdf
(
t
)
newIndex
:=
uint32
(
20
)
params
:=
DefaultPoolParams
()
...
...
@@ -329,7 +329,7 @@ func TestHostPool_PruneHostPool(t *testing.T) {
// Error path: not enough gateways in ndf compared to
// required pool size
func
TestHostPool_PruneHostPool_Error
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
testNdf
:=
getTestNdf
(
t
)
newIndex
:=
uint32
(
20
)
params
:=
DefaultPoolParams
()
...
...
@@ -359,7 +359,7 @@ func TestHostPool_PruneHostPool_Error(t *testing.T) {
// Unit test
func
TestHostPool_UpdateNdf
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
testNdf
:=
getTestNdf
(
t
)
newIndex
:=
uint32
(
20
)
...
...
@@ -394,7 +394,7 @@ func TestHostPool_UpdateNdf(t *testing.T) {
// Full test
func
TestHostPool_GetPreferred
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
rng
:=
csprng
.
NewSystemRNG
()
testNdf
:=
getTestNdf
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
...
...
@@ -466,7 +466,7 @@ func TestHostPool_GetPreferred(t *testing.T) {
// Unit test
func
TestHostPool_GetAny
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
rng
:=
csprng
.
NewSystemRNG
()
testNdf
:=
getTestNdf
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
...
...
@@ -523,7 +523,7 @@ func TestHostPool_GetAny(t *testing.T) {
// Unit test
func
TestHostPool_ForceAdd
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
rng
:=
csprng
.
NewSystemRNG
()
testNdf
:=
getTestNdf
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
...
...
@@ -584,7 +584,7 @@ func TestHostPool_ForceAdd(t *testing.T) {
// Unit test which only adds information to ndf
func
TestHostPool_UpdateConns_AddGateways
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
rng
:=
csprng
.
NewSystemRNG
()
testNdf
:=
getTestNdf
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
...
...
@@ -659,7 +659,7 @@ func TestHostPool_UpdateConns_AddGateways(t *testing.T) {
// Unit test which only adds information to ndf
func
TestHostPool_UpdateConns_RemoveGateways
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
rng
:=
csprng
.
NewSystemRNG
()
testNdf
:=
getTestNdf
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
...
...
@@ -732,7 +732,7 @@ func TestHostPool_UpdateConns_RemoveGateways(t *testing.T) {
// Unit test
func
TestHostPool_AddGateway
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
testNdf
:=
getTestNdf
(
t
)
newIndex
:=
uint32
(
20
)
params
:=
DefaultPoolParams
()
...
...
@@ -765,7 +765,7 @@ func TestHostPool_AddGateway(t *testing.T) {
// Unit test
func
TestHostPool_RemoveGateway
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
testNdf
:=
getTestNdf
(
t
)
newIndex
:=
uint32
(
20
)
params
:=
DefaultPoolParams
()
...
...
This diff is collapsed.
Click to expand it.
network/gateway/utils_test.go
+
7
−
27
View file @
4604ccac
package
gateway
import
(
"errors"
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/ndf"
)
// Mock structure adhering to HostManager which returns the error
// path for all it's methods
type
MangerErrorPath
struct
{}
// Constructor for MangerErrorPath
func
newErrorManager
()
*
MangerErrorPath
{
return
&
MangerErrorPath
{}
}
func
(
mep
*
MangerErrorPath
)
GetHost
(
hostId
*
id
.
ID
)
(
*
connect
.
Host
,
bool
)
{
return
nil
,
false
}
func
(
mep
*
MangerErrorPath
)
AddHost
(
hid
*
id
.
ID
,
address
string
,
cert
[]
byte
,
params
connect
.
HostParams
)
(
host
*
connect
.
Host
,
err
error
)
{
return
nil
,
errors
.
New
(
"Failed to add host"
)
}
func
(
mep
*
MangerErrorPath
)
RemoveHost
(
hid
*
id
.
ID
)
{}
// Mock structure adhering to HostManager to be used for happy path
type
Manager
HappyPath
struct
{
type
mock
Manager
struct
{
hosts
map
[
string
]
*
connect
.
Host
}
// Constructor for Manager
HappyPath
func
new
Happy
Manager
()
*
Manager
HappyPath
{
return
&
Manager
HappyPath
{
// Constructor for
mock
Manager
func
new
Mock
Manager
()
*
mock
Manager
{
return
&
mock
Manager
{
hosts
:
make
(
map
[
string
]
*
connect
.
Host
),
}
}
func
(
mhp
*
Manager
HappyPath
)
GetHost
(
hostId
*
id
.
ID
)
(
*
connect
.
Host
,
bool
)
{
func
(
mhp
*
mock
Manager
)
GetHost
(
hostId
*
id
.
ID
)
(
*
connect
.
Host
,
bool
)
{
h
,
ok
:=
mhp
.
hosts
[
hostId
.
String
()]
return
h
,
ok
}
func
(
mhp
*
Manager
HappyPath
)
AddHost
(
hid
*
id
.
ID
,
address
string
,
func
(
mhp
*
mock
Manager
)
AddHost
(
hid
*
id
.
ID
,
address
string
,
cert
[]
byte
,
params
connect
.
HostParams
)
(
host
*
connect
.
Host
,
err
error
)
{
host
,
err
=
connect
.
NewHost
(
hid
,
address
,
cert
,
params
)
if
err
!=
nil
{
...
...
@@ -55,7 +35,7 @@ func (mhp *ManagerHappyPath) AddHost(hid *id.ID, address string,
return
}
func
(
mhp
*
Manager
HappyPath
)
RemoveHost
(
hid
*
id
.
ID
)
{
func
(
mhp
*
mock
Manager
)
RemoveHost
(
hid
*
id
.
ID
)
{
delete
(
mhp
.
hosts
,
hid
.
String
())
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment