mirror of https://github.com/schollz/croc.git
fix tests with nodisable flag
This commit is contained in:
parent
a1e5a283f9
commit
e72795985b
|
@ -52,6 +52,7 @@ type Options struct {
|
||||||
RelayPorts []string
|
RelayPorts []string
|
||||||
Stdout bool
|
Stdout bool
|
||||||
NoPrompt bool
|
NoPrompt bool
|
||||||
|
DisableLocal bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
@ -226,6 +227,7 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
||||||
// connect to the relay for messaging
|
// connect to the relay for messaging
|
||||||
errchan := make(chan error, 1)
|
errchan := make(chan error, 1)
|
||||||
|
|
||||||
|
if !c.Options.DisableLocal {
|
||||||
// setup the relay locally
|
// setup the relay locally
|
||||||
for _, port := range c.Options.RelayPorts {
|
for _, port := range c.Options.RelayPorts {
|
||||||
go func(portStr string) {
|
go func(portStr string) {
|
||||||
|
@ -275,6 +277,7 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
||||||
c.Options.RelayAddress = "localhost"
|
c.Options.RelayAddress = "localhost"
|
||||||
errchan <- c.transfer(options)
|
errchan <- c.transfer(options)
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
log.Debug("establishing connection")
|
log.Debug("establishing connection")
|
||||||
|
@ -302,14 +305,18 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
||||||
// Receive will receive a file
|
// Receive will receive a file
|
||||||
func (c *Client) Receive() (err error) {
|
func (c *Client) Receive() (err error) {
|
||||||
// look for peers first
|
// look for peers first
|
||||||
|
if !c.Options.DisableLocal {
|
||||||
|
|
||||||
discoveries, err := peerdiscovery.Discover(peerdiscovery.Settings{
|
discoveries, err := peerdiscovery.Discover(peerdiscovery.Settings{
|
||||||
Limit: 1,
|
Limit: 1,
|
||||||
Payload: []byte("ok"),
|
Payload: []byte("ok"),
|
||||||
Delay: 10 * time.Millisecond,
|
Delay: 10 * time.Millisecond,
|
||||||
TimeLimit: 100 * time.Millisecond,
|
TimeLimit: 100 * time.Millisecond,
|
||||||
})
|
})
|
||||||
|
_ = err
|
||||||
log.Debugf("discoveries: %+v", discoveries)
|
log.Debugf("discoveries: %+v", discoveries)
|
||||||
log.Debug("establishing connection")
|
log.Debug("establishing connection")
|
||||||
|
}
|
||||||
c.conn[0], err = tcp.ConnectToTCPServer(c.Options.RelayAddress+":"+c.Options.RelayPorts[0], c.Options.SharedSecret)
|
c.conn[0], err = tcp.ConnectToTCPServer(c.Options.RelayAddress+":"+c.Options.RelayPorts[0], c.Options.SharedSecret)
|
||||||
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))
|
||||||
|
|
|
@ -30,6 +30,7 @@ func TestCroc(t *testing.T) {
|
||||||
RelayPorts: []string{"8081", "8082", "8083"},
|
RelayPorts: []string{"8081", "8082", "8083"},
|
||||||
Stdout: false,
|
Stdout: false,
|
||||||
NoPrompt: true,
|
NoPrompt: true,
|
||||||
|
DisableLocal: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -44,6 +45,7 @@ func TestCroc(t *testing.T) {
|
||||||
RelayPorts: []string{"8081", "8082", "8083"},
|
RelayPorts: []string{"8081", "8082", "8083"},
|
||||||
Stdout: false,
|
Stdout: false,
|
||||||
NoPrompt: true,
|
NoPrompt: true,
|
||||||
|
DisableLocal: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
Loading…
Reference in New Issue