From f31b2fb74f510fd6ce1b610dcd5f942847d718a2 Mon Sep 17 00:00:00 2001 From: boyska Date: Thu, 8 Nov 2018 19:49:29 +0100 Subject: [PATCH] refactor unit test --- hub_test.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/hub_test.go b/hub_test.go index cc90a84..457ddb2 100644 --- a/hub_test.go +++ b/hub_test.go @@ -11,19 +11,14 @@ func msg(s string) format.LogParts { } func hubCount(h Hub) int { - cl := Client{Options: ClientOptions{Nofollow: true, BacklogLength: -1}} - cl.Messages = make(chan format.LogParts) - h.Register <- cl - cnt := 0 - for range cl.Messages { - cnt++ - } - return cnt + return len(hubToArray(h)) } -func hubToArray(h Hub) []string { +var DefaultClient ClientOptions = ClientOptions{Nofollow: true, BacklogLength: -1} + +func hubToArrayOpt(h Hub, opt ClientOptions) []string { r := make([]string, 0) - cl := Client{Options: ClientOptions{Nofollow: true, BacklogLength: -1}} + cl := Client{Options: opt} cl.Messages = make(chan format.LogParts) h.Register <- cl for m := range cl.Messages { @@ -31,6 +26,9 @@ func hubToArray(h Hub) []string { } return r } +func hubToArray(h Hub) []string { + return hubToArrayOpt(h, DefaultClient) +} func TestSingle(t *testing.T) { h := NewHub(5)