1
0
mirror of https://github.com/schollz/croc.git synced 2024-11-24 16:23:47 +03:00

fix tests

This commit is contained in:
Zack Scholl 2019-11-18 13:25:51 -08:00
parent 6b26af4dca
commit af95cddd8d
2 changed files with 18 additions and 5 deletions

View File

@ -15,9 +15,9 @@ import (
func TestMessage(t *testing.T) {
m := Message{Type: "message", Message: "hello, world"}
e, err := crypt.New(nil, nil)
e, salt, err := crypt.New([]byte("pass"), nil)
assert.Nil(t, err)
fmt.Println(e.Salt())
fmt.Println(salt)
b, err := Encode(e, m)
assert.Nil(t, err)
fmt.Printf("%x\n", b)
@ -68,7 +68,8 @@ func TestSend(t *testing.T) {
a, err := comm.NewConnection("localhost:"+port, 10*time.Minute)
assert.Nil(t, err)
m := Message{Type: "message", Message: "hello, world"}
e, err := crypt.New(nil, nil)
e, salt, err := crypt.New([]byte("pass"), nil)
log.Debug(salt)
assert.Nil(t, err)
assert.Nil(t, Send(a, e, m))

View File

@ -1,6 +1,7 @@
package tcp
import (
"bytes"
"testing"
"time"
@ -23,12 +24,23 @@ func TestTCP(t *testing.T) {
// try sending data
assert.Nil(t, c1.Send([]byte("hello, c2")))
data, err := c2.Receive()
var data []byte
for {
data, err = c2.Receive()
if bytes.Equal(data, []byte{1}) {
continue
}
}
assert.Nil(t, err)
assert.Equal(t, []byte("hello, c2"), data)
assert.Nil(t, c2.Send([]byte("hello, c1")))
data, err = c1.Receive()
for {
data, err = c1.Receive()
if bytes.Equal(data, []byte{1}) {
continue
}
}
assert.Nil(t, err)
assert.Equal(t, []byte("hello, c1"), data)