Files
zeekay 241625e7d9 rename: ziti → zt across all paths
- Repo names: ziti-* → zt-*
- Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt
- Docker images: hanzozt/ziti-* → hanzozt/zt-*
- C/Java/JS symbols: ziti_* → zt_*
- File and directory names updated
2026-02-18 18:34:19 -08:00

74 lines
1.2 KiB
Go

package loop3
import (
"bytes"
"crypto/rand"
"crypto/sha512"
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hanzozt/zt/zttest/zt-traffic-test/loop3/pb"
"github.com/stretchr/testify/require"
)
type testPeer struct {
bytes.Buffer
}
func (t *testPeer) Close() error {
return nil
}
func Test_MessageSerDeser(t *testing.T) {
req := require.New(t)
data := make([]byte, 4192)
_, err := rand.Read(data)
req.NoError(err)
hash := sha512.Sum512(data)
block := &RandHashedBlock{
Type: BlockTypePlain,
Sequence: 10,
Hash: hash[:],
Data: data,
}
testBuf := &testPeer{}
p := &protocol{
peer: testBuf,
test: &loop3_pb.Test{
Name: "test",
},
}
req.NoError(block.Tx(p))
readBlock := &RandHashedBlock{}
req.NoError(readBlock.Rx(p))
req.True(reflect.DeepEqual(block, readBlock), cmp.Diff(block, readBlock))
data = make([]byte, 4192)
_, err = rand.Read(data)
req.NoError(err)
hash = sha512.Sum512(data)
block = &RandHashedBlock{
Type: BlockTypeLatencyRequest,
Sequence: 10,
Hash: hash[:],
Data: data,
}
req.NoError(block.Tx(p))
readBlock = &RandHashedBlock{}
req.NoError(readBlock.Rx(p))
req.Equal("", cmp.Diff(block, readBlock))
}