1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -05:00
v2fly/testing/mocks/fakeoutboundhandler.go

34 lines
670 B
Go
Raw Normal View History

2015-09-11 08:12:09 -04:00
package mocks
import (
"bytes"
"github.com/v2ray/v2ray-core"
v2net "github.com/v2ray/v2ray-core/net"
)
type FakeOutboundConnectionHandler struct {
2015-09-11 08:15:06 -04:00
Data2Send *bytes.Buffer
2015-09-11 08:12:09 -04:00
Data2Return []byte
2015-09-12 16:11:54 -04:00
Destination v2net.Address
2015-09-11 08:12:09 -04:00
}
2015-09-12 16:11:54 -04:00
func (handler *FakeOutboundConnectionHandler) Start(ray core.OutboundRay) error {
2015-09-11 08:12:09 -04:00
input := ray.OutboundInput()
output := ray.OutboundOutput()
output <- handler.Data2Return
for {
data, open := <-input
if !open {
break
}
handler.Data2Send.Write(data)
}
return nil
}
2015-09-12 16:11:54 -04:00
func (handler *FakeOutboundConnectionHandler) Create(point *core.Point, dest v2net.Address) (core.OutboundConnectionHandler, error) {
2015-09-11 08:12:09 -04:00
return handler, nil
}