Skip to content

Commit

Permalink
Reduce test methods to one per method
Browse files Browse the repository at this point in the history
  • Loading branch information
bahlo committed Sep 2, 2015
1 parent 55c35a7 commit 454a08b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 30 deletions.
2 changes: 0 additions & 2 deletions database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
27 changes: 3 additions & 24 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
Expand All @@ -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},
}
Expand All @@ -49,21 +45,16 @@ 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)
if out != ip {
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 = "["
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
4 changes: 0 additions & 4 deletions signals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 454a08b

Please sign in to comment.