@@ -23,6 +23,12 @@ type line struct {
23
23
time time.Time
24
24
}
25
25
26
+ type symlinkLine struct {
27
+ line string
28
+ name string
29
+ target string
30
+ }
31
+
26
32
type unsupportedLine struct {
27
33
line string
28
34
err error
@@ -35,7 +41,7 @@ var listTests = []line{
35
41
{"-rw-r--r-- 1 marketwired marketwired 12016 Mar 16 2016 2016031611G087802-001.newsml" , "2016031611G087802-001.newsml" , 12016 , EntryTypeFile , newTime (2016 , time .March , 16 )},
36
42
37
43
{"-rwxr-xr-x 3 110 1002 1234567 Dec 02 2009 fileName" , "fileName" , 1234567 , EntryTypeFile , newTime (2009 , time .December , 2 )},
38
- {"lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin" , "bin -> usr/bin " , 0 , EntryTypeLink , newTime (thisYear , time .January , 25 , 0 , 17 )},
44
+ {"lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin" , "bin" , 0 , EntryTypeLink , newTime (thisYear , time .January , 25 , 0 , 17 )},
39
45
40
46
// Another ls style
41
47
{"drwxr-xr-x folder 0 Aug 15 05:49 !!!-Tipp des Haus!" , "!!!-Tipp des Haus!" , 0 , EntryTypeFolder , newTime (thisYear , time .August , 15 , 5 , 49 )},
@@ -74,6 +80,11 @@ var listTests = []line{
74
80
{"-rwxrw-r--+ 1 521 101 2080 May 21 10:53 data.csv" , "data.csv" , 2080 , EntryTypeFile , newTime (thisYear , time .May , 21 , 10 , 53 )},
75
81
}
76
82
83
+ var listTestsSymlink = []symlinkLine {
84
+ {"lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin" , "bin" , "usr/bin" },
85
+ {"lrwxrwxrwx 1 0 1001 27 Jul 07 2017 R-3.4.0.pkg -> el-capitan/base/R-3.4.0.pkg" , "R-3.4.0.pkg" , "el-capitan/base/R-3.4.0.pkg" },
86
+ }
87
+
77
88
// Not supported, we expect a specific error message
78
89
var listTestsFail = []unsupportedLine {
79
90
{"d [R----F--] supervisor 512 Jan 16 18:53 login" , errUnsupportedListLine },
@@ -111,6 +122,25 @@ func TestParseValidListLine(t *testing.T) {
111
122
}
112
123
}
113
124
125
+ func TestParseSymlinks (t * testing.T ) {
126
+ for _ , lt := range listTestsSymlink {
127
+ entry , err := parseListLine (lt .line , now , time .UTC )
128
+ if err != nil {
129
+ t .Errorf ("parseListLine(%v) returned err = %v" , lt .line , err )
130
+ continue
131
+ }
132
+ if entry .Name != lt .name {
133
+ t .Errorf ("parseListLine(%v).Name = '%v', want '%v'" , lt .line , entry .Name , lt .name )
134
+ }
135
+ if entry .Target != lt .target {
136
+ t .Errorf ("parseListLine(%v).Target = '%v', want '%v'" , lt .line , entry .Target , lt .target )
137
+ }
138
+ if entry .Type != EntryTypeLink {
139
+ t .Errorf ("parseListLine(%v).EntryType = %v, want EntryTypeLink" , lt .line , entry .Type )
140
+ }
141
+ }
142
+ }
143
+
114
144
func TestParseUnsupportedListLine (t * testing.T ) {
115
145
for _ , lt := range listTestsFail {
116
146
t .Run (fmt .Sprintf ("parseListLine(%v)" , lt .line ), func (t * testing.T ) {
0 commit comments