本文整理汇总了Golang中github.com/v2ray/v2ray-core/testing/assert.String函数的典型用法代码示例。如果您正苦于以下问题:Golang String函数的具体用法?Golang String怎么用?Golang String使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了String函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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("")
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:33,代码来源:server_test.go
示例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())
}
开发者ID:ducktsmt,项目名称:v2ray-core,代码行数:54,代码来源:vmess_test.go
示例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")
}
开发者ID:JohnTsaiAndroid,项目名称:v2ray-core,代码行数:7,代码来源:config_test.go
示例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)
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:32,代码来源:go_test.go
示例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)
}
开发者ID:wangyou,项目名称:v2ray-core,代码行数:28,代码来源:commands_test.go
示例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")
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:16,代码来源:log_entry_test.go
示例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())
}
开发者ID:ibmendoza,项目名称:v2ray-core,代码行数:26,代码来源:accounts_test.go
示例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)
}
开发者ID:airmao,项目名称:v2ray-core,代码行数:28,代码来源:accounts_test.go
示例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")
}
开发者ID:ducktsmt,项目名称:v2ray-core,代码行数:8,代码来源:destination_test.go
示例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")
}
开发者ID:adoot,项目名称:v2ray-core,代码行数:8,代码来源:config_test.go
示例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")
}
开发者ID:ducktsmt,项目名称:v2ray-core,代码行数:8,代码来源:destination_test.go
示例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")
}
开发者ID:ducktsmt,项目名称:v2ray-core,代码行数:8,代码来源:address_test.go
示例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")
}
开发者ID:jim1568cas,项目名称:v2ray-core,代码行数:8,代码来源:string_json_test.go
示例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")
}
开发者ID:airmao,项目名称:v2ray-core,代码行数:9,代码来源:config_json_test.go
示例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())
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:9,代码来源:uuid_test.go
示例16: TestParseBytes
func TestParseBytes(t *testing.T) {
v2testing.Current(t)
str := "2418d087-648d-4990-86e8-19dca1d006d3"
bytes := []byte{0x24, 0x18, 0xd0, 0x87, 0x64, 0x8d, 0x49, 0x90, 0x86, 0xe8, 0x19, 0xdc, 0xa1, 0xd0, 0x06, 0xd3}
uuid, err := ParseBytes(bytes)
assert.Error(err).IsNil()
assert.String(uuid).Equals(str)
}
开发者ID:JohnTsaiAndroid,项目名称:v2ray-core,代码行数:10,代码来源:uuid_test.go
示例17: TestServerSampleConfig
func TestServerSampleConfig(t *testing.T) {
assert := assert.On(t)
GOPATH := os.Getenv("GOPATH")
baseDir := filepath.Join(GOPATH, "src", "github.com", "v2ray", "v2ray-core", "release", "config")
pointConfig, err := LoadConfig(filepath.Join(baseDir, "vpoint_vmess_freedom.json"))
assert.Error(err).IsNil()
assert.Pointer(pointConfig.InboundConfig).IsNotNil()
assert.Port(pointConfig.InboundConfig.Port).IsValid()
assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
assert.String(pointConfig.InboundConfig.Protocol).Equals("vmess")
assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil()
assert.String(pointConfig.OutboundConfig.Protocol).Equals("freedom")
assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil()
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:19,代码来源:config_json_test.go
示例18: TestNewUUID
func TestNewUUID(t *testing.T) {
assert := assert.On(t)
uuid := New()
uuid2, err := ParseString(uuid.String())
assert.Error(err).IsNil()
assert.String(uuid.String()).Equals(uuid2.String())
assert.Bytes(uuid.Bytes()).Equals(uuid2.Bytes())
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:10,代码来源:uuid_test.go
示例19: TestIPv4Asv6
func TestIPv4Asv6(t *testing.T) {
v2testing.Current(t)
ip := []byte{
byte(0), byte(0), byte(0), byte(0),
byte(0), byte(0), byte(0), byte(0),
byte(0), byte(0), byte(255), byte(255),
byte(1), byte(2), byte(3), byte(4),
}
addr := v2net.IPAddress(ip)
assert.String(addr).Equals("1.2.3.4")
}
开发者ID:airmao,项目名称:v2ray-core,代码行数:11,代码来源:address_test.go
示例20: TestNoAuthConfig
func TestNoAuthConfig(t *testing.T) {
v2testing.Current(t)
var config SocksConfig
err := json.Unmarshal([]byte("{\"auth\":\"noauth\", \"ip\":\"8.8.8.8\"}"), &config)
assert.Error(err).IsNil()
assert.Bool(config.IsNoAuth()).IsTrue()
assert.Bool(config.IsPassword()).IsFalse()
assert.String(config.IP()).Equals("8.8.8.8")
assert.Bool(config.UDPEnabled()).IsFalse()
}
开发者ID:adoot,项目名称:v2ray-core,代码行数:11,代码来源:config_test.go
注:本文中的github.com/v2ray/v2ray-core/testing/assert.String函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论