func NewPacket(command uint16, payload interface{}) *Packet { inst := &Packet{ Command: command, ID: consistenthash.NewRandomKey(), Sent: time.Now(), Payload: payload, } return inst }
func NewResponsePacket(command uint16, requestid [16]byte, payload interface{}) *Packet { inst := &Packet{ Command: command, ID: [16]byte(consistenthash.NewRandomKey()), RequestID: requestid, Sent: time.Now(), Payload: payload, } return inst }
func TestNewResponsePacket(t *testing.T) { payload := "Test2" k1 := [16]byte(consistenthash.NewRandomKey()) inst := NewResponsePacket(CMD_DISTRIBUTION, k1, payload) assert.Equal(t, inst.Command, uint16(CMD_DISTRIBUTION)) assert.NotNil(t, inst.ID) assert.NotNil(t, inst.RequestID, k1) assert.NotNil(t, inst.Sent) assert.Equal(t, inst.Payload, payload) }