diff --git a/channels/messages_test.go b/channels/messages_test.go index 14b54553a499883b305e846435ff4bb20e2a470c..26356e33c59b9f64751a76e1a198fc86d25d273d 100644 --- a/channels/messages_test.go +++ b/channels/messages_test.go @@ -33,6 +33,43 @@ func TestUnmarshalUserMessageInternal(t *testing.T) { } } +func TestUnmarshalUserMessageInternal_BadUserMessage(t *testing.T) { + _, err := unmarshalUserMessageInternal([]byte("Malformed")) + if err == nil { + t.Fatalf("Error not returned on unmarshaling a bad user " + + "message") + } +} + +func TestUnmarshalUserMessageInternal_BadChannelMessage(t *testing.T) { + _, usrMsg, _ := builtTestUMI(t, 7) + + usrMsg.Message = []byte("Malformed") + + usrMsgMarshaled, err := proto.Marshal(usrMsg) + if err != nil { + t.Fatalf("Failed to marshal user message: %+v", err) + } + + _, err = unmarshalUserMessageInternal(usrMsgMarshaled) + if err == nil { + t.Fatalf("Error not returned on unmarshaling a user message " + + "with a bad channel message") + } +} + +func TestNewUserMessageInternal_BadChannelMessage(t *testing.T) { + _, usrMsg, _ := builtTestUMI(t, 7) + + usrMsg.Message = []byte("Malformed") + + _, err := newUserMessageInternal(usrMsg) + + if err == nil { + t.Fatalf("failed to produce error with malformed user message") + } +} + func TestUserMessageInternal_GetChannelMessage(t *testing.T) { internal, _, channelMsg := builtTestUMI(t, 7) received := internal.GetChannelMessage() diff --git a/channels/userListener_test.go b/channels/userListener_test.go index 0103f4f0b71fe9e006c1916f7a4948a43f1126cd..7a2ec28ac810a3855c53bacb5354e32a18ff2694 100644 --- a/channels/userListener_test.go +++ b/channels/userListener_test.go @@ -3,18 +3,29 @@ package channels import ( "bytes" "crypto/ed25519" + jww "github.com/spf13/jwalterweatherman" + "math/rand" + "os" + "testing" + "time" + "github.com/golang/protobuf/proto" + "gitlab.com/elixxir/client/broadcast" "gitlab.com/elixxir/client/cmix/identity/receptionID" "gitlab.com/elixxir/client/cmix/rounds" cryptoChannel "gitlab.com/elixxir/crypto/channel" "gitlab.com/elixxir/primitives/states" "gitlab.com/xx_network/primitives/id" - "math/rand" - "testing" - "time" ) +func TestMain(m *testing.M) { + // many tests trigger warn prints, set the out threshold so the warns + // can be seen in the logs + jww.SetStdoutThreshold(jww.LevelWarn) + os.Exit(m.Run()) +} + type triggerEventDummy struct { gotData bool