Better error handling, new commands.
The code is no safer. Added Stor(), Rename(), NoOp() Improved Retr() Added client tests (requires a ftp server on localhost)
This commit is contained in:
55
client_test.go
Normal file
55
client_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package ftp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const (
|
||||
testData = "Just some text"
|
||||
)
|
||||
|
||||
func TestConn(t *testing.T) {
|
||||
c, err := ConnectAnonymous("localhost:21")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = c.NoOp()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
data := bytes.NewBufferString(testData)
|
||||
err = c.Stor("test", data)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = c.List(".")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = c.Rename("test", "tset")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
r, err := c.Retr("tset")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
buf, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if string(buf) != testData {
|
||||
t.Errorf("'%s'", buf)
|
||||
}
|
||||
r.Close()
|
||||
}
|
||||
|
||||
c.Quit()
|
||||
}
|
||||
Reference in New Issue
Block a user