本文整理汇总了Golang中github.com/v2ray/v2ray-core/testing/unit.Assert函数的典型用法代码示例。如果您正苦于以下问题:Golang Assert函数的具体用法?Golang Assert怎么用?Golang Assert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Assert函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestReadSingleByte
func TestReadSingleByte(t *testing.T) {
assert := unit.Assert(t)
reader := NewVMessRequestReader(nil)
_, err := reader.Read(bytes.NewReader(make([]byte, 1)))
assert.Error(err).Equals(io.EOF)
}
开发者ID:road0001,项目名称:v2ray-core,代码行数:7,代码来源:vmess_test.go
示例2: TestBuildMacOS
func TestBuildMacOS(t *testing.T) {
assert := unit.Assert(t)
binPath = filepath.Join(os.Getenv("GOPATH"), "testing")
cleanBinPath()
build("macos", "amd64", true, "test")
assert.Bool(allFilesExists(
"v2ray-macos.zip",
"v2ray-test-macos",
filepath.Join("v2ray-test-macos", "config.json"),
filepath.Join("v2ray-test-macos", "v2ray"))).IsTrue()
build("windows", "amd64", true, "test")
assert.Bool(allFilesExists(
"v2ray-windows-64.zip",
"v2ray-test-windows-64",
filepath.Join("v2ray-test-windows-64", "config.json"),
filepath.Join("v2ray-test-windows-64", "v2ray.exe"))).IsTrue()
build("linux", "amd64", true, "test")
assert.Bool(allFilesExists(
"v2ray-linux-64.zip",
"v2ray-test-linux-64",
filepath.Join("v2ray-test-linux-64", "vpoint_socks_vmess.json"),
filepath.Join("v2ray-test-linux-64", "vpoint_vmess_freedom.json"),
filepath.Join("v2ray-test-linux-64", "v2ray"))).IsTrue()
}
开发者ID:road0001,项目名称:v2ray-core,代码行数:27,代码来源:build_test.go
示例3: randomBytes
func randomBytes(p []byte, t *testing.T) {
assert := unit.Assert(t)
nBytes, err := rand.Read(p)
assert.Error(err).IsNil()
assert.Int(nBytes).Named("# bytes of random buffer").Equals(len(p))
}
开发者ID:nicedayzhu,项目名称:v2ray-core,代码行数:7,代码来源:decryptionreader_test.go
示例4: TestResponseWrite
func TestResponseWrite(t *testing.T) {
assert := unit.Assert(t)
response := Socks5Response{
socksVersion,
ErrorSuccess,
AddrTypeIPv4,
[4]byte{0x72, 0x72, 0x72, 0x72},
"",
[16]byte{},
uint16(53),
}
buffer := alloc.NewSmallBuffer().Clear()
defer buffer.Release()
response.Write(buffer)
expectedBytes := []byte{
socksVersion,
ErrorSuccess,
byte(0x00),
AddrTypeIPv4,
0x72, 0x72, 0x72, 0x72,
byte(0x00), byte(0x035),
}
assert.Bytes(buffer.Value).Named("raw response").Equals(expectedBytes)
}
开发者ID:NinjaOSX,项目名称:v2ray-core,代码行数:26,代码来源:socks_test.go
示例5: TestSocksTcpConnect
func TestSocksTcpConnect(t *testing.T) {
t.Skip("Not ready yet.")
assert := unit.Assert(t)
port := uint16(12384)
uuid := "2418d087-648d-4990-86e8-19dca1d006d3"
vid, err := core.UUIDToVID(uuid)
assert.Error(err).IsNil()
config := core.VConfig{
port,
[]core.VUser{core.VUser{vid}},
"",
[]core.VNext{}}
och := new(mocks.FakeOutboundConnectionHandler)
och.Data2Send = bytes.NewBuffer(make([]byte, 1024))
och.Data2Return = []byte("The data to be returned to socks server.")
vpoint, err := core.NewVPoint(&config, SocksServerFactory{}, och)
assert.Error(err).IsNil()
err = vpoint.Start()
assert.Error(err).IsNil()
}
开发者ID:nicholasxjy,项目名称:v2ray-core,代码行数:28,代码来源:socks_test.go
示例6: TestRevParse
func TestRevParse(t *testing.T) {
assert := unit.Assert(t)
rev, err := RevParse("HEAD")
assert.Error(err).IsNil()
assert.Int(len(rev)).GreaterThan(0)
}
开发者ID:road0001,项目名称:v2ray-core,代码行数:7,代码来源:git_test.go
示例7: TestDokodemoUDP
func TestDokodemoUDP(t *testing.T) {
assert := unit.Assert(t)
port := v2nettesting.PickPort()
data2Send := "Data to be sent to remote."
udpServer := &udp.Server{
Port: port,
MsgProcessor: func(data []byte) []byte {
buffer := make([]byte, 0, 2048)
buffer = append(buffer, []byte("Processed: ")...)
buffer = append(buffer, data...)
return buffer
},
}
_, err := udpServer.Start()
assert.Error(err).IsNil()
pointPort := v2nettesting.PickPort()
networkList := v2netjson.NetworkList([]string{"udp"})
config := mocks.Config{
PortValue: pointPort,
InboundConfigValue: &mocks.ConnectionConfig{
ProtocolValue: "dokodemo-door",
SettingsValue: &json.DokodemoConfig{
Host: "127.0.0.1",
Port: int(port),
Network: &networkList,
Timeout: 0,
},
},
OutboundConfigValue: &mocks.ConnectionConfig{
ProtocolValue: "freedom",
SettingsValue: nil,
},
}
point, err := point.NewPoint(&config)
assert.Error(err).IsNil()
err = point.Start()
assert.Error(err).IsNil()
udpClient, err := net.DialUDP("udp", nil, &net.UDPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(pointPort),
Zone: "",
})
assert.Error(err).IsNil()
udpClient.Write([]byte(data2Send))
response := make([]byte, 1024)
nBytes, err := udpClient.Read(response)
assert.Error(err).IsNil()
udpClient.Close()
assert.String("Processed: " + data2Send).Equals(string(response[:nBytes]))
}
开发者ID:sign4bill,项目名称:v2ray-core,代码行数:60,代码来源:dokodemo_test.go
示例8: TestSocksTcpConnectWithUserPass
func TestSocksTcpConnectWithUserPass(t *testing.T) {
assert := unit.Assert(t)
port := v2nettesting.PickPort()
connInput := []byte("The data to be returned to socks server.")
connOutput := bytes.NewBuffer(make([]byte, 0, 1024))
och := &proxymocks.OutboundConnectionHandler{
ConnInput: bytes.NewReader(connInput),
ConnOutput: connOutput,
}
connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och)
config := mocks.Config{
PortValue: port,
InboundConfigValue: &mocks.ConnectionConfig{
ProtocolValue: "socks",
SettingsValue: &json.SocksConfig{
AuthMethod: "password",
Accounts: []json.SocksAccount{
json.SocksAccount{
Username: "userx",
Password: "passy",
},
},
},
},
OutboundConfigValue: &mocks.ConnectionConfig{
ProtocolValue: "mock_och",
SettingsValue: nil,
},
}
point, err := point.NewPoint(&config)
assert.Error(err).IsNil()
err = point.Start()
assert.Error(err).IsNil()
socks5Client, err := proxy.SOCKS5("tcp", fmt.Sprintf("127.0.0.1:%d", port), &proxy.Auth{"userx", "passy"}, proxy.Direct)
assert.Error(err).IsNil()
targetServer := "1.2.3.4:443"
conn, err := socks5Client.Dial("tcp", targetServer)
assert.Error(err).IsNil()
data2Send := "The data to be sent to remote server."
conn.Write([]byte(data2Send))
if tcpConn, ok := conn.(*net.TCPConn); ok {
tcpConn.CloseWrite()
}
dataReturned, err := ioutil.ReadAll(conn)
assert.Error(err).IsNil()
conn.Close()
assert.Bytes([]byte(data2Send)).Equals(connOutput.Bytes())
assert.Bytes(dataReturned).Equals(connInput)
assert.String(targetServer).Equals(och.Destination.Address().String())
}
开发者ID:kennshi,项目名称:v2ray-core,代码行数:60,代码来源:socks_test.go
示例9: TestRepoVersion
func TestRepoVersion(t *testing.T) {
assert := unit.Assert(t)
version, err := RepoVersionHead()
assert.Error(err).IsNil()
assert.Int(len(version)).GreaterThan(0)
}
开发者ID:road0001,项目名称:v2ray-core,代码行数:7,代码来源:git_test.go
示例10: TestBuildAndRun
func TestBuildAndRun(t *testing.T) {
assert := unit.Assert(t)
gopath := os.Getenv("GOPATH")
target := filepath.Join(gopath, "src", "v2ray_test")
fmt.Println(target)
goOS := parseOS(runtime.GOOS)
goArch := parseArch(runtime.GOARCH)
err := buildV2Ray(target, "v1.0", goOS, goArch)
assert.Error(err).IsNil()
outBuffer := bytes.NewBuffer(make([]byte, 0, 1024))
errBuffer := bytes.NewBuffer(make([]byte, 0, 1024))
configFile := filepath.Join(gopath, "src", "github.com", "v2ray", "v2ray-core", "release", "config", "vpoint_socks_vmess.json")
cmd := exec.Command(target, "--config="+configFile)
cmd.Stdout = outBuffer
cmd.Stderr = errBuffer
cmd.Start()
<-time.After(1 * time.Second)
cmd.Process.Kill()
outStr := string(outBuffer.Bytes())
errStr := string(errBuffer.Bytes())
assert.Bool(strings.Contains(outStr, "v1.0")).IsTrue()
assert.Int(len(errStr)).Equals(0)
os.Remove(target)
}
开发者ID:road0001,项目名称:v2ray-core,代码行数:30,代码来源:go_test.go
示例11: TestVMessUDPReadWrite
func TestVMessUDPReadWrite(t *testing.T) {
assert := unit.Assert(t)
userId, err := user.NewID("2b2966ac-16aa-4fbf-8d81-c5f172a3da51")
assert.Error(err).IsNil()
userSet := mocks.MockUserSet{[]user.ID{}, make(map[string]int), make(map[string]int64)}
userSet.AddUser(user.User{userId})
message := &VMessUDP{
user: userId,
version: byte(0x01),
token: 1234,
address: v2net.DomainAddress("v2ray.com", 8372),
data: []byte("An UDP message."),
}
mockTime := int64(1823730)
buffer := message.ToBytes(user.NewTimeHash(user.HMACHash{}), func(base int64, delta int) int64 { return mockTime }, nil)
userSet.UserHashes[string(buffer[:16])] = 0
userSet.Timestamps[string(buffer[:16])] = mockTime
messageRestored, err := ReadVMessUDP(buffer, &userSet)
assert.Error(err).IsNil()
assert.String(messageRestored.user.String).Equals(message.user.String)
assert.Byte(messageRestored.version).Equals(message.version)
assert.Uint16(messageRestored.token).Equals(message.token)
assert.String(messageRestored.address.String()).Equals(message.address.String())
assert.Bytes(messageRestored.data).Equals(message.data)
}
开发者ID:s752550916,项目名称:v2ray-core,代码行数:32,代码来源:udp_test.go
示例12: TestSocksUdpSend
func TestSocksUdpSend(t *testing.T) {
assert := unit.Assert(t)
port := v2nettesting.PickPort()
connInput := []byte("The data to be returned to socks server.")
connOutput := bytes.NewBuffer(make([]byte, 0, 1024))
och := &proxymocks.OutboundConnectionHandler{
ConnInput: bytes.NewReader(connInput),
ConnOutput: connOutput,
}
connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och)
config := mocks.Config{
PortValue: port,
InboundConfigValue: &mocks.ConnectionConfig{
ProtocolValue: "socks",
SettingsValue: &json.SocksConfig{
AuthMethod: "noauth",
UDPEnabled: true,
},
},
OutboundConfigValue: &mocks.ConnectionConfig{
ProtocolValue: "mock_och",
SettingsValue: nil,
},
}
point, err := point.NewPoint(&config)
assert.Error(err).IsNil()
err = point.Start()
assert.Error(err).IsNil()
conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(port),
Zone: "",
})
assert.Error(err).IsNil()
data2Send := []byte("Fake DNS request")
buffer := make([]byte, 0, 1024)
buffer = append(buffer, 0, 0, 0)
buffer = append(buffer, 1, 8, 8, 4, 4, 0, 53)
buffer = append(buffer, data2Send...)
conn.Write(buffer)
response := make([]byte, 1024)
nBytes, err := conn.Read(response)
assert.Error(err).IsNil()
assert.Bytes(response[10:nBytes]).Equals(connInput)
assert.Bytes(data2Send).Equals(connOutput.Bytes())
assert.String(och.Destination.String()).Equals("udp:8.8.4.4:53")
}
开发者ID:kennshi,项目名称:v2ray-core,代码行数:59,代码来源:socks_test.go
示例13: TestIPAddressParsing
func TestIPAddressParsing(t *testing.T) {
assert := unit.Assert(t)
var ipAddress IPAddress
err := json.Unmarshal([]byte("\"1.2.3.4\""), &ipAddress)
assert.Error(err).IsNil()
assert.String(net.IP(ipAddress).String()).Equals("1.2.3.4")
}
开发者ID:road0001,项目名称:v2ray-core,代码行数:8,代码来源:config_test.go
示例14: TestParseOS
func TestParseOS(t *testing.T) {
assert := unit.Assert(t)
assert.Pointer(parseOS("windows")).Equals(Windows)
assert.Pointer(parseOS("macos")).Equals(MacOS)
assert.Pointer(parseOS("linux")).Equals(Linux)
assert.Pointer(parseOS("test")).Equals(UnknownOS)
}
开发者ID:road0001,项目名称:v2ray-core,代码行数:8,代码来源:env_test.go
示例15: TestUDPDestination
func TestUDPDestination(t *testing.T) {
assert := unit.Assert(t)
dest := NewUDPDestination(IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}, 53))
assert.Bool(dest.IsTCP()).IsFalse()
assert.Bool(dest.IsUDP()).IsTrue()
assert.String(dest.String()).Equals("udp:[2001:4860:4860::8888]:53")
}
开发者ID:road0001,项目名称:v2ray-core,代码行数:8,代码来源:destination_test.go
示例16: TestTCPDestination
func TestTCPDestination(t *testing.T) {
assert := unit.Assert(t)
dest := NewTCPDestination(IPAddress([]byte{1, 2, 3, 4}, 80))
assert.Bool(dest.IsTCP()).IsTrue()
assert.Bool(dest.IsUDP()).IsFalse()
assert.String(dest.String()).Equals("tcp:1.2.3.4:80")
}
开发者ID:road0001,项目名称:v2ray-core,代码行数:8,代码来源:destination_test.go
示例17: TestVMessSerialization
func TestVMessSerialization(t *testing.T) {
assert := unit.Assert(t)
userId, err := core.NewID("2b2966ac-16aa-4fbf-8d81-c5f172a3da51")
if err != nil {
t.Fatal(err)
}
userSet := mocks.MockUserSet{[]core.ID{}, make(map[string]int), make(map[string]int64)}
userSet.AddUser(core.User{userId})
request := new(VMessRequest)
request.Version = byte(0x01)
request.UserId = userId
_, err = rand.Read(request.RequestIV[:])
if err != nil {
t.Fatal(err)
}
_, err = rand.Read(request.RequestKey[:])
if err != nil {
t.Fatal(err)
}
_, err = rand.Read(request.ResponseHeader[:])
if err != nil {
t.Fatal(err)
}
request.Command = byte(0x01)
request.Address = v2net.DomainAddress("v2ray.com", 80)
buffer := bytes.NewBuffer(make([]byte, 0, 300))
mockTime := int64(1823730)
requestWriter := NewVMessRequestWriter(v2hash.NewTimeHash(v2hash.HMACHash{}), func(base int64, delta int) int64 { return mockTime })
err = requestWriter.Write(buffer, request)
if err != nil {
t.Fatal(err)
}
userSet.UserHashes[string(buffer.Bytes()[:16])] = 0
userSet.Timestamps[string(buffer.Bytes()[:16])] = mockTime
requestReader := NewVMessRequestReader(&userSet)
actualRequest, err := requestReader.Read(buffer)
if err != nil {
t.Fatal(err)
}
assert.Byte(actualRequest.Version).Named("Version").Equals(byte(0x01))
assert.String(actualRequest.UserId.String).Named("UserId").Equals(request.UserId.String)
assert.Bytes(actualRequest.RequestIV[:]).Named("RequestIV").Equals(request.RequestIV[:])
assert.Bytes(actualRequest.RequestKey[:]).Named("RequestKey").Equals(request.RequestKey[:])
assert.Bytes(actualRequest.ResponseHeader[:]).Named("ResponseHeader").Equals(request.ResponseHeader[:])
assert.Byte(actualRequest.Command).Named("Command").Equals(request.Command)
assert.String(actualRequest.Address.String()).Named("Address").Equals(request.Address.String())
}
开发者ID:neverisland,项目名称:v2ray-core,代码行数:58,代码来源:vmess_test.go
示例18: TestParseArch
func TestParseArch(t *testing.T) {
assert := unit.Assert(t)
assert.Pointer(parseArch("x86")).Equals(X86)
assert.Pointer(parseArch("x64")).Equals(Amd64)
assert.Pointer(parseArch("arm")).Equals(Arm)
assert.Pointer(parseArch("arm64")).Equals(Arm64)
assert.Pointer(parseArch("test")).Equals(UnknownArch)
}
开发者ID:road0001,项目名称:v2ray-core,代码行数:9,代码来源:env_test.go
示例19: TestAuthenticationResponseWrite
func TestAuthenticationResponseWrite(t *testing.T) {
assert := unit.Assert(t)
response := NewAuthenticationResponse(byte(0x05))
buffer := bytes.NewBuffer(make([]byte, 0, 10))
WriteAuthentication(buffer, response)
assert.Bytes(buffer.Bytes()).Equals([]byte{socksVersion, byte(0x05)})
}
开发者ID:NinjaOSX,项目名称:v2ray-core,代码行数:9,代码来源:socks_test.go
示例20: TestStringListParsingList
func TestStringListParsingList(t *testing.T) {
assert := unit.Assert(t)
rawJson := `["a", "b", "c", "d"]`
var strList StringList
err := json.Unmarshal([]byte(rawJson), &strList)
assert.Error(err).IsNil()
assert.Int(strList.Len()).Equals(4)
}
开发者ID:sign4bill,项目名称:v2ray-core,代码行数:9,代码来源:fieldrule_test.go
注:本文中的github.com/v2ray/v2ray-core/testing/unit.Assert函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论