Skip to content
Snippets Groups Projects
Select Git revision
  • 30f433a85d3351ff1b378089f15970294edfc988
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

publicFormat.go

Blame
  • webConn_test.go 3.07 KiB
    package connect
    
    import (
    	"github.com/pkg/errors"
    	"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")
    	}
    }
    
    func Test_checkErrorExceptions(t *testing.T) {
    	tests := map[error]bool{
    		errors.New("(Client.Timeout exceeded while awaiting headers)"): true,
    		errors.New("SSL"):                      true,
    		errors.New("CORS"):                     true,
    		errors.New("This is an invalid error"): true,
    		errors.New("Protocol"):                 true,
    		errors.New("error"):                    false,
    		errors.New("https"):                    false,
    	}
    
    	for err, b := range tests {
    		result := checkErrorExceptions(err)
    		if result != b {
    			t.Errorf("checkErrorExceptions did not return expected bool for %s"+
    				"\nexpected: %t\nreceived: %t", err.Error(), b, result)
    		}
    	}
    }
    
    //func Test_isOnline_actual(t *testing.T) {
    //	targetAddr := ".xxnode.io:22840"
    //	_, ok := isOnlineHelper(targetAddr, time.Second*10)
    //	t.Fatal(ok)
    //}