a87255661d
The code is no safer. Added Stor(), Rename(), NoOp() Improved Retr() Added client tests (requires a ftp server on localhost)
56 lines
717 B
Go
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()
|
|
}
|