-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Blaine Gardner <[email protected]>
- Loading branch information
Showing
6 changed files
with
37 additions
and
10 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,15 +91,19 @@ func TestConnector_Connect(t *testing.T) { | |
testutil.WriteFile(parsableKeyfile, parsableKey, 0644) | ||
|
||
// Test connector ready to go with an identity file added | ||
stubConnector := NewConnector() | ||
stubConnector.AddIdentityFile(parsableKeyfile) | ||
stubConnector := func() *Connector { | ||
c := NewConnector() | ||
c.AddIdentityFile(parsableKeyfile) | ||
return c | ||
} | ||
|
||
stubClient := &ssh.Client{} // stub dialer always returns this client | ||
|
||
var lastAddrDialed string // for checking that the right address was dialed | ||
failDial := true | ||
dialHost = func(network, addr string, config *ssh.ClientConfig) (*ssh.Client, error) { | ||
lastAddrDialed = addr | ||
// include the user in report of last addr dialed to keep test definitions leaner | ||
lastAddrDialed = config.User + "@" + addr | ||
if failDial { | ||
return nil, fmt.Errorf("test dial error") | ||
} | ||
|
@@ -130,16 +134,22 @@ func TestConnector_Connect(t *testing.T) { | |
failDial bool | ||
wants wants | ||
}{ | ||
{"successful connection", stubConnector, "1.1.1.1", false, wants{ | ||
addrDialed: "1.1.1.1:22", actor: expectedActor("1.1.1.1"), err: false}}, | ||
{"fail to dial", stubConnector, "2.2.2.2", true, wants{ | ||
addrDialed: "2.2.2.2:22", actor: nil, err: true}}, | ||
{"successful connection", stubConnector(), "1.1.1.1", false, wants{ | ||
addrDialed: "root@1.1.1.1:22", actor: expectedActor("1.1.1.1"), err: false}}, | ||
{"fail to dial", stubConnector(), "2.2.2.2", true, wants{ | ||
addrDialed: "root@2.2.2.2:22", actor: nil, err: true}}, | ||
{"connector w/o id file", NewConnector(), "not dialed", false, wants{ | ||
addrDialed: "not dialed", actor: nil, err: true}}, | ||
// Effectively test Port option | ||
{"connect with a different port", | ||
func() (c *Connector) { c = new(Connector); *c = *stubConnector; c.Port(2222); return }(), | ||
func() *Connector { c := stubConnector(); c.Port(2222); return c }(), | ||
"3.3.3.3", false, wants{ | ||
addrDialed: "3.3.3.3:2222", actor: expectedActor("3.3.3.3"), err: false}}, | ||
addrDialed: "[email protected]:2222", actor: expectedActor("3.3.3.3"), err: false}}, | ||
// Effectively test User option | ||
{"connect with a different user", | ||
func() *Connector { c := stubConnector(); c.User("sam"); return c }(), | ||
"4.4.4.4", false, wants{ | ||
addrDialed: "[email protected]:22", actor: expectedActor("4.4.4.4"), err: false}}, | ||
} | ||
for _, tt := range tests { | ||
lastAddrDialed = "not dialed" | ||
|