From 859130a9880ca35916aa9abd0d288f79716eb6ce Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Mon, 29 Apr 2019 19:51:54 -0700 Subject: [PATCH] add croc test --- src/croc/croc_test.go | 67 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/croc/croc_test.go diff --git a/src/croc/croc_test.go b/src/croc/croc_test.go new file mode 100644 index 00000000..643fc523 --- /dev/null +++ b/src/croc/croc_test.go @@ -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() +}