From 454a08b7d56378aee3edf333f6d6315d2499e3bb Mon Sep 17 00:00:00 2001 From: Arne Bahlo Date: Wed, 2 Sep 2015 14:06:42 +0200 Subject: [PATCH] Reduce test methods to one per method --- database_test.go | 2 -- http_test.go | 27 +++------------------------ signals_test.go | 4 ---- 3 files changed, 3 insertions(+), 30 deletions(-) diff --git a/database_test.go b/database_test.go index cbe48f8..a745c07 100644 --- a/database_test.go +++ b/database_test.go @@ -36,9 +36,7 @@ func TestRollbackErr(t *testing.T) { t.Errorf("Expected RollbackErr to return %v, but got %v", alt, err) } }) -} -func TestRollbackErrFailing(t *testing.T) { mockDBContext(t, func(db *sql.DB, mock sqlmock.Sqlmock) { rberr := errors.New("Some rollback error") diff --git a/http_test.go b/http_test.go index ce4803b..47ea440 100644 --- a/http_test.go +++ b/http_test.go @@ -22,9 +22,9 @@ func mockRequestContext(t *testing.T, fn func(*http.Request)) { } func TestRemoteIP(t *testing.T) { - mockRequestContext(t, func(r *http.Request) { - ip := "123.456.7.8" + ip := "123.456.7.8" + mockRequestContext(t, func(r *http.Request) { r.Header = http.Header{ "X-Real-Ip": []string{ip}, } @@ -34,12 +34,8 @@ func TestRemoteIP(t *testing.T) { t.Errorf("Expected %s, but got %s", ip, out) } }) -} -func TestRemoteIPForwardedFor(t *testing.T) { mockRequestContext(t, func(r *http.Request) { - ip := "123.456.7.8" - r.Header = http.Header{ "X-Forwarded-For": []string{ip}, } @@ -49,11 +45,8 @@ func TestRemoteIPForwardedFor(t *testing.T) { t.Errorf("Expected %s, but got %s", ip, out) } }) -} -func TestRemoteIPRemoteAddr(t *testing.T) { mockRequestContext(t, func(r *http.Request) { - ip := "123.456.7.8" r.RemoteAddr = ip out := RemoteIP(r) @@ -61,9 +54,7 @@ func TestRemoteIPRemoteAddr(t *testing.T) { t.Errorf("Expected %s, but got %s", ip, out) } }) -} -func TestRemoteIPLocalhost(t *testing.T) { mockRequestContext(t, func(r *http.Request) { ip := "127.0.0.1" r.RemoteAddr = "[" @@ -104,7 +95,7 @@ func gracefulServerContext(t *testing.T, fn func(*GracefulServer)) { fn(NewGracefulServer(p, h)) } -func TestNewGracefulServer(t *testing.T) { +func TestGracefulServer(t *testing.T) { gracefulServerContext(t, func(s *GracefulServer) { if s.Server.NoSignalHandling != true { t.Error("NoSignalHandling should be true") @@ -114,9 +105,7 @@ func TestNewGracefulServer(t *testing.T) { t.Error("Didn't set the port correctly") } }) -} -func TestGracefulServerStopped(t *testing.T) { gracefulServerContext(t, func(s *GracefulServer) { if !s.Stopped() { t.Error("Stopped returned false, but shouldn't") @@ -128,9 +117,7 @@ func TestGracefulServerStopped(t *testing.T) { t.Error("Stopped returned true, but shouldn't") } }) -} -func TestGracefulServerStop(t *testing.T) { gracefulServerContext(t, func(s *GracefulServer) { time.AfterFunc(20*time.Millisecond, func() { s.Stop(0) @@ -141,9 +128,7 @@ func TestGracefulServerStop(t *testing.T) { t.Error("Stopped returned false after Stop()") } }) -} -func TestGracefulServerListenAndServe(t *testing.T) { gracefulServerContext(t, func(s *GracefulServer) { time.AfterFunc(20*time.Millisecond, func() { if s.Stopped() { @@ -155,9 +140,7 @@ func TestGracefulServerListenAndServe(t *testing.T) { s.ListenAndServe() }) -} -func TestGracefulServerListenAndServeTLS(t *testing.T) { gracefulServerContext(t, func(s *GracefulServer) { time.AfterFunc(20*time.Millisecond, func() { if s.Stopped() { @@ -169,9 +152,7 @@ func TestGracefulServerListenAndServeTLS(t *testing.T) { s.ListenAndServeTLS("foo", "bar") }) -} -func TestGracefulServerListenAndServeTLSConfig(t *testing.T) { gracefulServerContext(t, func(s *GracefulServer) { time.AfterFunc(20*time.Millisecond, func() { if s.Stopped() { @@ -183,9 +164,7 @@ func TestGracefulServerListenAndServeTLSConfig(t *testing.T) { s.ListenAndServeTLSConfig(&tls.Config{}) }) -} -func TestGracefulServerServe(t *testing.T) { gracefulServerContext(t, func(s *GracefulServer) { time.AfterFunc(20*time.Millisecond, func() { if s.Stopped() { diff --git a/signals_test.go b/signals_test.go index 8d0a187..fbb71b3 100644 --- a/signals_test.go +++ b/signals_test.go @@ -27,10 +27,6 @@ func TestOnSignal(t *testing.T) { <-done } -func TestOnSignalNoChannel(t *testing.T) { - go OnSignal(func(s os.Signal) {}) -} - func ExampleOnSignal() { done := make(chan bool)