forked from yinheli/sshw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscp_test.go
75 lines (61 loc) · 1.06 KB
/
scp_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package sshw
import (
"fmt"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestScp(t *testing.T) {
p := "scp.go"
info, err := os.Stat(p)
assert.Nil(t, err)
assert.False(t, info.IsDir())
f, _ := os.Open(p)
defer f.Close()
s := fmt.Sprintf("%04d", info.Mode())
fmt.Println(s)
}
func TestBase(t *testing.T) {
ps := []string{
"./",
"./xx",
"/",
"/xx/",
"~",
"~/xx",
"~/.",
"/.",
"/./",
"/../.",
"/xx",
"/.././xx",
}
bs := []string{}
for _, p := range ps {
bs = append(bs, filepath.Base(filepath.Clean(p)))
}
fmt.Printf("%+v\n", bs)
}
func TestParsePath(t *testing.T) {
cases := map[string]string{
"hello": "./hello",
"/hello": "/hello",
"./hello": "./hello",
"xx:": "./",
"xx:.": "./",
"xx:hello": "./hello",
"xx:./hello": "./hello",
"xx:~/hello": "~/hello",
"xx:/": "/",
}
for k, v := range cases {
_, p, err := ParseHostFile(k)
assert.Nil(t, err)
assert.Equal(t, v, p)
}
}
func TestHistory(t *testing.T) {
v := os.Environ()
fmt.Println(v)
}