-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from Code-Hex/fix/119
fixed #119
- Loading branch information
Showing
8 changed files
with
213 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package testhelper | ||
|
||
import ( | ||
"io" | ||
"net" | ||
"testing" | ||
"time" | ||
|
||
"golang.org/x/crypto/ssh" | ||
) | ||
|
||
func NewSshConfig(username, password string) *ssh.ClientConfig { | ||
return &ssh.ClientConfig{ | ||
User: username, | ||
Auth: []ssh.AuthMethod{ssh.Password(password)}, | ||
HostKeyCallback: ssh.InsecureIgnoreHostKey(), | ||
} | ||
} | ||
|
||
func NewSshClient(conn net.Conn, addr string, config *ssh.ClientConfig) (*ssh.Client, error) { | ||
c, chans, reqs, err := ssh.NewClientConn(conn, addr, config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return ssh.NewClient(c, chans, reqs), nil | ||
} | ||
|
||
func SetKeepAlive(t *testing.T, session *ssh.Session) { | ||
t.Helper() | ||
go func() { | ||
for range time.Tick(5 * time.Second) { | ||
_, err := session.SendRequest("keepalive@codehex.vz", true, nil) | ||
if err != nil && err != io.EOF { | ||
t.Logf("failed to send keep-alive request: %v", err) | ||
return | ||
} | ||
} | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.