mirror of https://github.com/schollz/croc.git
add more tests
This commit is contained in:
parent
6287a7b7f7
commit
f89dd01e87
|
@ -300,7 +300,7 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
||||||
go func() {
|
go func() {
|
||||||
log.Debugf("establishing connection to %s", c.Options.RelayAddress)
|
log.Debugf("establishing connection to %s", c.Options.RelayAddress)
|
||||||
var banner string
|
var banner string
|
||||||
conn, banner, ipaddr, err := tcp.ConnectToTCPServer(c.Options.RelayAddress, c.Options.SharedSecret)
|
conn, banner, ipaddr, err := tcp.ConnectToTCPServer(c.Options.RelayAddress, c.Options.SharedSecret, 5*time.Second)
|
||||||
log.Debugf("banner: %s", banner)
|
log.Debugf("banner: %s", banner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress))
|
err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress))
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package croc
|
package croc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -8,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/schollz/croc/v6/src/tcp"
|
"github.com/schollz/croc/v6/src/tcp"
|
||||||
log "github.com/schollz/logger"
|
log "github.com/schollz/logger"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCroc(t *testing.T) {
|
func TestCroc(t *testing.T) {
|
||||||
|
@ -120,3 +122,40 @@ func TestCrocLocal(t *testing.T) {
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCrocError(t *testing.T) {
|
||||||
|
content := []byte("temporary file's content")
|
||||||
|
tmpfile, err := ioutil.TempFile("", "example")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer os.Remove(tmpfile.Name()) // clean up
|
||||||
|
|
||||||
|
if _, err := tmpfile.Write(content); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if err := tmpfile.Close(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug(false)
|
||||||
|
log.SetLevel("warn")
|
||||||
|
sender, _ := New(Options{
|
||||||
|
IsSender: true,
|
||||||
|
SharedSecret: "test",
|
||||||
|
Debug: true,
|
||||||
|
RelayAddress: "doesntexistok.com:8181",
|
||||||
|
RelayPorts: []string{"8181", "8182"},
|
||||||
|
Stdout: true,
|
||||||
|
NoPrompt: true,
|
||||||
|
DisableLocal: true,
|
||||||
|
})
|
||||||
|
err = sender.Send(TransferOptions{
|
||||||
|
PathToFiles: []string{tmpfile.Name()},
|
||||||
|
KeepPathInRemote: true,
|
||||||
|
})
|
||||||
|
log.Debug(err)
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue