2020-05-22 10:41:24 +00:00
|
|
|
package telebit
|
2020-05-18 09:30:22 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEncodeDataMessage(t *testing.T) {
|
2020-05-19 09:36:46 +00:00
|
|
|
id := Addr{
|
2020-05-18 09:30:22 +00:00
|
|
|
family: "IPv4",
|
|
|
|
addr: "192.168.1.101",
|
|
|
|
port: 6743,
|
|
|
|
}
|
2020-05-19 09:36:46 +00:00
|
|
|
tun := Addr{
|
|
|
|
family: id.family,
|
2020-05-21 10:29:05 +00:00
|
|
|
addr: "ex1.telebit.io",
|
2020-05-18 09:30:22 +00:00
|
|
|
port: 80,
|
|
|
|
scheme: "http",
|
|
|
|
}
|
|
|
|
|
|
|
|
payload := []byte("Hello, World!")
|
|
|
|
header := []byte("IPv4,192.168.1.101,6743," + strconv.Itoa(len(payload)) + ",http,80,ex1.telebit.io,\n")
|
|
|
|
//header = append([]byte{V1, byte(len(header))}, header...)
|
|
|
|
header = append([]byte{254, byte(len(header))}, header...)
|
|
|
|
|
2020-05-21 10:29:05 +00:00
|
|
|
h, b, err := Encode(payload, id, tun)
|
2020-05-18 09:30:22 +00:00
|
|
|
if nil != err {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if string(header) != string(h) {
|
|
|
|
t.Fatalf("header %q should have matched %q", h, header)
|
|
|
|
}
|
|
|
|
if string(b) != string(payload) {
|
|
|
|
t.Fatal("payload should be the exact reference to the original slice")
|
|
|
|
}
|
|
|
|
}
|