Skip to content
Snippets Groups Projects
Select Git revision
  • 2bdcc4ab910a2327749c28a837f3c78f72891299
  • 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

fileTransfer.go

Blame
  • firstMessagePart_test.go 3.23 KiB
    ///////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                          //
    //                                                                           //
    // Use of this source code is governed by a license that can be found in the //
    // LICENSE file                                                              //
    ///////////////////////////////////////////////////////////////////////////////
    
    package parse
    
    import (
    	"bytes"
    	"gitlab.com/elixxir/client/catalog"
    	"reflect"
    	"testing"
    	"time"
    )
    
    // Expected firstMessagePart for checking against, generated by fmp in
    // TestNewFirstMessagePart.
    var expectedFMP = firstMessagePart{
    	messagePart: messagePart{
    		Data: []byte{0, 0, 4, 53, 0, 0, 13, 2, 0, 0, 0, 2, 22, 87, 28, 11, 215,
    			220, 82, 0, 116, 101, 115, 116, 105, 110, 103, 115, 116, 114, 105,
    			110, 103, 0, firstMessagePartCurrentVersion},
    		Id:   []byte{0, 0, 4, 53},
    		Part: []byte{0},
    		Len:  []byte{0, 13},
    		Contents: []byte{116, 101, 115, 116, 105, 110, 103, 115, 116, 114, 105,
    			110, 103},
    	},
    	NumParts:  []byte{2},
    	Type:      []byte{0, 0, 0, 2},
    	Timestamp: []byte{22, 87, 28, 11, 215, 220, 82, 0},
    	Version:   []byte{firstMessagePartCurrentVersion},
    }
    
    // Test that newFirstMessagePart returns a correctly made firstMessagePart.
    func Test_newFirstMessagePart(t *testing.T) {
    	fmp := newFirstMessagePart(
    		catalog.XxMessage,
    		1077,
    		2,
    		time.Unix(1609786229, 0).UTC(),
    		[]byte{'t', 'e', 's', 't', 'i', 'n', 'g', 's', 't', 'r', 'i', 'n', 'g'}, len(expectedFMP.Data),
    	)
    
    	gotTime := fmp.getTimestamp()
    	expectedTime := time.Unix(1609786229, 0).UTC()
    	if !gotTime.Equal(expectedTime) {
    		t.Errorf("Failed to get expected timestamp."+
    			"\nexpected: %s\nreceived: %s", expectedTime, gotTime)
    	}
    
    	if !reflect.DeepEqual(fmp, expectedFMP) {
    		t.Errorf("Expected and got firstMessagePart did not match."+
    			"\nexpected: %+v\nrecieved: %+v", expectedFMP, fmp)
    	}
    }
    
    // Test that firstMessagePartFromBytes returns a correctly made firstMessagePart
    // from the bytes of one.
    func Test_firstMessagePartFromBytes(t *testing.T) {
    	fmp := firstMessagePartFromBytes(expectedFMP.Data)
    
    	if !reflect.DeepEqual(fmp, expectedFMP) {
    		t.Error("Expected and got firstMessagePart did not match")
    	}
    }
    
    // Test that firstMessagePart.getType returns the correct type.
    func Test_firstMessagePart_getType(t *testing.T) {
    	if expectedFMP.getType() != catalog.XxMessage {
    		t.Errorf("Got %v, expected %v", expectedFMP.getType(), catalog.XxMessage)
    	}
    }
    
    // Test that firstMessagePart.getNumParts returns the correct number of parts.
    func Test_firstMessagePart_getNumParts(t *testing.T) {
    	if expectedFMP.getNumParts() != 2 {
    		t.Errorf("Got %v, expected %v", expectedFMP.getNumParts(), 2)
    	}
    }
    
    // Test that firstMessagePart.getTimestamp returns the correct timestamp.
    func Test_firstMessagePart_getTimestamp(t *testing.T) {
    	et := expectedFMP.getTimestamp()
    	if !time.Unix(1609786229, 0).Equal(et) {
    		t.Errorf("Got %v, expected %v", et, time.Unix(1609786229, 0))
    	}
    }
    
    // Test that firstMessagePart.bytes returns the correct bytes.
    func Test_firstMessagePart_bytes(t *testing.T) {
    	if !bytes.Equal(expectedFMP.bytes(), expectedFMP.Data) {
    		t.Errorf("Got %v, expected %v", expectedFMP.bytes(), expectedFMP.Data)
    	}
    }