handlers_test.go 1.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
package dht

import (
	"bytes"
	"testing"

	proto "github.com/gogo/protobuf/proto"
	recpb "github.com/libp2p/go-libp2p-record/pb"
)

func TestCleanRecordSigned(t *testing.T) {
	actual := new(recpb.Record)
13
	actual.TimeReceived = "time"
14
	actual.Value = []byte("value")
15
	actual.Key = []byte("key")
16 17 18 19 20 21 22 23 24

	cleanRecord(actual)
	actualBytes, err := proto.Marshal(actual)
	if err != nil {
		t.Fatal(err)
	}

	expected := new(recpb.Record)
	expected.Value = []byte("value")
25
	expected.Key = []byte("key")
26 27 28 29 30 31 32 33 34 35 36 37
	expectedBytes, err := proto.Marshal(expected)
	if err != nil {
		t.Fatal(err)
	}

	if !bytes.Equal(actualBytes, expectedBytes) {
		t.Error("failed to clean record")
	}
}

func TestCleanRecord(t *testing.T) {
	actual := new(recpb.Record)
38 39
	actual.TimeReceived = "time"
	actual.Key = []byte("key")
40 41 42 43 44 45 46 47 48
	actual.Value = []byte("value")

	cleanRecord(actual)
	actualBytes, err := proto.Marshal(actual)
	if err != nil {
		t.Fatal(err)
	}

	expected := new(recpb.Record)
49
	expected.Key = []byte("key")
50 51 52 53 54 55 56 57 58 59
	expected.Value = []byte("value")
	expectedBytes, err := proto.Marshal(expected)
	if err != nil {
		t.Fatal(err)
	}

	if !bytes.Equal(actualBytes, expectedBytes) {
		t.Error("failed to clean record")
	}
}