0
0
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 21:30:16 +02:00

add croc test

This commit is contained in:
Zack Scholl 2019-04-29 19:51:54 -07:00
parent 7d1f7adddb
commit 859130a988

67
src/croc/croc_test.go Normal file
View 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()
}