本文整理汇总了Golang中github.com/v2ray/v2ray-core/testing/assert.On函数的典型用法代码示例。如果您正苦于以下问题:Golang On函数的具体用法?Golang On怎么用?Golang On使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了On函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestInvalidNetworkJson
func TestInvalidNetworkJson(t *testing.T) {
assert := assert.On(t)
var list NetworkList
err := json.Unmarshal([]byte("0"), &list)
assert.Error(err).IsNotNil()
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:7,代码来源:network_json_test.go
示例2: TestInvalidUserJson
func TestInvalidUserJson(t *testing.T) {
assert := assert.On(t)
user := new(User)
err := json.Unmarshal([]byte(`{"email": 1234}`), user)
assert.Error(err).IsNotNil()
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:7,代码来源:user_json_test.go
示例3: TestRecivingWindow
func TestRecivingWindow(t *testing.T) {
assert := assert.On(t)
window := NewReceivingWindow(3)
seg0 := &DataSegment{}
seg1 := &DataSegment{}
seg2 := &DataSegment{}
seg3 := &DataSegment{}
assert.Bool(window.Set(0, seg0)).IsTrue()
assert.Pointer(window.RemoveFirst()).Equals(seg0)
e := window.RemoveFirst()
if e != nil {
assert.Fail("Expecting nil.")
}
assert.Bool(window.Set(1, seg1)).IsTrue()
assert.Bool(window.Set(2, seg2)).IsTrue()
window.Advance()
assert.Bool(window.Set(2, seg3)).IsTrue()
assert.Pointer(window.RemoveFirst()).Equals(seg1)
assert.Pointer(window.Remove(1)).Equals(seg2)
assert.Pointer(window.Remove(2)).Equals(seg3)
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:27,代码来源:receiving_test.go
示例4: TestWrongAddressType
func TestWrongAddressType(t *testing.T) {
assert := assert.On(t)
buffer := alloc.NewSmallBuffer().Clear().AppendBytes(5)
_, err := ReadRequest(buffer, nil, false)
assert.Error(err).Equals(transport.ErrCorruptedPacket)
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:7,代码来源:protocol_test.go
示例5: TestInsufficientPortRequest
func TestInsufficientPortRequest(t *testing.T) {
assert := assert.On(t)
buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1, 1, 2, 3, 4, 5)
_, err := ReadRequest(buffer, nil, false)
assert.Error(err).Equals(transport.ErrCorruptedPacket)
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:7,代码来源:protocol_test.go
示例6: TestSingleBytePayload
func TestSingleBytePayload(t *testing.T) {
assert := assert.On(t)
buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1)
_, err := ReadRequest(buffer, nil, false)
assert.Error(err).Equals(transport.ErrCorruptedPacket)
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:7,代码来源:protocol_test.go
示例7: TestEmptyPayload
func TestEmptyPayload(t *testing.T) {
assert := assert.On(t)
buffer := alloc.NewSmallBuffer().Clear()
_, err := ReadRequest(buffer, nil, false)
assert.Error(err).Equals(io.EOF)
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:7,代码来源:protocol_test.go
示例8: TestReceiverUser
func TestReceiverUser(t *testing.T) {
assert := assert.On(t)
id := protocol.NewID(uuid.New())
alters := protocol.NewAlterIDs(id, 100)
account := &protocol.VMessAccount{
ID: id,
AlterIDs: alters,
}
user := protocol.NewUser(account, protocol.UserLevel(0), "")
rec := NewReceiver(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80), user)
assert.Bool(rec.HasUser(user)).IsTrue()
assert.Int(len(rec.Accounts)).Equals(1)
id2 := protocol.NewID(uuid.New())
alters2 := protocol.NewAlterIDs(id2, 100)
account2 := &protocol.VMessAccount{
ID: id2,
AlterIDs: alters2,
}
user2 := protocol.NewUser(account2, protocol.UserLevel(0), "")
assert.Bool(rec.HasUser(user2)).IsFalse()
rec.AddUser(user2)
assert.Bool(rec.HasUser(user2)).IsTrue()
assert.Int(len(rec.Accounts)).Equals(2)
}
开发者ID:xiaomotou,项目名称:v2ray-core,代码行数:27,代码来源:receiver_test.go
示例9: TestSendingQueue
func TestSendingQueue(t *testing.T) {
assert := assert.On(t)
queue := NewSendingQueue(3)
seg0 := alloc.NewBuffer()
seg1 := alloc.NewBuffer()
seg2 := alloc.NewBuffer()
seg3 := alloc.NewBuffer()
assert.Bool(queue.IsEmpty()).IsTrue()
assert.Bool(queue.IsFull()).IsFalse()
queue.Push(seg0)
assert.Bool(queue.IsEmpty()).IsFalse()
queue.Push(seg1)
queue.Push(seg2)
assert.Bool(queue.IsFull()).IsTrue()
assert.Pointer(queue.Pop()).Equals(seg0)
queue.Push(seg3)
assert.Bool(queue.IsFull()).IsTrue()
assert.Pointer(queue.Pop()).Equals(seg1)
assert.Pointer(queue.Pop()).Equals(seg2)
assert.Pointer(queue.Pop()).Equals(seg3)
assert.Int(int(queue.Len())).Equals(0)
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:31,代码来源:sending_test.go
示例10: TestHopByHopHeadersStrip
func TestHopByHopHeadersStrip(t *testing.T) {
assert := assert.On(t)
rawRequest := `GET /pkg/net/http/ HTTP/1.1
Host: golang.org
Connection: keep-alive,Foo, Bar
Foo: foo
Bar: bar
Proxy-Connection: keep-alive
Proxy-Authenticate: abc
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; de-de) AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/523.10
Accept-Encoding: gzip
Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7
Cache-Control: no-cache
Accept-Language: de,en;q=0.7,en-us;q=0.3
`
b := bufio.NewReader(strings.NewReader(rawRequest))
req, err := http.ReadRequest(b)
assert.Error(err).IsNil()
assert.String(req.Header.Get("Foo")).Equals("foo")
assert.String(req.Header.Get("Bar")).Equals("bar")
assert.String(req.Header.Get("Connection")).Equals("keep-alive,Foo, Bar")
assert.String(req.Header.Get("Proxy-Connection")).Equals("keep-alive")
assert.String(req.Header.Get("Proxy-Authenticate")).Equals("abc")
StripHopByHopHeaders(req)
assert.String(req.Header.Get("Connection")).Equals("close")
assert.String(req.Header.Get("Foo")).Equals("")
assert.String(req.Header.Get("Bar")).Equals("")
assert.String(req.Header.Get("Proxy-Connection")).Equals("")
assert.String(req.Header.Get("Proxy-Authenticate")).Equals("")
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:33,代码来源:server_test.go
示例11: TestBufferedReader
func TestBufferedReader(t *testing.T) {
assert := assert.On(t)
content := alloc.NewLargeBuffer()
len := content.Len()
reader := NewBufferedReader(content)
assert.Bool(reader.Cached()).IsTrue()
payload := make([]byte, 16)
nBytes, err := reader.Read(payload)
assert.Int(nBytes).Equals(16)
assert.Error(err).IsNil()
len2 := content.Len()
assert.Int(len - len2).GreaterThan(16)
nBytes, err = reader.Read(payload)
assert.Int(nBytes).Equals(16)
assert.Error(err).IsNil()
assert.Int(content.Len()).Equals(len2)
reader.SetCached(false)
payload2 := alloc.NewBuffer()
reader.Read(payload2.Value)
assert.Int(content.Len()).Equals(len2)
reader.Read(payload2.Value)
assert.Int(content.Len()).LessThan(len2)
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:33,代码来源:buffered_reader_test.go
示例12: TestBuildAndRun
func TestBuildAndRun(t *testing.T) {
assert := assert.On(t)
gopath := os.Getenv("GOPATH")
goOS := parseOS(runtime.GOOS)
goArch := parseArch(runtime.GOARCH)
target := filepath.Join(gopath, "src", "v2ray_test")
if goOS == Windows {
target += ".exe"
}
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.String(errStr).Equals("")
os.Remove(target)
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:32,代码来源:go_test.go
示例13: TestResponseWrite
func TestResponseWrite(t *testing.T) {
assert := assert.On(t)
response := Socks5Response{
socksVersion,
ErrorSuccess,
AddrTypeIPv4,
[4]byte{0x72, 0x72, 0x72, 0x72},
"",
[16]byte{},
v2net.Port(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).Equals(expectedBytes)
}
开发者ID:xiaomotou,项目名称:v2ray-core,代码行数:26,代码来源:socks_test.go
示例14: TestBadSegment
func TestBadSegment(t *testing.T) {
assert := assert.On(t)
seg, buf := ReadSegment(nil)
assert.Pointer(seg).IsNil()
assert.Int(len(buf)).Equals(0)
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:7,代码来源:segment_test.go
示例15: TestSwitchAccount
func TestSwitchAccount(t *testing.T) {
assert := assert.On(t)
sa := &protocol.CommandSwitchAccount{
Port: 1234,
ID: uuid.New(),
AlterIds: 1024,
Level: 128,
ValidMin: 16,
}
buffer := alloc.NewBuffer().Clear()
err := MarshalCommand(sa, buffer)
assert.Error(err).IsNil()
cmd, err := UnmarshalCommand(1, buffer.Value[2:])
assert.Error(err).IsNil()
sa2, ok := cmd.(*protocol.CommandSwitchAccount)
assert.Bool(ok).IsTrue()
assert.Pointer(sa.Host).IsNil()
assert.Pointer(sa2.Host).IsNil()
assert.Port(sa.Port).Equals(sa2.Port)
assert.String(sa.ID.String()).Equals(sa2.ID.String())
assert.Uint16(sa.AlterIds).Equals(sa2.AlterIds)
assert.Byte(byte(sa.Level)).Equals(byte(sa2.Level))
assert.Byte(sa.ValidMin).Equals(sa2.ValidMin)
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:28,代码来源:commands_test.go
示例16: TestIPResolution
func TestIPResolution(t *testing.T) {
assert := assert.On(t)
space := app.NewSpace()
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, proxyman.NewDefaultOutboundHandlerManager())
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
r, _ := router.CreateRouter("rules", &rules.RouterRuleConfig{}, space)
space.BindApp(router.APP_ID, r)
dnsServer := dns.NewCacheServer(space, &dns.Config{
Hosts: map[string]net.IP{
"v2ray.com": net.IP([]byte{127, 0, 0, 1}),
},
})
space.BindApp(dns.APP_ID, dnsServer)
freedom := NewFreedomConnection(
&Config{DomainStrategy: DomainStrategyUseIP},
space,
&proxy.OutboundHandlerMeta{
Address: v2net.AnyIP,
StreamSettings: &internet.StreamSettings{
Type: internet.StreamConnectionTypeRawTCP,
},
})
space.Initialize()
ipDest := freedom.ResolveIP(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), v2net.Port(80)))
assert.Destination(ipDest).IsTCP()
assert.Address(ipDest.Address()).Equals(v2net.LocalHostIP)
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:31,代码来源:freedom_test.go
示例17: TestACKSegment
func TestACKSegment(t *testing.T) {
assert := assert.On(t)
seg := &AckSegment{
Conv: 1,
ReceivingWindow: 2,
ReceivingNext: 3,
Count: 5,
NumberList: []uint32{1, 3, 5, 7, 9},
TimestampList: []uint32{2, 4, 6, 8, 10},
}
nBytes := seg.ByteSize()
bytes := seg.Bytes(nil)
assert.Int(len(bytes)).Equals(nBytes)
iseg, _ := ReadSegment(bytes)
seg2 := iseg.(*AckSegment)
assert.Uint16(seg2.Conv).Equals(seg.Conv)
assert.Uint32(seg2.ReceivingWindow).Equals(seg.ReceivingWindow)
assert.Uint32(seg2.ReceivingNext).Equals(seg.ReceivingNext)
assert.Byte(seg2.Count).Equals(seg.Count)
for i := byte(0); i < seg2.Count; i++ {
assert.Uint32(seg2.TimestampList[i]).Equals(seg.TimestampList[i])
assert.Uint32(seg2.NumberList[i]).Equals(seg.NumberList[i])
}
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:28,代码来源:segment_test.go
示例18: TestInvalidIdJson
func TestInvalidIdJson(t *testing.T) {
assert := assert.On(t)
user := new(User)
err := json.Unmarshal([]byte(`{"id": "1234"}`), user)
assert.Error(err).IsNotNil()
}
开发者ID:xiaomotou,项目名称:v2ray-core,代码行数:7,代码来源:user_json_test.go
示例19: TestNext
func TestNext(t *testing.T) {
assert := assert.On(t)
uuid := New()
uuid2 := uuid.Next()
assert.Bool(uuid.Equals(uuid2)).IsFalse()
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:7,代码来源:uuid_test.go
示例20: TestWrongProtocolVersion
func TestWrongProtocolVersion(t *testing.T) {
assert := assert.On(t)
buffer := alloc.NewBuffer().Clear().AppendBytes(6, 1, 0)
_, _, err := ReadAuthentication(buffer)
assert.Error(err).Equals(proxy.ErrorInvalidProtocolVersion)
}
开发者ID:xiaomotou,项目名称:v2ray-core,代码行数:7,代码来源:socks_test.go
注:本文中的github.com/v2ray/v2ray-core/testing/assert.On函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论