1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-01 23:16:23 -05:00

format code

This commit is contained in:
V2Ray 2015-09-09 15:26:11 +02:00
parent 5559c1ca60
commit f1292f6035
5 changed files with 25 additions and 25 deletions

View File

@ -16,7 +16,7 @@ func TestAuthenticationRequestRead(t *testing.T) {
0x02, // methods 0x02, // methods
} }
request, err := ReadAuthentication(bytes.NewReader(rawRequest)) request, err := ReadAuthentication(bytes.NewReader(rawRequest))
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.Byte(request.version).Named("Version").Equals(0x05) assert.Byte(request.version).Named("Version").Equals(0x05)
assert.Byte(request.nMethods).Named("#Methods").Equals(0x01) assert.Byte(request.nMethods).Named("#Methods").Equals(0x01)
assert.Byte(request.authMethods[0]).Named("Auth Method").Equals(0x02) assert.Byte(request.authMethods[0]).Named("Auth Method").Equals(0x02)
@ -46,7 +46,7 @@ func TestRequestRead(t *testing.T) {
0x00, 0x35, // port 53 0x00, 0x35, // port 53
} }
request, err := ReadRequest(bytes.NewReader(rawRequest)) request, err := ReadRequest(bytes.NewReader(rawRequest))
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.Byte(request.Version).Named("Version").Equals(0x05) assert.Byte(request.Version).Named("Version").Equals(0x05)
assert.Byte(request.Command).Named("Command").Equals(0x01) assert.Byte(request.Command).Named("Command").Equals(0x01)
assert.Byte(request.AddrType).Named("Address Type").Equals(0x01) assert.Byte(request.AddrType).Named("Address Type").Equals(0x01)

View File

@ -7,21 +7,21 @@ import (
"crypto/rand" "crypto/rand"
mrand "math/rand" mrand "math/rand"
"testing" "testing"
"github.com/v2ray/v2ray-core/testing/unit" "github.com/v2ray/v2ray-core/testing/unit"
) )
func randomBytes(p []byte, t *testing.T) { func randomBytes(p []byte, t *testing.T) {
assert := unit.Assert(t) assert := unit.Assert(t)
nBytes, err := rand.Read(p) nBytes, err := rand.Read(p)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.Int(nBytes).Named("# bytes of random buffer").Equals(len(p)) assert.Int(nBytes).Named("# bytes of random buffer").Equals(len(p))
} }
func TestNormalReading(t *testing.T) { func TestNormalReading(t *testing.T) {
assert := unit.Assert(t) assert := unit.Assert(t)
testSize := 256 testSize := 256
plaintext := make([]byte, testSize) plaintext := make([]byte, testSize)
randomBytes(plaintext, t) randomBytes(plaintext, t)
@ -33,8 +33,8 @@ func TestNormalReading(t *testing.T) {
randomBytes(iv, t) randomBytes(iv, t)
aesBlock, err := aes.NewCipher(key) aesBlock, err := aes.NewCipher(key)
assert.Error(err).IsNil() assert.Error(err).IsNil()
aesMode := cipher.NewCBCEncrypter(aesBlock, iv) aesMode := cipher.NewCBCEncrypter(aesBlock, iv)
ciphertext := make([]byte, testSize) ciphertext := make([]byte, testSize)
@ -55,8 +55,8 @@ func TestNormalReading(t *testing.T) {
} }
bytesRead, err := reader.Read(readtext[readSize : readSize+nBytes]) bytesRead, err := reader.Read(readtext[readSize : readSize+nBytes])
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.Int(bytesRead).Equals(nBytes) assert.Int(bytesRead).Equals(nBytes)
readSize += nBytes readSize += nBytes
} }
assert.Bytes(readtext).Named("Plaintext").Equals(plaintext) assert.Bytes(readtext).Named("Plaintext").Equals(plaintext)
} }

View File

@ -33,9 +33,9 @@ func (a *Assertion) Bytes(value []byte) *BytesSubject {
} }
func (a *Assertion) String(value string) *StringSubject { func (a *Assertion) String(value string) *StringSubject {
return NewStringSubject(NewSubject(a), value) return NewStringSubject(NewSubject(a), value)
} }
func (a *Assertion) Error(value error) *ErrorSubject { func (a *Assertion) Error(value error) *ErrorSubject {
return NewErrorSubject(NewSubject(a), value) return NewErrorSubject(NewSubject(a), value)
} }

View File

@ -32,7 +32,7 @@ func (subject *ErrorSubject) Equals(expectation error) {
} }
func (subject *ErrorSubject) IsNil() { func (subject *ErrorSubject) IsNil() {
if subject.value != nil { if subject.value != nil {
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is nil.") subject.FailWithMessage("Not true that " + subject.DisplayString() + " is nil.")
} }
} }

View File

@ -2,16 +2,16 @@ package core
import ( import (
"testing" "testing"
"github.com/v2ray/v2ray-core/testing/unit" "github.com/v2ray/v2ray-core/testing/unit"
) )
func TestUUIDToVID(t *testing.T) { func TestUUIDToVID(t *testing.T) {
assert := unit.Assert(t) assert := unit.Assert(t)
uuid := "2418d087-648d-4990-86e8-19dca1d006d3" uuid := "2418d087-648d-4990-86e8-19dca1d006d3"
expectedBytes := []byte{0x24, 0x18, 0xd0, 0x87, 0x64, 0x8d, 0x49, 0x90, 0x86, 0xe8, 0x19, 0xdc, 0xa1, 0xd0, 0x06, 0xd3} expectedBytes := []byte{0x24, 0x18, 0xd0, 0x87, 0x64, 0x8d, 0x49, 0x90, 0x86, 0xe8, 0x19, 0xdc, 0xa1, 0xd0, 0x06, 0xd3}
actualBytes, _ := UUIDToVID(uuid) actualBytes, _ := UUIDToVID(uuid)
assert.Bytes(actualBytes[:]).Named("UUID").Equals(expectedBytes) assert.Bytes(actualBytes[:]).Named("UUID").Equals(expectedBytes)
} }