1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-04-10 15:55:32 -04:00

introduce go-cmp

This commit is contained in:
Darien Raymond
2018-11-15 10:30:03 +01:00
parent 7560a99d7b
commit ac4f868078
3 changed files with 39 additions and 34 deletions

View File

@@ -4,9 +4,10 @@ import (
"crypto/rand"
"testing"
"github.com/google/go-cmp/cmp"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/compare"
"v2ray.com/core/proxy/shadowsocks"
)
@@ -32,7 +33,7 @@ func TestAEADCipherUDP(t *testing.T) {
common.Must(cipher.EncodePacket(key, b1))
common.Must(cipher.DecodePacket(key, b1))
if err := compare.BytesEqualWithDetail(b1.Bytes(), payload); err != nil {
t.Error(err)
if diff := cmp.Diff(b1.Bytes(), payload); diff != "" {
t.Error(diff)
}
}

View File

@@ -3,33 +3,35 @@ package shadowsocks_test
import (
"testing"
"github.com/google/go-cmp/cmp"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
. "v2ray.com/core/proxy/shadowsocks"
. "v2ray.com/ext/assert"
)
func TestNormalChunkReading(t *testing.T) {
assert := With(t)
buffer := buf.New()
buffer.Write([]byte{0, 8, 39, 228, 69, 96, 133, 39, 254, 26, 201, 70, 11, 12, 13, 14, 15, 16, 17, 18})
reader := NewChunkReader(buffer, NewAuthenticator(ChunkKeyGenerator(
[]byte{21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36})))
payload, err := reader.ReadMultiBuffer()
assert(err, IsNil)
assert(payload[0].Bytes(), Equals, []byte{11, 12, 13, 14, 15, 16, 17, 18})
common.Must(err)
if diff := cmp.Diff(payload[0].Bytes(), []byte{11, 12, 13, 14, 15, 16, 17, 18}); diff != "" {
t.Error(diff)
}
}
func TestNormalChunkWriting(t *testing.T) {
assert := With(t)
buffer := buf.New()
writer := NewChunkWriter(buffer, NewAuthenticator(ChunkKeyGenerator(
[]byte{21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36})))
b := buf.New()
b.Write([]byte{11, 12, 13, 14, 15, 16, 17, 18})
err := writer.WriteMultiBuffer(buf.NewMultiBufferValue(b))
assert(err, IsNil)
assert(buffer.Bytes(), Equals, []byte{0, 8, 39, 228, 69, 96, 133, 39, 254, 26, 201, 70, 11, 12, 13, 14, 15, 16, 17, 18})
common.Must(writer.WriteMultiBuffer(buf.NewMultiBufferValue(b)))
if diff := cmp.Diff(buffer.Bytes(), []byte{0, 8, 39, 228, 69, 96, 133, 39, 254, 26, 201, 70, 11, 12, 13, 14, 15, 16, 17, 18}); diff != "" {
t.Error(diff)
}
}