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