ftp/client_test.go
jlaffaye a87255661d 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)
2011-09-05 23:36:14 +02:00

56 lines
717 B
Go

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()
}