diff options
Diffstat (limited to 'lilin_test.go')
| -rw-r--r-- | lilin_test.go | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/lilin_test.go b/lilin_test.go index ba1c069..fe951a0 100644 --- a/lilin_test.go +++ b/lilin_test.go @@ -12,17 +12,27 @@ import ( "time" "git.sr.ht/~shulhan/lilin" + "git.sr.ht/~shulhan/lilin/internal" "git.sr.ht/~shulhan/pakakeh.go/lib/net" "git.sr.ht/~shulhan/pakakeh.go/lib/test" ) var client *lilin.Client +const ( + dummyHTTPAddress = `127.0.0.1:6330` +) + func TestMain(m *testing.M) { + internal.Now = func() time.Time { + return time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC) + } + var server *lilin.Server server = startServer() client = createClient(server) + go dummyHTTPService() m.Run() @@ -75,6 +85,26 @@ func createClient(server *lilin.Server) (client *lilin.Client) { return client } +func dummyHTTPService() { + var mux = http.NewServeMux() + + mux.HandleFunc(`GET /health`, func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + var httpd = http.Server{ + Addr: dummyHTTPAddress, + Handler: mux, + ReadTimeout: 5 * time.Second, + WriteTimeout: 5 * time.Second, + } + + var err = httpd.ListenAndServe() + if err != nil { + log.Fatal(err) + } +} + func TestServer_handleServicesSummary(t *testing.T) { var gotSummary []lilin.Service var err error @@ -84,22 +114,6 @@ func TestServer_handleServicesSummary(t *testing.T) { t.Fatal(err) } - var expSummary = []lilin.Service{{ - Name: `example http`, - Type: `http`, - Method: `GET`, - Address: `http://127.0.0.1:6121/health`, - Timeout: `5s`, - }, { - Name: `example tcp`, - Type: `tcp`, - Address: `127.0.0.1:6122`, - Timeout: `5s`, - }, { - Name: `example udp`, - Type: `udp`, - Address: `127.0.0.1:6123`, - Timeout: `5s`, - }} + var expSummary = []lilin.Service{{}, {}, {}} test.Assert(t, `ServicesSummary`, expSummary, gotSummary) } |
