Skip to content
Snippets Groups Projects
Commit 55f38103 authored by Jonah Husson's avatar Jonah Husson
Browse files

Add basic unit tests for webconn

parent cb2eb413
No related branches found
No related tags found
3 merge requests!39Merge release into master,!34Update to use modified client, add params for relevant options, enable use of tls with web conn,!32Project/channels
package connect
import (
"gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/primitives/id"
"testing"
)
func TestWebConn_Close(t *testing.T) {
rng := csprng.NewSystemRNG()
hostId, err := id.NewRandomID(rng, id.User)
if err != nil {
t.Fatal(err)
}
hostParams := GetDefaultHostParams()
hostParams.ConnectionType = Web
h, err := NewHost(hostId, "0.0.0.0", nil, hostParams)
if err != nil {
t.Fatal(err)
}
wc := webConn{
h: h,
connection: nil,
}
err = wc.Connect()
if err != nil {
t.Fatal(err)
}
err = wc.Close()
if err != nil {
t.Fatal(err)
}
}
func TestWebConn_Connect(t *testing.T) {
rng := csprng.NewSystemRNG()
hostId, err := id.NewRandomID(rng, id.User)
if err != nil {
t.Fatal(err)
}
hostParams := GetDefaultHostParams()
hostParams.ConnectionType = Web
h, err := NewHost(hostId, "0.0.0.0", nil, hostParams)
if err != nil {
t.Fatal(err)
}
wc := webConn{
h: h,
connection: nil,
}
err = wc.Connect()
if err != nil {
t.Fatal(err)
}
}
func TestWebConn_GetGrpcConn(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Error("Did not receive expected fatal error")
}
}()
rng := csprng.NewSystemRNG()
hostId, err := id.NewRandomID(rng, id.User)
if err != nil {
t.Fatal(err)
}
hostParams := GetDefaultHostParams()
hostParams.ConnectionType = Web
h, err := NewHost(hostId, "0.0.0.0", nil, hostParams)
if err != nil {
t.Fatal(err)
}
wc := webConn{
h: h,
connection: nil,
}
err = wc.Connect()
if err != nil {
t.Fatal(err)
}
conn := wc.GetGrpcConn()
if conn != nil {
t.Fatal("Expected panic, received conn instead")
}
}
func TestWebConn_GetWebConn(t *testing.T) {
rng := csprng.NewSystemRNG()
hostId, err := id.NewRandomID(rng, id.User)
if err != nil {
t.Fatal(err)
}
hostParams := GetDefaultHostParams()
hostParams.ConnectionType = Web
h, err := NewHost(hostId, "0.0.0.0", nil, hostParams)
if err != nil {
t.Fatal(err)
}
wc := webConn{
h: h,
connection: nil,
}
err = wc.Connect()
if err != nil {
t.Fatal(err)
}
conn := wc.GetWebConn()
if conn == nil {
t.Fatal("Expected grpcConn, received nil instead")
}
}
func TestWebConn_IsWeb(t *testing.T) {
wc := webConn{}
if !wc.IsWeb() {
t.Fatal("WebConn is not web")
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment