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 (
...
@@ -22,7 +22,7 @@ import (
// Unit test
// Unit test
func
TestNewHostPool
(
t
*
testing
.
T
)
{
func
TestNewHostPool
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
rng
:=
csprng
.
NewSystemRNG
()
rng
:=
csprng
.
NewSystemRNG
()
testNdf
:=
getTestNdf
(
t
)
testNdf
:=
getTestNdf
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
...
@@ -56,7 +56,7 @@ func TestNewHostPool(t *testing.T) {
...
@@ -56,7 +56,7 @@ func TestNewHostPool(t *testing.T) {
// Unit test
// Unit test
func
TestHostPool_ManageHostPool
(
t
*
testing
.
T
)
{
func
TestHostPool_ManageHostPool
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
rng
:=
csprng
.
NewSystemRNG
()
rng
:=
csprng
.
NewSystemRNG
()
testNdf
:=
getTestNdf
(
t
)
testNdf
:=
getTestNdf
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
...
@@ -131,7 +131,7 @@ func TestHostPool_ManageHostPool(t *testing.T) {
...
@@ -131,7 +131,7 @@ func TestHostPool_ManageHostPool(t *testing.T) {
// Full happy path test
// Full happy path test
func
TestHostPool_ReplaceHost
(
t
*
testing
.
T
)
{
func
TestHostPool_ReplaceHost
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
testNdf
:=
getTestNdf
(
t
)
testNdf
:=
getTestNdf
(
t
)
newIndex
:=
uint32
(
20
)
newIndex
:=
uint32
(
20
)
...
@@ -238,7 +238,7 @@ func TestHostPool_ReplaceHost(t *testing.T) {
...
@@ -238,7 +238,7 @@ func TestHostPool_ReplaceHost(t *testing.T) {
// Error path, could not get host
// Error path, could not get host
func
TestHostPool_ReplaceHost_Error
(
t
*
testing
.
T
)
{
func
TestHostPool_ReplaceHost_Error
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
// Construct a manager (bypass business logic in constructor)
// Construct a manager (bypass business logic in constructor)
hostPool
:=
&
HostPool
{
hostPool
:=
&
HostPool
{
...
@@ -259,7 +259,7 @@ func TestHostPool_ReplaceHost_Error(t *testing.T) {
...
@@ -259,7 +259,7 @@ func TestHostPool_ReplaceHost_Error(t *testing.T) {
// Happy path
// Happy path
func
TestHostPool_PruneHostPool
(
t
*
testing
.
T
)
{
func
TestHostPool_PruneHostPool
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
testNdf
:=
getTestNdf
(
t
)
testNdf
:=
getTestNdf
(
t
)
newIndex
:=
uint32
(
20
)
newIndex
:=
uint32
(
20
)
params
:=
DefaultPoolParams
()
params
:=
DefaultPoolParams
()
...
@@ -329,7 +329,7 @@ func TestHostPool_PruneHostPool(t *testing.T) {
...
@@ -329,7 +329,7 @@ func TestHostPool_PruneHostPool(t *testing.T) {
// Error path: not enough gateways in ndf compared to
// Error path: not enough gateways in ndf compared to
// required pool size
// required pool size
func
TestHostPool_PruneHostPool_Error
(
t
*
testing
.
T
)
{
func
TestHostPool_PruneHostPool_Error
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
testNdf
:=
getTestNdf
(
t
)
testNdf
:=
getTestNdf
(
t
)
newIndex
:=
uint32
(
20
)
newIndex
:=
uint32
(
20
)
params
:=
DefaultPoolParams
()
params
:=
DefaultPoolParams
()
...
@@ -359,7 +359,7 @@ func TestHostPool_PruneHostPool_Error(t *testing.T) {
...
@@ -359,7 +359,7 @@ func TestHostPool_PruneHostPool_Error(t *testing.T) {
// Unit test
// Unit test
func
TestHostPool_UpdateNdf
(
t
*
testing
.
T
)
{
func
TestHostPool_UpdateNdf
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
testNdf
:=
getTestNdf
(
t
)
testNdf
:=
getTestNdf
(
t
)
newIndex
:=
uint32
(
20
)
newIndex
:=
uint32
(
20
)
...
@@ -394,7 +394,7 @@ func TestHostPool_UpdateNdf(t *testing.T) {
...
@@ -394,7 +394,7 @@ func TestHostPool_UpdateNdf(t *testing.T) {
// Full test
// Full test
func
TestHostPool_GetPreferred
(
t
*
testing
.
T
)
{
func
TestHostPool_GetPreferred
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
rng
:=
csprng
.
NewSystemRNG
()
rng
:=
csprng
.
NewSystemRNG
()
testNdf
:=
getTestNdf
(
t
)
testNdf
:=
getTestNdf
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
...
@@ -466,7 +466,7 @@ func TestHostPool_GetPreferred(t *testing.T) {
...
@@ -466,7 +466,7 @@ func TestHostPool_GetPreferred(t *testing.T) {
// Unit test
// Unit test
func
TestHostPool_GetAny
(
t
*
testing
.
T
)
{
func
TestHostPool_GetAny
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
rng
:=
csprng
.
NewSystemRNG
()
rng
:=
csprng
.
NewSystemRNG
()
testNdf
:=
getTestNdf
(
t
)
testNdf
:=
getTestNdf
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
...
@@ -523,7 +523,7 @@ func TestHostPool_GetAny(t *testing.T) {
...
@@ -523,7 +523,7 @@ func TestHostPool_GetAny(t *testing.T) {
// Unit test
// Unit test
func
TestHostPool_ForceAdd
(
t
*
testing
.
T
)
{
func
TestHostPool_ForceAdd
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
rng
:=
csprng
.
NewSystemRNG
()
rng
:=
csprng
.
NewSystemRNG
()
testNdf
:=
getTestNdf
(
t
)
testNdf
:=
getTestNdf
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
...
@@ -584,7 +584,7 @@ func TestHostPool_ForceAdd(t *testing.T) {
...
@@ -584,7 +584,7 @@ func TestHostPool_ForceAdd(t *testing.T) {
// Unit test which only adds information to ndf
// Unit test which only adds information to ndf
func
TestHostPool_UpdateConns_AddGateways
(
t
*
testing
.
T
)
{
func
TestHostPool_UpdateConns_AddGateways
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
rng
:=
csprng
.
NewSystemRNG
()
rng
:=
csprng
.
NewSystemRNG
()
testNdf
:=
getTestNdf
(
t
)
testNdf
:=
getTestNdf
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
...
@@ -659,7 +659,7 @@ func TestHostPool_UpdateConns_AddGateways(t *testing.T) {
...
@@ -659,7 +659,7 @@ func TestHostPool_UpdateConns_AddGateways(t *testing.T) {
// Unit test which only adds information to ndf
// Unit test which only adds information to ndf
func
TestHostPool_UpdateConns_RemoveGateways
(
t
*
testing
.
T
)
{
func
TestHostPool_UpdateConns_RemoveGateways
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
rng
:=
csprng
.
NewSystemRNG
()
rng
:=
csprng
.
NewSystemRNG
()
testNdf
:=
getTestNdf
(
t
)
testNdf
:=
getTestNdf
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
testStorage
:=
storage
.
InitTestingSession
(
t
)
...
@@ -732,7 +732,7 @@ func TestHostPool_UpdateConns_RemoveGateways(t *testing.T) {
...
@@ -732,7 +732,7 @@ func TestHostPool_UpdateConns_RemoveGateways(t *testing.T) {
// Unit test
// Unit test
func
TestHostPool_AddGateway
(
t
*
testing
.
T
)
{
func
TestHostPool_AddGateway
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
testNdf
:=
getTestNdf
(
t
)
testNdf
:=
getTestNdf
(
t
)
newIndex
:=
uint32
(
20
)
newIndex
:=
uint32
(
20
)
params
:=
DefaultPoolParams
()
params
:=
DefaultPoolParams
()
...
@@ -765,7 +765,7 @@ func TestHostPool_AddGateway(t *testing.T) {
...
@@ -765,7 +765,7 @@ func TestHostPool_AddGateway(t *testing.T) {
// Unit test
// Unit test
func
TestHostPool_RemoveGateway
(
t
*
testing
.
T
)
{
func
TestHostPool_RemoveGateway
(
t
*
testing
.
T
)
{
manager
:=
new
Happy
Manager
()
manager
:=
new
Mock
Manager
()
testNdf
:=
getTestNdf
(
t
)
testNdf
:=
getTestNdf
(
t
)
newIndex
:=
uint32
(
20
)
newIndex
:=
uint32
(
20
)
params
:=
DefaultPoolParams
()
params
:=
DefaultPoolParams
()
...
...
This diff is collapsed.
Click to expand it.
network/gateway/utils_test.go
+
7
−
27
View file @
4604ccac
package
gateway
package
gateway
import
(
import
(
"errors"
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/ndf"
"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
// Mock structure adhering to HostManager to be used for happy path
type
Manager
HappyPath
struct
{
type
mock
Manager
struct
{
hosts
map
[
string
]
*
connect
.
Host
hosts
map
[
string
]
*
connect
.
Host
}
}
// Constructor for Manager
HappyPath
// Constructor for
mock
Manager
func
new
Happy
Manager
()
*
Manager
HappyPath
{
func
new
Mock
Manager
()
*
mock
Manager
{
return
&
Manager
HappyPath
{
return
&
mock
Manager
{
hosts
:
make
(
map
[
string
]
*
connect
.
Host
),
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
()]
h
,
ok
:=
mhp
.
hosts
[
hostId
.
String
()]
return
h
,
ok
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
)
{
cert
[]
byte
,
params
connect
.
HostParams
)
(
host
*
connect
.
Host
,
err
error
)
{
host
,
err
=
connect
.
NewHost
(
hid
,
address
,
cert
,
params
)
host
,
err
=
connect
.
NewHost
(
hid
,
address
,
cert
,
params
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -55,7 +35,7 @@ func (mhp *ManagerHappyPath) AddHost(hid *id.ID, address string,
...
@@ -55,7 +35,7 @@ func (mhp *ManagerHappyPath) AddHost(hid *id.ID, address string,
return
return
}
}
func
(
mhp
*
Manager
HappyPath
)
RemoveHost
(
hid
*
id
.
ID
)
{
func
(
mhp
*
mock
Manager
)
RemoveHost
(
hid
*
id
.
ID
)
{
delete
(
mhp
.
hosts
,
hid
.
String
())
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