From fa09d1002b22b74abcf2a937745c44f0b8bee91b Mon Sep 17 00:00:00 2001 From: James Mills Date: Wed, 14 Sep 2016 16:42:30 +1000 Subject: [PATCH] Added a simple integration test --- gopher_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/gopher_test.go b/gopher_test.go index b105c7a..068afab 100644 --- a/gopher_test.go +++ b/gopher_test.go @@ -3,6 +3,8 @@ package gopher_test import ( "fmt" "log" + "os" + "testing" "github.com/prologic/go-gopher" ) @@ -28,3 +30,46 @@ func Example_fileserver() { gopher.Handle("/", gopher.FileServer(gopher.Dir("/tmp"))) log.Fatal(gopher.ListenAndServe("localhost:7000", nil)) } + +func TestGet(t *testing.T) { + res, err := gopher.Get("gopher://localhost:7000/1hello") + if err != nil { + t.Fatal(err) + } + + b, err := res.Dir.ToText() + if err != nil { + t.Fatal(err) + } + + t.Logf("res: %s", string(b)) + + if len(res.Dir) == 0 { + t.Fatal("expected items but none found") + } + + 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") + } +} + +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) +}