From a3a54051442ae6545096ae8e438589ed70c61148 Mon Sep 17 00:00:00 2001 From: James Mills Date: Fri, 16 Sep 2016 22:15:34 +1000 Subject: [PATCH] Improve test suite by using github.com/stretchr/testify --- gopher_test.go | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/gopher_test.go b/gopher_test.go index 068afab..e63acee 100644 --- a/gopher_test.go +++ b/gopher_test.go @@ -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()) }