Skip to content

Instantly share code, notes, and snippets.

@metarsit
Last active July 23, 2022 17:05
Show Gist options
  • Select an option

  • Save metarsit/5cd4cafda05b9cd1e18c3918d56f5076 to your computer and use it in GitHub Desktop.

Select an option

Save metarsit/5cd4cafda05b9cd1e18c3918d56f5076 to your computer and use it in GitHub Desktop.
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