2020-05-22 10:41:24 +00:00
|
|
|
package telebit
|
2020-05-20 07:49:40 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"io"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDialServer(t *testing.T) {
|
|
|
|
// TODO replace the websocket connection with a mock server
|
|
|
|
|
2020-05-21 10:29:05 +00:00
|
|
|
//ctx := context.Background()
|
2020-05-21 18:28:33 +00:00
|
|
|
tun := &WebsocketTunnel{}
|
2020-05-21 05:30:24 +00:00
|
|
|
|
|
|
|
mux := NewRouteMux()
|
2020-05-21 18:28:33 +00:00
|
|
|
t.Fatal(ListenAndServe(tun, mux))
|
2020-05-21 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 10:29:05 +00:00
|
|
|
var ErrNoImpl error = errors.New("not implemented")
|
2020-05-21 05:30:24 +00:00
|
|
|
|
2020-05-21 10:29:05 +00:00
|
|
|
// RWTest is a fake buffer
|
|
|
|
type RWTest struct {
|
|
|
|
closed bool
|
|
|
|
tmpr []byte
|
2020-05-21 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 10:29:05 +00:00
|
|
|
func (rwt *RWTest) Read(dst []byte) (int, error) {
|
|
|
|
if rwt.closed {
|
|
|
|
return 0, io.EOF
|
2020-05-21 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 10:29:05 +00:00
|
|
|
id := Addr{
|
|
|
|
scheme: "http",
|
|
|
|
addr: "192.168.1.108",
|
|
|
|
port: 6732,
|
2020-05-21 05:30:24 +00:00
|
|
|
}
|
2020-05-21 10:29:05 +00:00
|
|
|
tun := Addr{
|
|
|
|
scheme: "http",
|
|
|
|
termination: TLS,
|
|
|
|
addr: "abc.example.com",
|
|
|
|
port: 443,
|
2020-05-21 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 10:29:05 +00:00
|
|
|
if 0 == len(rwt.tmpr) {
|
|
|
|
b := []byte("Hello, World!")
|
|
|
|
h, _, _ := Encode(b, id, tun)
|
|
|
|
rwt.tmpr = append(h, b...)
|
2020-05-20 07:49:40 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 10:29:05 +00:00
|
|
|
n := copy(dst, rwt.tmpr)
|
|
|
|
rwt.tmpr = rwt.tmpr[n:]
|
2020-05-20 07:49:40 +00:00
|
|
|
|
2020-05-21 10:29:05 +00:00
|
|
|
return n, nil
|
2020-05-20 07:49:40 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 10:29:05 +00:00
|
|
|
func (rwt *RWTest) Write(int, []byte) error {
|
|
|
|
if rwt.closed {
|
|
|
|
return io.EOF
|
2020-05-20 07:49:40 +00:00
|
|
|
}
|
2020-05-21 10:29:05 +00:00
|
|
|
return nil
|
2020-05-20 07:49:40 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 10:29:05 +00:00
|
|
|
func (rwt *RWTest) Close() error {
|
|
|
|
rwt.closed = true
|
|
|
|
return nil
|
2020-05-20 07:49:40 +00:00
|
|
|
}
|