mirror of
https://github.com/go-i2p/go-sam-go.git
synced 2025-07-19 10:35:42 -04:00
start on a wrapper for sam3
This commit is contained in:
@@ -1,132 +0,0 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
from = RandPort()
|
||||
to = RandPort()
|
||||
)
|
||||
|
||||
func setupTestEmit() *SAMEmit {
|
||||
return &SAMEmit{
|
||||
I2PConfig: I2PConfig{
|
||||
SamHost: "127.0.0.1",
|
||||
SamPort: 7656,
|
||||
SamMin: "3.0",
|
||||
SamMax: "3.1",
|
||||
Style: "STREAM",
|
||||
TunName: "testid",
|
||||
Fromport: from,
|
||||
Toport: to,
|
||||
SigType: "ED25519",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestSAMEmit_Hello(t *testing.T) {
|
||||
emit := setupTestEmit()
|
||||
want := "HELLO VERSION MIN=3.0 MAX=3.1 \n"
|
||||
|
||||
t.Run("string output", func(t *testing.T) {
|
||||
if got := emit.Hello(); got != want {
|
||||
t.Errorf("Hello() = %v, want %v", got, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("byte output", func(t *testing.T) {
|
||||
if got := emit.HelloBytes(); !bytes.Equal(got, []byte(want)) {
|
||||
t.Errorf("HelloBytes() = %v, want %v", got, []byte(want))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestSAMEmit_GenerateDestination(t *testing.T) {
|
||||
emit := setupTestEmit()
|
||||
want := "DEST GENERATE ED25519 \n"
|
||||
|
||||
t.Run("string output", func(t *testing.T) {
|
||||
if got := emit.GenerateDestination(); got != want {
|
||||
t.Errorf("GenerateDestination() = %v, want %v", got, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("byte output", func(t *testing.T) {
|
||||
if got := emit.GenerateDestinationBytes(); !bytes.Equal(got, []byte(want)) {
|
||||
t.Errorf("GenerateDestinationBytes() = %v, want %v", got, []byte(want))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestSAMEmit_Lookup(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
lookup string
|
||||
want string
|
||||
}{
|
||||
{"basic lookup", "test.i2p", "NAMING LOOKUP NAME=test.i2p \n"},
|
||||
{"empty lookup", "", "NAMING LOOKUP NAME= \n"},
|
||||
}
|
||||
|
||||
emit := setupTestEmit()
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := emit.Lookup(tt.lookup); got != tt.want {
|
||||
t.Errorf("Lookup() = %v, want %v", got, tt.want)
|
||||
}
|
||||
if got := emit.LookupBytes(tt.lookup); !bytes.Equal(got, []byte(tt.want)) {
|
||||
t.Errorf("LookupBytes() = %v, want %v", got, []byte(tt.want))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSAMEmit_Connect(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
dest string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
"basic connect",
|
||||
"destination123",
|
||||
"STREAM CONNECT ID=testid " + from + " " + to + " DESTINATION=destination123 \n",
|
||||
},
|
||||
{
|
||||
"empty destination",
|
||||
"",
|
||||
"STREAM CONNECT ID=testid " + from + " " + to + " DESTINATION= \n",
|
||||
},
|
||||
}
|
||||
|
||||
emit := setupTestEmit()
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := emit.Connect(tt.dest); got != tt.want {
|
||||
t.Errorf("Connect() = %v, want %v", got, tt.want)
|
||||
}
|
||||
if got := emit.ConnectBytes(tt.dest); !bytes.Equal(got, []byte(tt.want)) {
|
||||
t.Errorf("ConnectBytes() = %v, want %v", got, []byte(tt.want))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSAMEmit_Accept(t *testing.T) {
|
||||
emit := setupTestEmit()
|
||||
want := "STREAM ACCEPT ID=testid " + from + " " + to + ""
|
||||
|
||||
t.Run("string output", func(t *testing.T) {
|
||||
if got := emit.Accept(); got != want {
|
||||
t.Errorf("Accept() = %v, want %v", got, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("byte output", func(t *testing.T) {
|
||||
if got := emit.AcceptBytes(); !bytes.Equal(got, []byte(want)) {
|
||||
t.Errorf("AcceptBytes() = %v, want %v", got, []byte(want))
|
||||
}
|
||||
})
|
||||
}
|
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
// Creates a new datagram session. udpPort is the UDP port SAM is listening on,
|
||||
// and if you set it to zero, it will use SAMs standard UDP port.
|
||||
func (s *SAM) NewDatagramSession(id string, keys i2pkeys.I2PKeys, options []string, udpPort int) (*DatagramSession, error) {
|
||||
func (s SAM) NewDatagramSession(id string, keys i2pkeys.I2PKeys, options []string, udpPort int) (*DatagramSession, error) {
|
||||
log.WithFields(logrus.Fields{
|
||||
"id": id,
|
||||
"udpPort": udpPort,
|
||||
|
Reference in New Issue
Block a user