本文整理汇总了Golang中github.com/v2ray/v2ray-core/testing/assert.String函数的典型用法代码示例。如果您正苦于以下问题:Golang String函数的具体用法?Golang String怎么用?Golang String使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了String函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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("")
}
示例2: TestVMessSerialization
func TestVMessSerialization(t *testing.T) {
v2testing.Current(t)
id, err := uuid.ParseString("2b2966ac-16aa-4fbf-8d81-c5f172a3da51")
assert.Error(err).IsNil()
userId := vmess.NewID(id)
testUser := &vmess.User{
ID: userId,
}
userSet := protocoltesting.MockUserSet{[]*vmess.User{}, make(map[string]int), make(map[string]Timestamp)}
userSet.AddUser(testUser)
request := new(VMessRequest)
request.Version = byte(0x01)
request.User = testUser
randBytes := make([]byte, 36)
_, err = rand.Read(randBytes)
assert.Error(err).IsNil()
request.RequestIV = randBytes[:16]
request.RequestKey = randBytes[16:32]
request.ResponseHeader = randBytes[32:]
request.Command = byte(0x01)
request.Address = v2net.DomainAddress("v2ray.com")
request.Port = v2net.Port(80)
mockTime := Timestamp(1823730)
buffer, err := request.ToBytes(&FakeTimestampGenerator{timestamp: mockTime}, nil)
if err != nil {
t.Fatal(err)
}
userSet.UserHashes[string(buffer.Value[:16])] = 0
userSet.Timestamps[string(buffer.Value[:16])] = mockTime
requestReader := NewVMessRequestReader(&userSet)
actualRequest, err := requestReader.Read(bytes.NewReader(buffer.Value))
if err != nil {
t.Fatal(err)
}
assert.Byte(actualRequest.Version).Named("Version").Equals(byte(0x01))
assert.String(actualRequest.User.ID).Named("UserId").Equals(request.User.ID.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).Named("Address").Equals(request.Address.String())
}
示例3: TestDefaultIPAddress
func TestDefaultIPAddress(t *testing.T) {
v2testing.Current(t)
socksConfig, err := config.CreateInboundConnectionConfig("socks", []byte(`{}`))
assert.Error(err).IsNil()
assert.String(socksConfig.(*SocksConfig).IP()).Equals("127.0.0.1")
}
示例4: 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)
}
示例5: TestSwitchAccount
func TestSwitchAccount(t *testing.T) {
v2testing.Current(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()
netassert.Port(sa.Port).Equals(sa2.Port)
assert.String(sa.ID).Equals(sa2.ID.String())
assert.Uint16(sa.AlterIds.Value()).Equals(sa2.AlterIds.Value())
assert.Byte(byte(sa.Level)).Equals(byte(sa2.Level))
assert.Byte(sa.ValidMin).Equals(sa2.ValidMin)
}
示例6: TestAccessLog
func TestAccessLog(t *testing.T) {
assert := assert.On(t)
entry := &AccessLog{
From: "test_from",
To: "test_to",
Status: "Accepted",
Reason: "test_reason",
}
entryStr := entry.String()
assert.String(entryStr).Contains("test_from")
assert.String(entryStr).Contains("test_to")
assert.String(entryStr).Contains("test_reason")
assert.String(entryStr).Contains("Accepted")
}
示例7: TestSwitchAccount
func TestSwitchAccount(t *testing.T) {
v2testing.Current(t)
sa := &SwitchAccount{
Port: 1234,
ID: uuid.New(),
AlterIds: 1024,
ValidUntil: time.Now(),
}
cmd, err := CreateResponseCommand(1)
assert.Error(err).IsNil()
buffer := bytes.NewBuffer(make([]byte, 0, 1024))
nBytes, err := sa.Marshal(buffer)
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(buffer.Len())
cmd.Unmarshal(buffer.Bytes())
sa2, ok := cmd.(*SwitchAccount)
assert.Bool(ok).IsTrue()
netassert.Port(sa.Port).Equals(sa2.Port)
assert.String(sa.ID).Equals(sa2.ID.String())
assert.Uint16(sa.AlterIds.Value()).Equals(sa2.AlterIds.Value())
assert.Int64(sa.ValidUntil.Unix()).Equals(sa2.ValidUntil.Unix())
}
示例8: TestSwitchAccount
func TestSwitchAccount(t *testing.T) {
v2testing.Current(t)
sa := &SwitchAccount{
Port: 1234,
ID: uuid.New(),
AlterIds: 1024,
Level: 128,
ValidMin: 16,
}
cmd, err := CreateResponseCommand(1)
assert.Error(err).IsNil()
buffer := bytes.NewBuffer(make([]byte, 0, 1024))
sa.Marshal(buffer)
cmd.Unmarshal(buffer.Bytes())
sa2, ok := cmd.(*SwitchAccount)
assert.Bool(ok).IsTrue()
assert.Pointer(sa.Host).IsNil()
assert.Pointer(sa2.Host).IsNil()
netassert.Port(sa.Port).Equals(sa2.Port)
assert.String(sa.ID).Equals(sa2.ID.String())
assert.Uint16(sa.AlterIds.Value()).Equals(sa2.AlterIds.Value())
assert.Byte(byte(sa.Level)).Equals(byte(sa2.Level))
assert.Byte(sa.ValidMin).Equals(sa2.ValidMin)
}
示例9: TestUDPDestination
func TestUDPDestination(t *testing.T) {
v2testing.Current(t)
dest := v2net.UDPDestination(v2net.IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}), 53)
v2netassert.Destination(dest).IsNotTCP()
v2netassert.Destination(dest).IsUDP()
assert.String(dest).Equals("udp:[2001:4860:4860::8888]:53")
}
示例10: TestIPAddressParsing
func TestIPAddressParsing(t *testing.T) {
v2testing.Current(t)
var ipAddress IPAddress
err := json.Unmarshal([]byte("\"1.2.3.4\""), &ipAddress)
assert.Error(err).IsNil()
assert.String(net.IP(ipAddress)).Equals("1.2.3.4")
}
示例11: TestTCPDestination
func TestTCPDestination(t *testing.T) {
v2testing.Current(t)
dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
v2netassert.Destination(dest).IsTCP()
v2netassert.Destination(dest).IsNotUDP()
assert.String(dest).Equals("tcp:1.2.3.4:80")
}
示例12: TestNetIPv4Address
func TestNetIPv4Address(t *testing.T) {
v2testing.Current(t)
ip := net.IPv4(1, 2, 3, 4)
addr := v2net.IPAddress(ip)
v2netassert.Address(addr).IsIPv4()
assert.String(addr).Equals("1.2.3.4")
}
示例13: TestStringLiteralParsing
func TestStringLiteralParsing(t *testing.T) {
v2testing.Current(t)
var s StringLiteral
err := json.Unmarshal([]byte("\"1\""), &s)
assert.Error(err).IsNil()
assert.String(s).Equals("1")
}
示例14: TestDefaultIPAddress
func TestDefaultIPAddress(t *testing.T) {
v2testing.Current(t)
socksConfig, err := config.CreateInboundConfig("socks", []byte(`{
"auth": "noauth"
}`))
assert.Error(err).IsNil()
assert.String(socksConfig.(*socks.Config).Address).Equals("127.0.0.1")
}
示例15: TestRandom
func TestRandom(t *testing.T) {
assert := assert.On(t)
uuid := New()
uuid2 := New()
assert.String(uuid.String()).NotEquals(uuid2.String())
assert.Bytes(uuid.Bytes()).NotEquals(uuid2.Bytes())
}