From a6055c7bc8ebe5df2fc8114c78f676eeb2cb9395 Mon Sep 17 00:00:00 2001 From: John Episcopo Date: Thu, 2 May 2019 09:29:41 +0100 Subject: [PATCH] Added further tests --- walker_test.go | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/walker_test.go b/walker_test.go index 1b6fea1..a2f7772 100644 --- a/walker_test.go +++ b/walker_test.go @@ -2,6 +2,7 @@ package ftp import ( "fmt" + "strings" "testing" "time" @@ -66,7 +67,7 @@ func TestNoDescendDoesNotAddToStack(t *testing.T) { result := w.Step() assert.Equal(t, true, result, "Result should return true") - assert.Equal(t, 1, len(w.stack)) + assert.Equal(t, 0, len(w.stack)) assert.Equal(t, true, w.descend) } @@ -136,12 +137,37 @@ func TestCurAndStackSetCorrectly(t *testing.T) { 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 + + mock, err := newFtpMock(t, "127.0.0.1") + if err != nil { + t.Fatal(err) + } + defer mock.Close() + + c, cErr := Connect(mock.Addr()) + if cErr != nil { + t.Fatal(err) + } + + w := Walker{ + cur: item{ + path: "/root", + entry: Entry{ + Name: "root", + Size: 123, + Time: time.Now(), + Type: EntryTypeFolder, + }, + }, + serverConn: c, + } + + w.descend = true + + w.Step() + + assert.Equal(t, 0, len(w.stack)) + assert.Equal(t, "lo", w.cur.entry.Name) + assert.Equal(t, true, strings.HasSuffix(w.cur.path, "/")) }