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
6b5d1182
Commit
6b5d1182
authored
Feb 7, 2020
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
move notifications functions to separate file
parent
5923e8c8
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/client.go
+0
-46
0 additions, 46 deletions
api/client.go
api/client_test.go
+0
-46
0 additions, 46 deletions
api/client_test.go
api/notifications.go
+52
-0
52 additions, 0 deletions
api/notifications.go
api/notifications_test.go
+50
-0
50 additions, 0 deletions
api/notifications_test.go
with
102 additions
and
92 deletions
api/client.go
+
0
−
46
View file @
6b5d1182
...
@@ -25,7 +25,6 @@ import (
...
@@ -25,7 +25,6 @@ import (
"gitlab.com/elixxir/client/rekey"
"gitlab.com/elixxir/client/rekey"
"gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/comms/connect"
"gitlab.com/elixxir/comms/connect"
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/crypto/signature/rsa"
...
@@ -596,48 +595,3 @@ func (cl *Client) WriteToSessionFile(replacement string, store globals.Storage)
...
@@ -596,48 +595,3 @@ func (cl *Client) WriteToSessionFile(replacement string, store globals.Storage)
return
nil
return
nil
}
}
// RegisterForNotifications sends a message to notification bot indicating it
// is registering for notifications
func
(
cl
*
Client
)
RegisterForNotifications
(
notificationToken
[]
byte
)
error
{
// Pull the host from the manage
notificationBotHost
,
ok
:=
cl
.
receptionManager
.
Comms
.
GetHost
(
id
.
NOTIFICATION_BOT
)
if
!
ok
{
return
errors
.
New
(
"Failed to retrieve host for notification bot"
)
}
// Send the register message
_
,
err
:=
cl
.
receptionManager
.
Comms
.
RegisterForNotifications
(
notificationBotHost
,
&
mixmessages
.
NotificationToken
{
Token
:
notificationToken
,
})
if
err
!=
nil
{
err
:=
errors
.
Errorf
(
"RegisterForNotifications: Unable to register for notifications! %s"
,
err
)
return
err
}
return
nil
}
// UnregisterForNotifications sends a message to notification bot indicating it
// no longer wants to be registered for notifications
func
(
cl
*
Client
)
UnregisterForNotifications
()
error
{
// Pull the host from the manage
notificationBotHost
,
ok
:=
cl
.
receptionManager
.
Comms
.
GetHost
(
id
.
NOTIFICATION_BOT
)
if
!
ok
{
return
errors
.
New
(
"Failed to retrieve host for notification bot"
)
}
// Send the unregister message
_
,
err
:=
cl
.
receptionManager
.
Comms
.
UnregisterForNotifications
(
notificationBotHost
)
if
err
!=
nil
{
err
:=
errors
.
Errorf
(
"RegisterForNotifications: Unable to register for notifications! %s"
,
err
)
return
err
}
return
nil
}
This diff is collapsed.
Click to expand it.
api/client_test.go
+
0
−
46
View file @
6b5d1182
...
@@ -560,49 +560,3 @@ func TestClient_GetCommManager(t *testing.T) {
...
@@ -560,49 +560,3 @@ func TestClient_GetCommManager(t *testing.T) {
t
.
Error
(
"Received session not the same as the real session"
)
t
.
Error
(
"Received session not the same as the real session"
)
}
}
}
}
// Happy path
func
TestClient_RegisterForNotifications
(
t
*
testing
.
T
)
{
// Initialize client with dummy storage
storage
:=
DummyStorage
{
LocationA
:
"Blah"
,
StoreA
:
[]
byte
{
'a'
,
'b'
,
'c'
}}
client
,
err
:=
NewClient
(
&
storage
,
"hello"
,
""
,
def
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to initialize dummy client: %s"
,
err
.
Error
())
}
// InitNetwork to gateways and reg server
err
=
client
.
InitNetwork
()
if
err
!=
nil
{
t
.
Errorf
(
"Client failed of connect: %+v"
,
err
)
}
token
:=
make
([]
byte
,
32
)
err
=
client
.
RegisterForNotifications
(
token
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected happy path, received error: %+v"
,
err
)
}
}
// Happy path
func
TestClient_UnregisterForNotifications
(
t
*
testing
.
T
)
{
// Initialize client with dummy storage
storage
:=
DummyStorage
{
LocationA
:
"Blah"
,
StoreA
:
[]
byte
{
'a'
,
'b'
,
'c'
}}
client
,
err
:=
NewClient
(
&
storage
,
"hello"
,
""
,
def
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to initialize dummy client: %s"
,
err
.
Error
())
}
// InitNetwork to gateways and reg server
err
=
client
.
InitNetwork
()
if
err
!=
nil
{
t
.
Errorf
(
"Client failed of connect: %+v"
,
err
)
}
err
=
client
.
UnregisterForNotifications
()
if
err
!=
nil
{
t
.
Errorf
(
"Expected happy path, received error: %+v"
,
err
)
}
}
This diff is collapsed.
Click to expand it.
api/notifications.go
0 → 100644
+
52
−
0
View file @
6b5d1182
package
api
import
(
"github.com/pkg/errors"
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/primitives/id"
)
// RegisterForNotifications sends a message to notification bot indicating it
// is registering for notifications
func
(
cl
*
Client
)
RegisterForNotifications
(
notificationToken
[]
byte
)
error
{
// Pull the host from the manage
notificationBotHost
,
ok
:=
cl
.
receptionManager
.
Comms
.
GetHost
(
id
.
NOTIFICATION_BOT
)
if
!
ok
{
return
errors
.
New
(
"Failed to retrieve host for notification bot"
)
}
// Send the register message
_
,
err
:=
cl
.
receptionManager
.
Comms
.
RegisterForNotifications
(
notificationBotHost
,
&
mixmessages
.
NotificationToken
{
Token
:
notificationToken
,
})
if
err
!=
nil
{
err
:=
errors
.
Errorf
(
"RegisterForNotifications: Unable to register for notifications! %s"
,
err
)
return
err
}
return
nil
}
// UnregisterForNotifications sends a message to notification bot indicating it
// no longer wants to be registered for notifications
func
(
cl
*
Client
)
UnregisterForNotifications
()
error
{
// Pull the host from the manage
notificationBotHost
,
ok
:=
cl
.
receptionManager
.
Comms
.
GetHost
(
id
.
NOTIFICATION_BOT
)
if
!
ok
{
return
errors
.
New
(
"Failed to retrieve host for notification bot"
)
}
// Send the unregister message
_
,
err
:=
cl
.
receptionManager
.
Comms
.
UnregisterForNotifications
(
notificationBotHost
)
if
err
!=
nil
{
err
:=
errors
.
Errorf
(
"RegisterForNotifications: Unable to register for notifications! %s"
,
err
)
return
err
}
return
nil
}
This diff is collapsed.
Click to expand it.
api/notifications_test.go
0 → 100644
+
50
−
0
View file @
6b5d1182
package
api
import
"testing"
// Happy path
func
TestClient_RegisterForNotifications
(
t
*
testing
.
T
)
{
// Initialize client with dummy storage
storage
:=
DummyStorage
{
LocationA
:
"Blah"
,
StoreA
:
[]
byte
{
'a'
,
'b'
,
'c'
}}
client
,
err
:=
NewClient
(
&
storage
,
"hello"
,
""
,
def
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to initialize dummy client: %s"
,
err
.
Error
())
return
}
// InitNetwork to gateways and reg server
err
=
client
.
InitNetwork
()
if
err
!=
nil
{
t
.
Errorf
(
"Client failed of connect: %+v"
,
err
)
}
token
:=
make
([]
byte
,
32
)
err
=
client
.
RegisterForNotifications
(
token
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected happy path, received error: %+v"
,
err
)
}
}
// Happy path
func
TestClient_UnregisterForNotifications
(
t
*
testing
.
T
)
{
// Initialize client with dummy storage
storage
:=
DummyStorage
{
LocationA
:
"Blah"
,
StoreA
:
[]
byte
{
'a'
,
'b'
,
'c'
}}
client
,
err
:=
NewClient
(
&
storage
,
"hello"
,
""
,
def
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to initialize dummy client: %s"
,
err
.
Error
())
}
// InitNetwork to gateways and reg server
err
=
client
.
InitNetwork
()
if
err
!=
nil
{
t
.
Errorf
(
"Client failed of connect: %+v"
,
err
)
}
err
=
client
.
UnregisterForNotifications
()
if
err
!=
nil
{
t
.
Errorf
(
"Expected happy path, received error: %+v"
,
err
)
}
}
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