Skip to content

Commit

Permalink
Merge pull request #2 from jlaffaye/master
Browse files Browse the repository at this point in the history
Test PR
  • Loading branch information
rafael84 authored Jan 18, 2018
2 parents 4c3ab0c + 83891db commit b2bb3d0
Show file tree
Hide file tree
Showing 10 changed files with 543 additions and 98 deletions.
19 changes: 11 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
language: go
dist: trusty
sudo: required
go:
- 1.7.3
- 1.7.5
- 1.8.1
env:
- FTP_SERVER=vsftpd
- FTP_SERVER=proftpd
before_install:
- sudo mkdir --mode 0777 -p /var/ftp/incoming
- sudo apt-get update -qq
- sudo apt-get install -qq vsftpd
- sudo cp $TRAVIS_BUILD_DIR/.vsftpd.conf /etc/vsftpd.conf
- sudo service vsftpd restart
- sudo $TRAVIS_BUILD_DIR/.travis/prepare.sh "$FTP_SERVER"
- sudo sysctl net.ipv6.conf.lo.disable_ipv6=0
- go get github.com/axw/gocov/gocov
- go get github.com/mattn/goveralls
- go get github.com/golang/lint/golint
script:
- $GOPATH/bin/goveralls -service=travis-ci
- goveralls -v
- golint -set_exit_status $(go list ./...)
18 changes: 18 additions & 0 deletions .travis/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh -e

case "$1" in
proftpd)
mkdir -p /etc/proftpd/conf.d/
cp $TRAVIS_BUILD_DIR/.travis/proftpd.conf /etc/proftpd/conf.d/
;;
vsftpd)
cp $TRAVIS_BUILD_DIR/.travis/vsftpd.conf /etc/vsftpd.conf
;;
*)
echo "unknown software: $1"
exit 1
esac

mkdir --mode 0777 -p /var/ftp/incoming

apt-get install -qq "$1"
9 changes: 9 additions & 0 deletions .travis/proftpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Anonymous /var/ftp>
User ftp
Group nogroup
MaxClients 2
# We want clients to be able to login with "anonymous" as well as "ftp"
UserAlias anonymous ftp

