improve tests

This commit is contained in:
Zack Scholl 2019-09-07 10:06:41 -07:00
parent 33aa006c26
commit a82dd2f284
4 changed files with 73 additions and 7 deletions

View File

@ -47,7 +47,7 @@ func TestComm(t *testing.T) {
}()
time.Sleep(300 * time.Millisecond)
a, err := NewConnection("localhost:" + port)
a, err := NewConnection("localhost:"+port, 10*time.Minute)
assert.Nil(t, err)
data, err := a.Receive()
assert.Equal(t, []byte("hello, world"), data)
@ -56,5 +56,6 @@ func TestComm(t *testing.T) {
assert.Nil(t, a.Send([]byte{'\x00'}))
assert.Nil(t, a.Send(token))
_ = a.Connection()
a.Close()
}

View File

@ -70,12 +70,18 @@ func TestCompress(t *testing.T) {
dataRateSavings := 100 * (1.0 - float64(len(compressedB))/float64(len(fable)))
fmt.Printf("Level 9: %2.0f%% percent space savings\n", dataRateSavings)
assert.True(t, len(compressedB) < len(fable))
assert.Equal(t, fable, Decompress(compressedB))
compressedB = CompressWithOption(fable, -2)
dataRateSavings = 100 * (1.0 - float64(len(compressedB))/float64(len(fable)))
fmt.Printf("Level -2: %2.0f%% percent space savings\n", dataRateSavings)
assert.True(t, len(compressedB) < len(fable))
compressedB = Compress(fable)
dataRateSavings = 100 * (1.0 - float64(len(compressedB))/float64(len(fable)))
fmt.Printf("Level -2: %2.0f%% percent space savings\n", dataRateSavings)
assert.True(t, len(compressedB) < len(fable))
data := make([]byte, 4096)
rand.Read(data)
compressedB = CompressWithOption(data, -2)
@ -85,6 +91,7 @@ func TestCompress(t *testing.T) {
rand.Read(data)
compressedB = CompressWithOption(data, 9)
dataRateSavings = 100 * (1.0 - float64(len(compressedB))/float64(len(data)))
fmt.Printf("random, Level 9: %2.0f%% percent space savings\n", dataRateSavings)
}

View File

@ -65,3 +65,61 @@ func TestCroc(t *testing.T) {
wg.Wait()
}
func TestCrocLocal(t *testing.T) {
log.SetLevel("trace")
defer os.Remove("README.md")
// go tcp.Run("debug", "8081", "8082,8083,8084,8085")
// 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.Debug("setting up sender")
sender, err := New(Options{
IsSender: true,
SharedSecret: "test",
Debug: true,
RelayAddress: "localhost:8181",
RelayPorts: []string{"8181", "8182"},
Stdout: false,
NoPrompt: true,
DisableLocal: false,
})
if err != nil {
panic(err)
}
time.Sleep(1 * time.Second)
log.Debug("setting up receiver")
receiver, err := New(Options{
IsSender: false,
SharedSecret: "test",
Debug: true,
RelayAddress: "localhost:8181",
Stdout: false,
NoPrompt: true,
DisableLocal: false,
})
if err != nil {
panic(err)
}
var wg sync.WaitGroup
wg.Add(2)
go func() {
sender.Send(TransferOptions{
PathToFiles: []string{"../../README.md"},
KeepPathInRemote: true,
})
wg.Done()
}()
time.Sleep(100 * time.Millisecond)
go func() {
receiver.Receive()
wg.Done()
}()
wg.Wait()
}

View File

@ -8,14 +8,14 @@ import (
)
func TestTCP(t *testing.T) {
go Run("debug", "8081", "8082")
go Run("debug", "8281", "8282")
time.Sleep(100 * time.Millisecond)
c1, banner, _, err := ConnectToTCPServer("localhost:8081", "testRoom")
assert.Equal(t, banner, "8082")
c1, banner, _, err := ConnectToTCPServer("localhost:8281", "testRoom")
assert.Equal(t, banner, "8282")
assert.Nil(t, err)
c2, _, _, err := ConnectToTCPServer("localhost:8081", "testRoom")
c2, _, _, err := ConnectToTCPServer("localhost:8281", "testRoom")
assert.Nil(t, err)
_, _, _, err = ConnectToTCPServer("localhost:8081", "testRoom")
_, _, _, err = ConnectToTCPServer("localhost:8281", "testRoom")
assert.NotNil(t, err)
// try sending data