| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- package ftp
- import (
- "fmt"
- "testing"
- "time"
- "github.com/stretchr/testify/assert"
- )
- func TestFieldsReturnCorrectData(t *testing.T) {
- w := Walker{
- cur: item{
- path: "/root/",
- err: fmt.Errorf("This is an error"),
- entry: Entry{
- Name: "root",
- Size: 123,
- Time: time.Now(),
- Type: EntryTypeFolder,
- },
- },
- }
- assert.Equal(t, "This is an error", w.Err().Error())
- assert.Equal(t, "/root/", w.Path())
- assert.Equal(t, EntryTypeFolder, w.Stat().Type)
- }
- func TestSkipDirIsCorrectlySet(t *testing.T) {
- w := Walker{}
- w.SkipDir()
- assert.Equal(t, false, w.descend)
- }
- func TestNoDescendDoesNotAddToStack(t *testing.T) {
- w := new(Walker)
- w.cur = item{
- path: "/root/",
- err: nil,
- entry: Entry{
- Name: "root",
- Size: 123,
- Time: time.Now(),
- Type: EntryTypeFolder,
- },
- }
- w.stack = []item{
- item{
- path: "file",
- err: nil,
- entry: Entry{
- Name: "file",
- Size: 123,
- Time: time.Now(),
- Type: EntryTypeFile,
- },
- },
- }
- w.SkipDir()
- result := w.Step()
- assert.Equal(t, true, result, "Result should return true")
- assert.Equal(t, 1, len(w.stack))
- assert.Equal(t, true, w.descend)
- }
- func TestEmptyStackReturnsFalse(t *testing.T) {
- w := new(Walker)
- w.cur = item{
- path: "/root/",
- err: nil,
- entry: Entry{
- Name: "root",
- Size: 123,
- Time: time.Now(),
- Type: EntryTypeFolder,
- },
- }
- w.stack = []item{}
- w.SkipDir()
- result := w.Step()
- assert.Equal(t, false, result, "Result should return false")
- }
- func TestCurAndStackSetCorrectly(t *testing.T) {
- w := new(Walker)
- w.cur = item{
- path: "root/file1",
- err: nil,
- entry: Entry{
- Name: "file1",
- Size: 123,
- Time: time.Now(),
- Type: EntryTypeFile,
- },
- }
- w.stack = []item{
- item{
- path: "file",
- err: nil,
- entry: Entry{
- Name: "file",
- Size: 123,
- Time: time.Now(),
- Type: EntryTypeFile,
- },
- },
- item{
- path: "root/file1",
- err: nil,
- entry: Entry{
- Name: "file1",
- Size: 123,
- Time: time.Now(),
- Type: EntryTypeFile,
- },
- },
- }
- result := w.Step()
- result = w.Step()
- assert.Equal(t, true, result, "Result should return true")
- assert.Equal(t, 0, len(w.stack))
- assert.Equal(t, "file", w.cur.entry.Name)
- }
- func TestErrorsFromListAreHandledCorrectly(t *testing.T) {
- //Get error
- //Check w.cur.err
- //Check stack
- }
- func TestStackIsPopulatedCorrectly(t *testing.T) {
- //Check things are added to the stack correcty
- }
|