diff --git a/src/croc/croc.go b/src/croc/croc.go index 9ad1ab3..ab15e78 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -300,7 +300,7 @@ func (c *Client) Send(options TransferOptions) (err error) { go func() { log.Debugf("establishing connection to %s", c.Options.RelayAddress) 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) if err != nil { err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress)) diff --git a/src/croc/croc_test.go b/src/croc/croc_test.go index 5bd9de6..823fd1b 100644 --- a/src/croc/croc_test.go +++ b/src/croc/croc_test.go @@ -1,6 +1,7 @@ package croc import ( + "io/ioutil" "os" "sync" "testing" @@ -8,6 +9,7 @@ import ( "github.com/schollz/croc/v6/src/tcp" log "github.com/schollz/logger" + "github.com/stretchr/testify/assert" ) func TestCroc(t *testing.T) { @@ -120,3 +122,40 @@ func TestCrocLocal(t *testing.T) { 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) + +}