本文整理汇总了Golang中github.com/v2ray/v2ray-core/testing/assert.On函数的典型用法代码示例。如果您正苦于以下问题:Golang On函数的具体用法?Golang On怎么用?Golang On使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了On函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
}
示例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()
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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("")
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}