1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package remote
- import (
- "fmt"
- "testing"
- )
- func NewSSHClientTest() (*SSHClient, error) {
- sshClient, err := NewSSHClient("1", "gtong", "845895", "127.0.0.1", "22")
- if err != nil {
- fmt.Errorf("NewSSHClient failed: %v", err)
- return nil, err
- }
- //sshClient.Close()
- return sshClient, nil
- }
- func TestRunCommand(t *testing.T) {
- sshClient, err := NewSSHClientTest()
- if err != nil {
- t.Errorf("NewSSHClientTest failed: %v\n", err)
- return
- }
- str, err := sshClient.RunCommand("ls -l")
- if err != nil {
- t.Errorf("RunCommand failed: %v\n", err)
- return
- }
- fmt.Println("str: ", str)
- }
- func TestSystemInfo(t *testing.T) {
- sshClient, err := NewSSHClientTest()
- if err != nil {
- t.Errorf("NewSSHClientTest failed: %v\n", err)
- return
- }
- defer sshClient.Close()
- commands := map[string]string{
- "OS Info": "cat /etc/os-release",
- "CPU Info": "lscpu",
- "Memory Info": "free -h",
- "Disk Info": "df -h",
- "Network Info": "ip addr",
- }
- for name, cmd := range commands {
- output, err := sshClient.RunCommand(cmd)
- if err != nil {
- t.Errorf("%s command failed: %v\n", name, err)
- continue
- }
- fmt.Printf("%s:\n%s\n", name, output)
- }
- }
|