Improve test suite by using github.com/stretchr/testify

This commit is contained in:
James Mills 2016-09-16 22:15:34 +10:00
parent 8e4cb6a448
commit a3a5405144
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6
1 changed files with 9 additions and 25 deletions

View File

@ -7,6 +7,7 @@ import (
"testing"
"github.com/prologic/go-gopher"
"github.com/stretchr/testify/assert"
)
func hello(w gopher.ResponseWriter, r *gopher.Request) {
@ -32,44 +33,27 @@ func Example_fileserver() {
}
func TestGet(t *testing.T) {
assert := assert.New(t)
res, err := gopher.Get("gopher://localhost:7000/1hello")
if err != nil {
t.Fatal(err)
}
assert.Nil(err)
b, err := res.Dir.ToText()
if err != nil {
t.Fatal(err)
}
assert.Nil(err)
t.Logf("res: %s", string(b))
if len(res.Dir) == 0 {
t.Fatal("expected items but none found")
}
assert.Len(res.Dir, 1)
i := res.Dir[0]
if i.Type != gopher.INFO {
log.Fatalf("expected INFO item %s found", i.Type)
}
if i.Description != "Hello World!" {
log.Fatal("expected \"Hello World!\" as description")
}
assert.Equal(res.Dir[0].Type, gopher.INFO)
assert.Equal(res.Dir[0].Description, "Hello World!")
}
func TestMain(m *testing.M) {
log.Print("Setup...")
gopher.HandleFunc("/hello", hello)
go func() {
log.Fatal(gopher.ListenAndServe("localhost:7000", nil))
}()
retcode := m.Run()
log.Printf(" Return: %q", retcode)
log.Print("Teardown...")
os.Exit(retcode)
os.Exit(m.Run())
}