本文整理汇总了Golang中github.com/v2ray/v2ray-core/testing/assert.StringLiteral函数的典型用法代码示例。如果您正苦于以下问题:Golang StringLiteral函数的具体用法?Golang StringLiteral怎么用?Golang StringLiteral使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringLiteral函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestHopByHopHeadersStrip
func TestHopByHopHeadersStrip(t *testing.T) {
v2testing.Current(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.StringLiteral(req.Header.Get("Foo")).Equals("foo")
assert.StringLiteral(req.Header.Get("Bar")).Equals("bar")
assert.StringLiteral(req.Header.Get("Connection")).Equals("keep-alive,Foo, Bar")
assert.StringLiteral(req.Header.Get("Proxy-Connection")).Equals("keep-alive")
assert.StringLiteral(req.Header.Get("Proxy-Authenticate")).Equals("abc")
StripHopByHopHeaders(req)
assert.StringLiteral(req.Header.Get("Connection")).Equals("close")
assert.StringLiteral(req.Header.Get("Foo")).Equals("")
assert.StringLiteral(req.Header.Get("Bar")).Equals("")
assert.StringLiteral(req.Header.Get("Proxy-Connection")).Equals("")
assert.StringLiteral(req.Header.Get("Proxy-Authenticate")).Equals("")
}
示例2: TestStreamLogger
func TestStreamLogger(t *testing.T) {
v2testing.Current(t)
buffer := bytes.NewBuffer(make([]byte, 0, 1024))
infoLogger = &stdOutLogWriter{
logger: log.New(buffer, "", 0),
}
Info("Test ", "Stream Logger", " Format")
assert.StringLiteral(string(buffer.Bytes())).Equals("[Info]Test Stream Logger Format" + platform.LineSeparator())
buffer.Reset()
errorLogger = infoLogger
Error("Test ", serial.StringLiteral("literal"), " Format")
assert.StringLiteral(string(buffer.Bytes())).Equals("[Error]Test literal Format" + platform.LineSeparator())
}
示例3: TestBuildAndRun
func TestBuildAndRun(t *testing.T) {
v2testing.Current(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.StringLiteral(errStr).Equals("")
os.Remove(target)
}
示例4: TestSocksUdpSend
func TestSocksUdpSend(t *testing.T) {
v2testing.Current(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,
}
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och",
func(space app.Space, config interface{}) (v2proxy.OutboundConnectionHandler, error) {
return och, nil
})
assert.Error(err).IsNil()
config := &point.Config{
Port: port,
InboundConfig: &point.ConnectionConfig{
Protocol: "socks",
Settings: []byte(`{"auth": "noauth", "udp": true}`),
},
OutboundConfig: &point.ConnectionConfig{
Protocol: protocol,
Settings: 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.StringLiteral(och.Destination.String()).Equals("udp:8.8.4.4:53")
}
示例5: TestPubsub
func TestPubsub(t *testing.T) {
v2testing.Current(t)
messages := make(map[string]app.PubsubMessage)
pubsub := New()
pubsub.Subscribe(&apptesting.Context{}, "t1", func(message app.PubsubMessage) {
messages["t1"] = message
})
pubsub.Subscribe(&apptesting.Context{}, "t2", func(message app.PubsubMessage) {
messages["t2"] = message
})
message := app.PubsubMessage([]byte("This is a pubsub message."))
pubsub.Publish(&apptesting.Context{}, "t2", message)
<-time.Tick(time.Second)
_, found := messages["t1"]
assert.Bool(found).IsFalse()
actualMessage, found := messages["t2"]
assert.Bool(found).IsTrue()
assert.StringLiteral(string(actualMessage)).Equals(string(message))
}
示例6: TestDokodemoUDP
func TestDokodemoUDP(t *testing.T) {
v2testing.Current(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: v2netjson.NewIPHost(net.ParseIP("127.0.0.1")),
PortValue: port,
NetworkList: &networkList,
TimeoutValue: 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.StringLiteral("Processed: " + data2Send).Equals(string(response[:nBytes]))
}
示例7: TestHttpProxy
func TestHttpProxy(t *testing.T) {
v2testing.Current(t)
httpServer := &v2http.Server{
Port: v2net.Port(50042),
PathHandler: make(map[string]http.HandlerFunc),
}
_, err := httpServer.Start()
assert.Error(err).IsNil()
defer httpServer.Close()
assert.Error(InitializeServerSetOnce("test_5")).IsNil()
transport := &http.Transport{
Proxy: func(req *http.Request) (*url.URL, error) {
return url.Parse("http://127.0.0.1:50040/")
},
}
client := &http.Client{
Transport: transport,
}
resp, err := client.Get("http://127.0.0.1:50042/")
assert.Error(err).IsNil()
assert.Int(resp.StatusCode).Equals(200)
content, err := ioutil.ReadAll(resp.Body)
assert.Error(err).IsNil()
assert.StringLiteral(string(content)).Equals("Home")
CloseAllServers()
}
示例8: TestDokodemoTCP
func TestDokodemoTCP(t *testing.T) {
v2testing.Current(t)
port := v2nettesting.PickPort()
data2Send := "Data to be sent to remote."
tcpServer := &tcp.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 := tcpServer.Start()
assert.Error(err).IsNil()
pointPort := v2nettesting.PickPort()
config := mocks.Config{
PortValue: pointPort,
InboundConfigValue: &mocks.ConnectionConfig{
ProtocolValue: "dokodemo-door",
SettingsValue: []byte(`{
"address": "127.0.0.1",
"port": ` + port.String() + `,
"network": "tcp",
"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()
tcpClient, err := net.DialTCP("tcp", nil, &net.TCPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(pointPort),
Zone: "",
})
assert.Error(err).IsNil()
tcpClient.Write([]byte(data2Send))
tcpClient.CloseWrite()
response := make([]byte, 1024)
nBytes, err := tcpClient.Read(response)
assert.Error(err).IsNil()
tcpClient.Close()
assert.StringLiteral("Processed: " + data2Send).Equals(string(response[:nBytes]))
}
示例9: TestSocksUdpSend
func TestSocksUdpSend(t *testing.T) {
v2testing.Current(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",
UDP: 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.StringLiteral(och.Destination.String()).Equals("udp:8.8.4.4:53")
}
示例10: TestSocksTcpConnect
func TestSocksTcpConnect(t *testing.T) {
v2testing.Current(t)
port := v2nettesting.PickPort()
connInput := []byte("The data to be returned to socks server.")
connOutput := bytes.NewBuffer(make([]byte, 0, 1024))
och := &proxymocks.OutboundConnectionHandler{
ConnOutput: connOutput,
ConnInput: bytes.NewReader(connInput),
}
protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och", func(space app.Space, config interface{}) (v2proxy.OutboundConnectionHandler, error) {
return och, nil
})
assert.Error(err).IsNil()
config := mocks.Config{
PortValue: port,
InboundConfigValue: &mocks.ConnectionConfig{
ProtocolValue: "socks",
SettingsValue: []byte(`
{
"auth": "noauth"
}`),
},
OutboundConfigValue: &mocks.ConnectionConfig{
ProtocolValue: protocol,
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), nil, proxy.Direct)
assert.Error(err).IsNil()
targetServer := "google.com:80"
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.StringLiteral(targetServer).Equals(och.Destination.NetAddr())
}
示例11: TestRandom
func TestRandom(t *testing.T) {
v2testing.Current(t)
uuid := New()
uuid2 := New()
assert.StringLiteral(uuid.String()).NotEquals(uuid2.String())
assert.Bytes(uuid.Bytes()).NotEquals(uuid2.Bytes())
}
示例12: TestSocksTcpConnectWithUserPass
func TestSocksTcpConnectWithUserPass(t *testing.T) {
v2testing.Current(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.SocksAccountMap{
"userx": "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.StringLiteral(targetServer).Equals(och.Destination.NetAddr())
}
示例13: TestServerSampleConfig
func TestServerSampleConfig(t *testing.T) {
v2testing.Current(t)
// TODO: fix for Windows
baseDir := "$GOPATH/src/github.com/v2ray/v2ray-core/release/config"
pointConfig, err := LoadConfig(filepath.Join(baseDir, "vpoint_vmess_freedom.json"))
assert.Error(err).IsNil()
netassert.Port(pointConfig.Port).IsValid()
assert.Pointer(pointConfig.InboundConfig).IsNotNil()
assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
assert.StringLiteral(pointConfig.InboundConfig.Protocol).Equals("vmess")
assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil()
assert.StringLiteral(pointConfig.OutboundConfig.Protocol).Equals("freedom")
assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil()
}
示例14: TestNewUUID
func TestNewUUID(t *testing.T) {
v2testing.Current(t)
uuid := New()
uuid2, err := ParseString(uuid.String())
assert.Error(err).IsNil()
assert.StringLiteral(uuid.String()).Equals(uuid2.String())
assert.Bytes(uuid.Bytes()).Equals(uuid2.Bytes())
}
示例15: TestServerSampleConfig
func TestServerSampleConfig(t *testing.T) {
v2testing.Current(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()
netassert.Port(pointConfig.Port).IsValid()
assert.Pointer(pointConfig.InboundConfig).IsNotNil()
assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
assert.StringLiteral(pointConfig.InboundConfig.Protocol).Equals("vmess")
assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil()
assert.StringLiteral(pointConfig.OutboundConfig.Protocol).Equals("freedom")
assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil()
}