RequireValidShell off
</Anonymous>
File renamed without changes.
236 changes: 235 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"io/ioutil"
"net/textproto"
"strings"
"testing"
"time"
)
Expand Down Expand Up @@ -33,7 +34,7 @@ func testConn(t *testing.T, disableEPSV bool) {

if disableEPSV {
delete(c.features, "EPSV")
c.disableEPSV = true
c.DisableEPSV = true
}

err = c.Login("anonymous", "anonymous")
Expand Down Expand Up @@ -67,6 +68,7 @@ func testConn(t *testing.T, disableEPSV bool) {
t.Error(err)
}

// Read without deadline
r, err := c.Retr("tset")
if err != nil {
t.Error(err)
Expand All @@ -79,8 +81,25 @@ func testConn(t *testing.T, disableEPSV bool) {
t.Errorf("'%s'", buf)
}
r.Close()
r.Close() // test we can close two times
}

// Read with deadline
r, err = c.Retr("tset")
if err != nil {
t.Error(err)
} else {
r.SetDeadline(time.Now())
_, err := ioutil.ReadAll(r)
if err == nil {
t.Error("deadline should have caused error")
} else if !strings.HasSuffix(err.Error(), "i/o timeout") {
t.Error(err)
}
r.Close()
}

// Read with offset
r, err = c.RetrFrom("tset", 5)
if err != nil {
t.Error(err)
Expand All @@ -96,6 +115,33 @@ func testConn(t *testing.T, disableEPSV bool) {
r.Close()
}

fileSize, err := c.FileSize("tset")
if err != nil {
t.Error(err)
}
if fileSize != 14 {
t.Errorf("file size %q, expected %q", fileSize, 14)
}

data = bytes.NewBufferString("")
err = c.Stor("tset", data)
if err != nil {
t.Error(err)
}

fileSize, err = c.FileSize("tset")
if err != nil {
t.Error(err)
}
if fileSize != 0 {
t.Errorf("file size %q, expected %q", fileSize, 0)
}

_, err = c.FileSize("not-found")
if err == nil {
t.Fatal("expected error, got nil")
}

err = c.Delete("tset")
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -222,3 +268,191 @@ func TestWrongLogin(t *testing.T) {
t.Fatal("expected error, got nil")
}
}

func TestDeleteDirRecur(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
c, err := DialTimeout("localhost:21", 5*time.Second)
if err != nil {
t.Fatal(err)
}

err = c.Login("anonymous", "anonymous")
if err != nil {
t.Fatal(err)
}

err = c.NoOp()
if err != nil {
t.Error(err)
}

err = c.ChangeDir("incoming")
if err != nil {
t.Error(err)
}

err = c.MakeDir("testDir")
if err != nil {
t.Error(err)
}

err = c.ChangeDir("testDir")
if err != nil {
t.Error(err)
}

err = c.MakeDir("anotherDir")
if err != nil {
t.Error(err)
}

data := bytes.NewBufferString("test text")
err = c.Stor("fileTest", data)
if err != nil {
t.Error(err)
}

err = c.ChangeDirToParent()
if err != nil {
t.Error(err)
}
err = c.RemoveDirRecur("testDir")
if err != nil {
t.Error(err)
}
dir, err := c.CurrentDir()
if err != nil {
t.Error(err)
} else {
if dir != "/incoming" {
t.Error("Wrong dir: " + dir)
}
}

err = c.ChangeDir("testDir")
if err == nil {
t.Fatal("expected error, got nil")
}

err = c.Logout()
if err != nil {
if protoErr := err.(*textproto.Error); protoErr != nil {
if protoErr.Code != StatusNotImplemented {
t.Error(err)
}
} else {
t.Error(err)
}
}

c.Quit()
}

func TestFileDeleteDirRecur(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}

c, err := DialTimeout("localhost:21", 5*time.Second)
if err != nil {
t.Fatal(err)
}

err = c.Login("anonymous", "anonymous")
if err != nil {
t.Fatal(err)
}

err = c.ChangeDir("incoming")
if err != nil {
t.Error(err)
}

data := bytes.NewBufferString(testData)
err = c.Stor("testFile", data)
if err != nil {
t.Error(err)
}

err = c.RemoveDirRecur("testFile")
if err == nil {
t.Fatal("expected error got nill")
}

dir, err := c.CurrentDir()
if err != nil {
t.Error(err)
} else {
if dir != "/incoming" {
t.Error("Wrong dir: " + dir)
}
}

err = c.Delete("testFile")
if err != nil {
t.Error(err)
}

err = c.Logout()
if err != nil {
if protoErr := err.(*textproto.Error); protoErr != nil {
if protoErr.Code != StatusNotImplemented {
t.Error(err)
}
} else {
t.Error(err)
}
}

c.Quit()
}

func TestMissingFolderDeleteDirRecur(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}

c, err := DialTimeout("localhost:21", 5*time.Second)
if err != nil {
t.Fatal(err)
}

err = c.Login("anonymous", "anonymous")
if err != nil {
t.Fatal(err)
}

err = c.ChangeDir("incoming")
if err != nil {
t.Error(err)
}

err = c.RemoveDirRecur("test")
if err == nil {
t.Fatal("expected error got nill")
}

dir, err := c.CurrentDir()
if err != nil {
t.Error(err)
} else {
if dir != "/incoming" {
t.Error("Wrong dir: " + dir)
}
}

err = c.Logout()
if err != nil {
if protoErr := err.(*textproto.Error); protoErr != nil {
if protoErr.Code != StatusNotImplemented {
t.Error(err)
}
} else {
t.Error(err)
}
}

c.Quit()
}
Loading

0 comments on commit b2bb3d0

Please sign in to comment.