mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
add croc test
This commit is contained in:
parent
7d1f7adddb
commit
859130a988
1 changed files with 67 additions and 0 deletions
67
src/croc/croc_test.go
Normal file
67
src/croc/croc_test.go
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
package croc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
log "github.com/cihub/seelog"
|
||||||
|
"github.com/schollz/croc/v6/src/tcp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCroc(t *testing.T) {
|
||||||
|
defer log.Flush()
|
||||||
|
|
||||||
|
go tcp.Run("debug", "8081")
|
||||||
|
go tcp.Run("debug", "8082")
|
||||||
|
go tcp.Run("debug", "8083")
|
||||||
|
go tcp.Run("debug", "8084")
|
||||||
|
go tcp.Run("debug", "8085")
|
||||||
|
time.Sleep(300 * time.Millisecond)
|
||||||
|
|
||||||
|
log.Flush()
|
||||||
|
log.Debug("setting up sender")
|
||||||
|
log.Flush()
|
||||||
|
sender, err := New(Options{
|
||||||
|
IsSender: true,
|
||||||
|
SharedSecret: "test",
|
||||||
|
Debug: true,
|
||||||
|
RelayAddress: "localhost",
|
||||||
|
RelayPorts: []string{"8081", "8082", "8083"},
|
||||||
|
Stdout: false,
|
||||||
|
NoPrompt: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debug("setting up receiver")
|
||||||
|
receiver, err := New(Options{
|
||||||
|
IsSender: false,
|
||||||
|
SharedSecret: "test",
|
||||||
|
Debug: true,
|
||||||
|
RelayAddress: "localhost",
|
||||||
|
RelayPorts: []string{"8081", "8082", "8083"},
|
||||||
|
Stdout: false,
|
||||||
|
NoPrompt: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(2)
|
||||||
|
go func() {
|
||||||
|
sender.Send(TransferOptions{
|
||||||
|
PathToFiles: []string{"../../README.md"},
|
||||||
|
})
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
go func() {
|
||||||
|
receiver.Receive()
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue