github.com/zooyer/miskit@v1.0.71/ssh/ssh_test.go (about)

     1  package ssh
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func TestParse(t *testing.T) {
     9  	var err error
    10  	var user, addr, path string
    11  	var tests = []struct {
    12  		Input string
    13  		User  string
    14  		Addr  string
    15  		Path  string
    16  	}{
    17  		{
    18  			Input: "root@127.0.0.1:2022:/tmp/test",
    19  			User:  "root",
    20  			Addr:  "127.0.0.1:2022",
    21  			Path:  "/tmp/test",
    22  		},
    23  		{
    24  			Input: "127.0.0.1:/tmp/test",
    25  			User:  "Administrator",
    26  			Addr:  "127.0.0.1:22",
    27  			Path:  "/tmp/test",
    28  		},
    29  		{
    30  			Input: "root@127.0.0.1",
    31  			User:  "root",
    32  			Addr:  "127.0.0.1:22",
    33  			Path:  "/",
    34  		},
    35  		{
    36  			Input: "127.0.0.1:/",
    37  			User:  "Administrator",
    38  			Addr:  "127.0.0.1:22",
    39  			Path:  "/",
    40  		},
    41  	}
    42  
    43  	for _, test := range tests {
    44  		if user, addr, path, err = parse(test.Input); err != nil {
    45  			t.Fatal(err)
    46  		}
    47  		if user != test.User {
    48  			t.Fatal(user, test.User)
    49  		}
    50  		if addr != test.Addr {
    51  			t.Fatal(addr, test.Addr)
    52  		}
    53  		if path != test.Path {
    54  			t.Fatal(path, test.Path)
    55  		}
    56  	}
    57  }
    58  
    59  func progress(current, total int64) {
    60  	fmt.Println(current, total)
    61  }
    62  
    63  func TestScpFile(t *testing.T) {
    64  	var err error
    65  	if err = Scp("./攀D者-HC(2).mp4", "zzy@127.0.0.1:/home/zzy/video.mp4", "386143717", progress); err != nil {
    66  		t.Fatal(err)
    67  	}
    68  }
    69  
    70  func TestCmd(t *testing.T) {
    71  	output, err := Command("zzy@127.0.0.1", "386143717", "ls")
    72  	if err != nil {
    73  		t.Fatal(err)
    74  	}
    75  	t.Log(output)
    76  }