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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
fa2a17d9
Commit
fa2a17d9
authored
2 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
added some tests
parent
b8d1feb4
No related branches found
No related tags found
3 merge requests
!510
Release
,
!214
Project/restlike
,
!207
WIP: Client Restructure
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
restlike/response_test.go
+96
-0
96 additions, 0 deletions
restlike/response_test.go
with
96 additions
and
0 deletions
restlike/response_test.go
0 → 100644
+
96
−
0
View file @
fa2a17d9
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
package
restlike
import
(
"bytes"
"github.com/pkg/errors"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
"google.golang.org/protobuf/proto"
"testing"
"time"
)
// Test happy path
func
TestSingleResponse_Callback
(
t
*
testing
.
T
)
{
resultChan
:=
make
(
chan
*
Message
,
1
)
cb
:=
func
(
input
*
Message
)
{
resultChan
<-
input
}
testPath
:=
"test/path"
testMethod
:=
Get
testMessage
:=
&
Message
{
Content
:
[]
byte
(
"test"
),
Headers
:
nil
,
Method
:
uint32
(
testMethod
),
Uri
:
testPath
,
Error
:
""
,
}
response
:=
singleResponse
{
cb
}
testPayload
,
err
:=
proto
.
Marshal
(
testMessage
)
if
err
!=
nil
{
t
.
Errorf
(
err
.
Error
())
}
response
.
Callback
(
testPayload
,
receptionID
.
EphemeralIdentity
{},
nil
,
nil
)
select
{
case
result
:=
<-
resultChan
:
if
result
.
Uri
!=
testPath
{
t
.
Errorf
(
"Mismatched uri"
)
}
if
result
.
Method
!=
uint32
(
testMethod
)
{
t
.
Errorf
(
"Mismatched method"
)
}
if
!
bytes
.
Equal
(
testMessage
.
Content
,
result
.
Content
)
{
t
.
Errorf
(
"Mismatched content"
)
}
case
<-
time
.
After
(
3
*
time
.
Second
)
:
t
.
Errorf
(
"Test SingleResponse timed out!"
)
}
}
// Test error input path
func
TestSingleResponse_Callback_Err
(
t
*
testing
.
T
)
{
resultChan
:=
make
(
chan
*
Message
,
1
)
cb
:=
func
(
input
*
Message
)
{
resultChan
<-
input
}
response
:=
singleResponse
{
cb
}
response
.
Callback
(
nil
,
receptionID
.
EphemeralIdentity
{},
nil
,
errors
.
New
(
"test"
))
select
{
case
result
:=
<-
resultChan
:
if
len
(
result
.
Error
)
==
0
{
t
.
Errorf
(
"Expected cb error!"
)
}
case
<-
time
.
After
(
3
*
time
.
Second
)
:
t
.
Errorf
(
"Test SingleResponse input error timed out!"
)
}
}
// Test proto error path
func
TestSingleResponse_Callback_ProtoErr
(
t
*
testing
.
T
)
{
resultChan
:=
make
(
chan
*
Message
,
1
)
cb
:=
func
(
input
*
Message
)
{
resultChan
<-
input
}
response
:=
singleResponse
{
cb
}
response
.
Callback
([]
byte
(
"test"
),
receptionID
.
EphemeralIdentity
{},
nil
,
nil
)
select
{
case
result
:=
<-
resultChan
:
if
len
(
result
.
Error
)
==
0
{
t
.
Errorf
(
"Expected cb proto error!"
)
}
case
<-
time
.
After
(
3
*
time
.
Second
)
:
t
.
Errorf
(
"Test SingleResponse proto error timed out!"
)
}
}
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