From 5686bc0f8ab0f4671961ef6c5d88420710ae9058 Mon Sep 17 00:00:00 2001 From: josh <josh@elixxir.io> Date: Fri, 25 Sep 2020 09:39:50 -0700 Subject: [PATCH] Fix tests --- connect/auth.go | 2 -- connect/auth_test.go | 3 +-- connect/token/map.go | 2 +- connect/token/map_test.go | 2 +- connect/token/token.go | 2 +- connect/token/token_test.go | 2 +- gossip/endpoint_test.go | 24 ++++++++++++++++++++---- gossip/manager_test.go | 30 +++++++++++++++++++++++++----- gossip/protocol_test.go | 9 ++++++--- 9 files changed, 56 insertions(+), 20 deletions(-) diff --git a/connect/auth.go b/connect/auth.go index 289f46e..ff5fd2e 100644 --- a/connect/auth.go +++ b/connect/auth.go @@ -19,11 +19,9 @@ import ( "github.com/golang/protobuf/ptypes" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/crypto/xx" "gitlab.com/xx_network/comms/connect/token" pb "gitlab.com/xx_network/comms/messages" - "gitlab.com/xx_network/crypto/nonce" "gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/primitives/id" "google.golang.org/grpc/metadata" diff --git a/connect/auth_test.go b/connect/auth_test.go index 024f280..9717e20 100644 --- a/connect/auth_test.go +++ b/connect/auth_test.go @@ -12,12 +12,11 @@ import ( "github.com/golang/protobuf/ptypes" "gitlab.com/elixxir/crypto/csprng" "gitlab.com/elixxir/crypto/xx" - token "gitlab.com/xx_network/comms/connect/token" + "gitlab.com/xx_network/comms/connect/token" pb "gitlab.com/xx_network/comms/messages" "gitlab.com/xx_network/comms/testkeys" "gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/primitives/id" - "sync" "testing" ) diff --git a/connect/token/map.go b/connect/token/map.go index b106a88..5bd8039 100644 --- a/connect/token/map.go +++ b/connect/token/map.go @@ -2,7 +2,7 @@ package token import ( jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/crypto/nonce" + "gitlab.com/xx_network/crypto/nonce" "sync" ) diff --git a/connect/token/map_test.go b/connect/token/map_test.go index d841170..45bdacd 100644 --- a/connect/token/map_test.go +++ b/connect/token/map_test.go @@ -1,7 +1,7 @@ package token import ( - nonce2 "gitlab.com/elixxir/crypto/nonce" + nonce2 "gitlab.com/xx_network/crypto/nonce" "testing" ) diff --git a/connect/token/token.go b/connect/token/token.go index 5461358..6063c95 100644 --- a/connect/token/token.go +++ b/connect/token/token.go @@ -9,7 +9,7 @@ package token import ( "bytes" "github.com/pkg/errors" - "gitlab.com/elixxir/crypto/nonce" + "gitlab.com/xx_network/crypto/nonce" "sync" ) diff --git a/connect/token/token_test.go b/connect/token/token_test.go index 7d4bb9d..b70645a 100644 --- a/connect/token/token_test.go +++ b/connect/token/token_test.go @@ -8,7 +8,7 @@ package token import ( "bytes" - nonce2 "gitlab.com/elixxir/crypto/nonce" + nonce2 "gitlab.com/xx_network/crypto/nonce" "reflect" "testing" ) diff --git a/gossip/endpoint_test.go b/gossip/endpoint_test.go index eb8c0af..efcd0ea 100644 --- a/gossip/endpoint_test.go +++ b/gossip/endpoint_test.go @@ -17,7 +17,11 @@ import ( // Test endpoint when manager has a protocol func TestManager_Endpoint_toProtocol(t *testing.T) { - m := NewManager(&connect.ProtoComms{}, DefaultManagerFlags()) + pc := &connect.ProtoComms{ + Manager: connect.NewManagerTesting(t), + } + + m := NewManager(pc, DefaultManagerFlags()) var received bool r := func(msg *GossipMsg) error { @@ -47,7 +51,11 @@ func TestManager_Endpoint_toProtocol(t *testing.T) { // Test endpoint function when there is no protocol and no buffer record func TestManager_Endpoint_toNewBuffer(t *testing.T) { - m := NewManager(&connect.ProtoComms{}, DefaultManagerFlags()) + pc := &connect.ProtoComms{ + Manager: connect.NewManagerTesting(t), + } + + m := NewManager(pc, DefaultManagerFlags()) _, err := m.Endpoint(context.Background(), &GossipMsg{ Tag: "test", Origin: []byte("origin"), @@ -68,7 +76,11 @@ func TestManager_Endpoint_toNewBuffer(t *testing.T) { // Test endpoint function when there is no protocol, but an existing buffer func TestComms_Endpoint_toExistingBuffer(t *testing.T) { - m := NewManager(&connect.ProtoComms{}, DefaultManagerFlags()) + pc := &connect.ProtoComms{ + Manager: connect.NewManagerTesting(t), + } + + m := NewManager(pc, DefaultManagerFlags()) now := time.Now() m.buffer["test"] = &MessageRecord{ Timestamp: now, @@ -93,7 +105,11 @@ func TestComms_Endpoint_toExistingBuffer(t *testing.T) { } func TestManager_Endpoint_AddProtocol(t *testing.T) { - m := NewManager(&connect.ProtoComms{}, DefaultManagerFlags()) + pc := &connect.ProtoComms{ + Manager: connect.NewManagerTesting(t), + } + + m := NewManager(pc, DefaultManagerFlags()) _, err := m.Endpoint(context.Background(), &GossipMsg{ Tag: "test", Origin: []byte("origin"), diff --git a/gossip/manager_test.go b/gossip/manager_test.go index b79910b..359544a 100644 --- a/gossip/manager_test.go +++ b/gossip/manager_test.go @@ -16,7 +16,11 @@ import ( // Basic test on manager creation func TestNewManager(t *testing.T) { - m := NewManager(&connect.ProtoComms{}, DefaultManagerFlags()) + pc := &connect.ProtoComms{ + Manager: connect.NewManagerTesting(t), + } + + m := NewManager(pc, DefaultManagerFlags()) if m.buffer == nil || m.protocols == nil { t.Error("Failed to initialize all fields properly") } @@ -24,7 +28,11 @@ func TestNewManager(t *testing.T) { // Happy path test for adding new gossip protocol func TestManager_NewGossip(t *testing.T) { - m := NewManager(&connect.ProtoComms{}, DefaultManagerFlags()) + pc := &connect.ProtoComms{ + Manager: connect.NewManagerTesting(t), + } + + m := NewManager(pc, DefaultManagerFlags()) r := func(msg *GossipMsg) error { return nil @@ -41,7 +49,11 @@ func TestManager_NewGossip(t *testing.T) { // Happy path test for new gossip protocol with messages in buffer for that tag func TestManager_NewGossip_WithBuffer(t *testing.T) { - m := NewManager(&connect.ProtoComms{}, DefaultManagerFlags()) + pc := &connect.ProtoComms{ + Manager: connect.NewManagerTesting(t), + } + + m := NewManager(pc, DefaultManagerFlags()) m.buffer["test"] = &MessageRecord{ Timestamp: time.Time{}, Messages: []*GossipMsg{{Tag: "testmsg"}}, @@ -74,7 +86,11 @@ func TestManager_NewGossip_WithBuffer(t *testing.T) { // Basic unit test for getting a protocol func TestManager_Get(t *testing.T) { - m := NewManager(&connect.ProtoComms{}, DefaultManagerFlags()) + pc := &connect.ProtoComms{ + Manager: connect.NewManagerTesting(t), + } + + m := NewManager(pc, DefaultManagerFlags()) m.protocols = map[string]*Protocol{"test": {}} _, ok := m.Get("test") @@ -85,7 +101,11 @@ func TestManager_Get(t *testing.T) { // Basic unit test for deleting a protocol func TestManager_Delete(t *testing.T) { - m := NewManager(&connect.ProtoComms{}, DefaultManagerFlags()) + pc := &connect.ProtoComms{ + Manager: connect.NewManagerTesting(t), + } + + m := NewManager(pc, DefaultManagerFlags()) m.protocols = map[string]*Protocol{"test": {}} m.Delete("test") diff --git a/gossip/protocol_test.go b/gossip/protocol_test.go index ee7f732..c0f7814 100644 --- a/gossip/protocol_test.go +++ b/gossip/protocol_test.go @@ -32,7 +32,8 @@ import ( func TestProtocol_AddGossipPeer(t *testing.T) { p := setup(t) testHostID := id.NewIdFromString("testhost", id.Node, t) - _, err := p.comms.AddHost(testHostID, "0.0.0.0:420", nil, true, false) + + _, err := p.comms.AddHost(testHostID, "0.0.0.0:420", nil, connect.GetDefaultHostParams()) if err != nil { t.Errorf("Failed to add test host: %+v", err) } @@ -179,7 +180,7 @@ func setup(t *testing.T) *Protocol { return nil } c := &connect.ProtoComms{ - Manager: connect.Manager{}, + Manager: connect.NewManagerTesting(t), } return &Protocol{ comms: c, @@ -445,7 +446,9 @@ func TestGossipNodes(t *testing.T) { for j := 0; j < numNodes; j++ { if i != j { peers = append(peers, nodes[j]) - _, err := managers[i].comms.AddHost(nodes[j], "127.0.0.1:"+ports[j], certPEM, false, false) + params := connect.GetDefaultHostParams() + params.AuthEnabled = false + _, err := managers[i].comms.AddHost(nodes[j], "127.0.0.1:"+ports[j], certPEM, params) if err != nil { t.Fatal(err) } -- GitLab