parent
8f5b34ce00
commit
9284a88df5
6
parse.go
6
parse.go
@ -73,8 +73,10 @@ func parseRFC3659ListLine(line string, now time.Time, loc *time.Location) (*Entr
|
|||||||
// the UNIX ls command.
|
// the UNIX ls command.
|
||||||
func parseLsListLine(line string, now time.Time, loc *time.Location) (*Entry, error) {
|
func parseLsListLine(line string, now time.Time, loc *time.Location) (*Entry, error) {
|
||||||
|
|
||||||
// Has the first field a length of 10 bytes?
|
// Has the first field a length of exactly 10 bytes
|
||||||
if strings.IndexByte(line, ' ') != 10 {
|
// - or 10 bytes with an additional '+' character for indicating ACLs?
|
||||||
|
// If not, return.
|
||||||
|
if i := strings.IndexByte(line, ' '); !(i == 10 || (i == 11 && line[10] == '+')) {
|
||||||
return nil, errUnsupportedListLine
|
return nil, errUnsupportedListLine
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ftp
|
package ftp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -68,6 +69,9 @@ var listTests = []line{
|
|||||||
|
|
||||||
// Odd link count from hostedftp.com
|
// Odd link count from hostedftp.com
|
||||||
{"-r-------- 0 user group 65222236 Feb 24 00:39 RegularFile", "RegularFile", 65222236, EntryTypeFile, newTime(thisYear, time.February, 24, 0, 39)},
|
{"-r-------- 0 user group 65222236 Feb 24 00:39 RegularFile", "RegularFile", 65222236, EntryTypeFile, newTime(thisYear, time.February, 24, 0, 39)},
|
||||||
|
|
||||||
|
// Line with ACL persmissions
|
||||||
|
{"-rwxrw-r--+ 1 521 101 2080 May 21 10:53 data.csv", "data.csv", 2080, EntryTypeFile, newTime(thisYear, time.May, 21, 10, 53)},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not supported, we expect a specific error message
|
// Not supported, we expect a specific error message
|
||||||
@ -84,35 +88,41 @@ var listTestsFail = []unsupportedLine{
|
|||||||
|
|
||||||
func TestParseValidListLine(t *testing.T) {
|
func TestParseValidListLine(t *testing.T) {
|
||||||
for _, lt := range listTests {
|
for _, lt := range listTests {
|
||||||
entry, err := parseListLine(lt.line, now, time.UTC)
|
t.Run(fmt.Sprintf("parseListLine(%v)", lt.line), func(t *testing.T) {
|
||||||
if err != nil {
|
|
||||||
t.Errorf("parseListLine(%v) returned err = %v", lt.line, err)
|
entry, err := parseListLine(lt.line, now, time.UTC)
|
||||||
continue
|
if err != nil {
|
||||||
}
|
t.Errorf("returned err = %v", err)
|
||||||
if entry.Name != lt.name {
|
return
|
||||||
t.Errorf("parseListLine(%v).Name = '%v', want '%v'", lt.line, entry.Name, lt.name)
|
}
|
||||||
}
|
if entry.Name != lt.name {
|
||||||
if entry.Type != lt.entryType {
|
t.Errorf("Name = '%v', want '%v'", entry.Name, lt.name)
|
||||||
t.Errorf("parseListLine(%v).EntryType = %v, want %v", lt.line, entry.Type, lt.entryType)
|
}
|
||||||
}
|
if entry.Type != lt.entryType {
|
||||||
if entry.Size != lt.size {
|
t.Errorf("EntryType = %v, want %v", entry.Type, lt.entryType)
|
||||||
t.Errorf("parseListLine(%v).Size = %v, want %v", lt.line, entry.Size, lt.size)
|
}
|
||||||
}
|
if entry.Size != lt.size {
|
||||||
if !entry.Time.Equal(lt.time) {
|
t.Errorf("Size = %v, want %v", entry.Size, lt.size)
|
||||||
t.Errorf("parseListLine(%v).Time = %v, want %v", lt.line, entry.Time, lt.time)
|
}
|
||||||
}
|
if !entry.Time.Equal(lt.time) {
|
||||||
|
t.Errorf("Time = %v, want %v", entry.Time, lt.time)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseUnsupportedListLine(t *testing.T) {
|
func TestParseUnsupportedListLine(t *testing.T) {
|
||||||
for _, lt := range listTestsFail {
|
for _, lt := range listTestsFail {
|
||||||
_, err := parseListLine(lt.line, now, time.UTC)
|
t.Run(fmt.Sprintf("parseListLine(%v)", lt.line), func(t *testing.T) {
|
||||||
if err == nil {
|
|
||||||
t.Errorf("parseListLine(%v) expected to fail", lt.line)
|
_, err := parseListLine(lt.line, now, time.UTC)
|
||||||
}
|
if err == nil {
|
||||||
if err != lt.err {
|
t.Error("expected to fail")
|
||||||
t.Errorf("parseListLine(%v) expected to fail with error: '%s'; was: '%s'", lt.line, lt.err.Error(), err.Error())
|
}
|
||||||
}
|
if err != lt.err {
|
||||||
|
t.Errorf("expected to fail with error: '%s'; was: '%s'", lt.err.Error(), err.Error())
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user