From e8ef8e1c6107df1504fa8a44a1824ff70bd706ba Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Mon, 24 Sep 2018 07:00:48 -0700 Subject: [PATCH] add test --- src/croc/croc.go | 6 +++++- src/croc/croc_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/croc/croc_test.go diff --git a/src/croc/croc.go b/src/croc/croc.go index cda398b..464566a 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -51,10 +51,14 @@ type Croc struct { // Init will initiate with the default parameters func Init(debug bool) (c *Croc) { c = new(Croc) - c.CurveType = "siec" c.UseCompression = true c.UseEncryption = true c.AllowLocalDiscovery = true + c.RelayWebsocketPort = "8153" + c.RelayTCPPort = "8154" + c.CurveType = "siec" + c.Address = "198.199.67.130" + c.NoRecipientPrompt = true debugLevel := "info" if debug { debugLevel = "debug" diff --git a/src/croc/croc_test.go b/src/croc/croc_test.go new file mode 100644 index 0000000..d698d8e --- /dev/null +++ b/src/croc/croc_test.go @@ -0,0 +1,40 @@ +package croc + +import ( + "crypto/rand" + "io/ioutil" + "os" + "sync" + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func TestSendReceive(t *testing.T) { + generateRandomFile(100) + + var wg sync.WaitGroup + wg.Add(2) + go func() { + defer wg.Done() + c := Init(true) + assert.Nil(t, c.Send("100mb.file", "test")) + }() + go func() { + defer wg.Done() + time.Sleep(100 * time.Millisecond) + os.MkdirAll("test", 0755) + os.Chdir("test") + c := Init(true) + assert.Nil(t, c.Receive("test")) + }() + wg.Wait() +} + +func generateRandomFile(megabytes int) { + // generate a random file + bigBuff := make([]byte, 1024*1024*megabytes) + rand.Read(bigBuff) + ioutil.WriteFile("100mb.file", bigBuff, 0666) +}