Last active
July 23, 2022 17:05
-
-
Save metarsit/5cd4cafda05b9cd1e18c3918d56f5076 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package medium | |
| import ( | |
| "testing" | |
| "github.com/metarsit/sshtest" | |
| "gotest.tools/v3/assert" | |
| ) | |
| func TestRunCmdOverSSH(t *testing.T) { | |
| const ( | |
| fakeUsername = "fake_username" | |
| fakePassword = "super_secret_password" | |
| fakeCmd = "fake_command" | |
| addr = "localhost:2222" | |
| returnMsg = "something was run over there" | |
| ) | |
| hp := sshtest.NewHoneyPot(addr) | |
| // Start the server in the background | |
| go func() { | |
| hp.ListenAndServe() | |
| }() | |
| t.Cleanup(func() { | |
| hp.Close() | |
| }) | |
| hp.SetReturnString(returnMsg) | |
| result, err := RunCmdOverSSH(addr, fakeUsername, fakePassword, fakeCmd) | |
| assert.NilError(t, err) | |
| assert.Equal(t, string(result), returnMsg) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment