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
6cf058a4
Commit
6cf058a4
authored
3 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Addd high level tests for marshalling across the board
parent
1e65ef4d
No related branches found
No related tags found
4 merge requests
!510
Release
,
!227
Have all Params objects adhere to json.Marshaler/Unmarshaler
,
!226
WIP: Api2.0
,
!207
WIP: Client Restructure
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/params_test.go
+19
-7
19 additions, 7 deletions
api/params_test.go
cmix/params_test.go
+36
-0
36 additions, 0 deletions
cmix/params_test.go
fileTransfer2/params_test.go
+38
-0
38 additions, 0 deletions
fileTransfer2/params_test.go
single/params_test.go
+31
-0
31 additions, 0 deletions
single/params_test.go
with
124 additions
and
7 deletions
api/params_test.go
+
19
−
7
View file @
6cf058a4
...
@@ -8,30 +8,42 @@
...
@@ -8,30 +8,42 @@
package
api
package
api
import
(
import
(
"bytes"
"encoding/json"
"encoding/json"
"testing"
"testing"
)
)
// Tests that no data is lost when marshaling and
// unmarshaling the Params object.
func
TestParams_MarshalUnmarshal
(
t
*
testing
.
T
)
{
func
TestParams_MarshalUnmarshal
(
t
*
testing
.
T
)
{
// Construct a set of params
p
:=
GetDefaultParams
()
p
:=
GetDefaultParams
()
data
,
err
:=
json
.
Marshal
(
p
)
// Marshal the params
data
,
err
:=
json
.
Marshal
(
&
p
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Marshal error: %
+
v"
,
err
)
t
.
Fatalf
(
"Marshal error: %v"
,
err
)
}
}
t
.
Logf
(
"%s"
,
string
(
data
))
t
.
Logf
(
"%s"
,
string
(
data
))
received
:=
GetDefaultParams
()
// Unmarshal the params object
received
:=
Params
{}
err
=
json
.
Unmarshal
(
data
,
&
received
)
err
=
json
.
Unmarshal
(
data
,
&
received
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unmarshal error: %
+
v"
,
err
)
t
.
Fatalf
(
"Unmarshal error: %v"
,
err
)
}
}
// Re-marshal this params object
data2
,
err
:=
json
.
Marshal
(
received
)
data2
,
err
:=
json
.
Marshal
(
received
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Marshal error: %
+
v"
,
err
)
t
.
Fatalf
(
"Marshal error: %v"
,
err
)
}
}
t
.
Logf
(
"%s"
,
string
(
data2
))
// Check that they match (it is done this way to avoid
// false failures with the reflect.DeepEqual function and
// pointers)
if
!
bytes
.
Equal
(
data
,
data2
)
{
t
.
Fatalf
(
"Data was lost in marshal/unmarshal."
)
}
}
}
This diff is collapsed.
Click to expand it.
cmix/params_test.go
+
36
−
0
View file @
6cf058a4
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
package
cmix
package
cmix
import
(
import
(
"bytes"
"encoding/json"
"encoding/json"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id"
"reflect"
"reflect"
...
@@ -15,6 +16,41 @@ import (
...
@@ -15,6 +16,41 @@ import (
"time"
"time"
)
)
// Tests that no data is lost when marshaling and
// unmarshaling the Params object.
func
TestParams_MarshalJSON
(
t
*
testing
.
T
)
{
// Construct a set of params
p
:=
GetDefaultParams
()
// Marshal the params
data
,
err
:=
json
.
Marshal
(
&
p
)
if
err
!=
nil
{
t
.
Fatalf
(
"Marshal error: %v"
,
err
)
}
t
.
Logf
(
"%s"
,
string
(
data
))
// Unmarshal the params object
received
:=
Params
{}
err
=
json
.
Unmarshal
(
data
,
&
received
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unmarshal error: %v"
,
err
)
}
// Re-marshal this params object
data2
,
err
:=
json
.
Marshal
(
received
)
if
err
!=
nil
{
t
.
Fatalf
(
"Marshal error: %v"
,
err
)
}
// Check that they match (it is done this way to avoid
// false failures with the reflect.DeepEqual function and
// pointers)
if
!
bytes
.
Equal
(
data
,
data2
)
{
t
.
Fatalf
(
"Data was lost in marshal/unmarshal."
)
}
}
func
TestCMIXParams_JSON_Marshal_Unmarshal
(
t
*
testing
.
T
)
{
func
TestCMIXParams_JSON_Marshal_Unmarshal
(
t
*
testing
.
T
)
{
p
:=
CMIXParams
{
p
:=
CMIXParams
{
RoundTries
:
5
,
RoundTries
:
5
,
...
...
This diff is collapsed.
Click to expand it.
fileTransfer2/params_test.go
+
38
−
0
View file @
6cf058a4
...
@@ -8,11 +8,49 @@
...
@@ -8,11 +8,49 @@
package
fileTransfer2
package
fileTransfer2
import
(
import
(
"bytes"
"encoding/json"
"gitlab.com/elixxir/client/cmix"
"gitlab.com/elixxir/client/cmix"
"reflect"
"reflect"
"testing"
"testing"
)
)
// Tests that no data is lost when marshaling and
// unmarshaling the Params object.
func
TestParams_MarshalJSON
(
t
*
testing
.
T
)
{
// Construct a set of params
p
:=
DefaultParams
()
// Marshal the params
data
,
err
:=
json
.
Marshal
(
&
p
)
if
err
!=
nil
{
t
.
Fatalf
(
"Marshal error: %v"
,
err
)
}
t
.
Logf
(
"%s"
,
string
(
data
))
// Unmarshal the params object
received
:=
Params
{}
err
=
json
.
Unmarshal
(
data
,
&
received
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unmarshal error: %v"
,
err
)
}
// Re-marshal this params object
data2
,
err
:=
json
.
Marshal
(
received
)
if
err
!=
nil
{
t
.
Fatalf
(
"Marshal error: %v"
,
err
)
}
// Check that they match (it is done this way to avoid
// false failures with the reflect.DeepEqual function and
// pointers)
if
!
bytes
.
Equal
(
data
,
data2
)
{
t
.
Fatalf
(
"Data was lost in marshal/unmarshal."
)
}
}
// Tests that DefaultParams returns a Params object with the expected defaults.
// Tests that DefaultParams returns a Params object with the expected defaults.
func
TestDefaultParams
(
t
*
testing
.
T
)
{
func
TestDefaultParams
(
t
*
testing
.
T
)
{
expected
:=
Params
{
expected
:=
Params
{
...
...
This diff is collapsed.
Click to expand it.
single/params_test.go
+
31
−
0
View file @
6cf058a4
...
@@ -8,11 +8,42 @@
...
@@ -8,11 +8,42 @@
package
single
package
single
import
(
import
(
"bytes"
"encoding/json"
"gitlab.com/elixxir/client/cmix"
"gitlab.com/elixxir/client/cmix"
"reflect"
"reflect"
"testing"
"testing"
)
)
// Tests that no data is lost when marshaling and
// unmarshaling the RequestParams object.
func
TestParams_MarshalUnmarshal
(
t
*
testing
.
T
)
{
p
:=
GetDefaultRequestParams
()
data
,
err
:=
json
.
Marshal
(
p
)
if
err
!=
nil
{
t
.
Fatalf
(
"Marshal error: %+v"
,
err
)
}
t
.
Logf
(
"%s"
,
string
(
data
))
received
:=
RequestParams
{}
err
=
json
.
Unmarshal
(
data
,
&
received
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unmarshal error: %+v"
,
err
)
}
data2
,
err
:=
json
.
Marshal
(
received
)
if
err
!=
nil
{
t
.
Fatalf
(
"Marshal error: %+v"
,
err
)
}
t
.
Logf
(
"%s"
,
string
(
data2
))
if
!
bytes
.
Equal
(
data
,
data2
)
{
t
.
Fatalf
(
"Data was lost in marshal/unmarshal."
)
}
}
// Tests that GetDefaultRequestParams returns a RequestParams with the expected
// Tests that GetDefaultRequestParams returns a RequestParams with the expected
// default values.
// default values.
func
TestGetDefaultRequestParams
(
t
*
testing
.
T
)
{
func
TestGetDefaultRequestParams
(
t
*
testing
.
T
)
{
...
...
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