mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-01-23 01:15:31 -05:00
test case for socks.net
This commit is contained in:
36
testing/mocks/config.go
Normal file
36
testing/mocks/config.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core"
|
||||
)
|
||||
|
||||
type ConnectionConfig struct {
|
||||
ProtocolValue string
|
||||
ContentValue []byte
|
||||
}
|
||||
|
||||
func (config *ConnectionConfig) Protocol() string {
|
||||
return config.ProtocolValue
|
||||
}
|
||||
|
||||
func (config *ConnectionConfig) Content() []byte {
|
||||
return config.ContentValue
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
PortValue uint16
|
||||
InboundConfigValue *ConnectionConfig
|
||||
OutboundConfigValue *ConnectionConfig
|
||||
}
|
||||
|
||||
func (config *Config) Port() uint16 {
|
||||
return config.PortValue
|
||||
}
|
||||
|
||||
func (config *Config) InboundConfig() core.ConnectionConfig {
|
||||
return config.InboundConfigValue
|
||||
}
|
||||
|
||||
func (config *Config) OutboundConfig() core.ConnectionConfig {
|
||||
return config.OutboundConfigValue
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/v2ray/v2ray-core"
|
||||
v2net "github.com/v2ray/v2ray-core/net"
|
||||
)
|
||||
|
||||
type FakeOutboundConnectionHandler struct {
|
||||
Data2Send *bytes.Buffer
|
||||
Data2Return []byte
|
||||
Destination v2net.Address
|
||||
}
|
||||
|
||||
func (handler *FakeOutboundConnectionHandler) Start(ray core.OutboundRay) error {
|
||||
input := ray.OutboundInput()
|
||||
output := ray.OutboundOutput()
|
||||
|
||||
output <- handler.Data2Return
|
||||
for {
|
||||
data, open := <-input
|
||||
if !open {
|
||||
break
|
||||
}
|
||||
handler.Data2Send.Write(data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (handler *FakeOutboundConnectionHandler) Create(point *core.Point, dest v2net.Address) (core.OutboundConnectionHandler, error) {
|
||||
return handler, nil
|
||||
}
|
||||
38
testing/mocks/outboundhandler.go
Normal file
38
testing/mocks/outboundhandler.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/v2ray/v2ray-core"
|
||||
v2net "github.com/v2ray/v2ray-core/net"
|
||||
)
|
||||
|
||||
type OutboundConnectionHandler struct {
|
||||
Data2Send *bytes.Buffer
|
||||
Data2Return []byte
|
||||
Destination v2net.Address
|
||||
}
|
||||
|
||||
func (handler *OutboundConnectionHandler) Start(ray core.OutboundRay) error {
|
||||
input := ray.OutboundInput()
|
||||
output := ray.OutboundOutput()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
data, open := <-input
|
||||
if !open {
|
||||
break
|
||||
}
|
||||
handler.Data2Send.Write(data)
|
||||
}
|
||||
output <- handler.Data2Return
|
||||
close(output)
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (handler *OutboundConnectionHandler) Create(point *core.Point, config []byte, dest v2net.Address) (core.OutboundConnectionHandler, error) {
|
||||
handler.Destination = dest
|
||||
return handler, nil
|
||||
}
|
||||
Reference in New Issue
Block a user