@@ -3,6 +3,7 @@ package geoblock_test
33import (
44 "context"
55 "fmt"
6+ "io"
67 "net/http"
78 "net/http/httptest"
89 "os"
@@ -106,7 +107,7 @@ func TestAllowedCountry(t *testing.T) {
106107 cfg .Countries = append (cfg .Countries , "CH" )
107108
108109 ctx := context .Background ()
109- next := http .HandlerFunc (func (_ http.ResponseWriter , _ * http.Request ) {})
110+ next := http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) { _ , _ = w . Write ([] byte ( "Allowed request" )) })
110111
111112 handler , err := geoblock .New (ctx , next , cfg , "GeoBlock" )
112113 if err != nil {
@@ -124,7 +125,19 @@ func TestAllowedCountry(t *testing.T) {
124125
125126 handler .ServeHTTP (recorder , req )
126127
127- assertStatusCode (t , recorder .Result (), http .StatusOK )
128+ recorderResult := recorder .Result ()
129+
130+ assertStatusCode (t , recorderResult , http .StatusOK )
131+
132+ body , err := io .ReadAll (recorderResult .Body )
133+ if err != nil {
134+ t .Fatal (err )
135+ }
136+
137+ expectedBody := "Allowed request"
138+ if string (body ) != expectedBody {
139+ t .Fatalf ("expected body %q, got %q" , expectedBody , string (body ))
140+ }
128141}
129142
130143func TestMultipleAllowedCountry (t * testing.T ) {
@@ -385,7 +398,7 @@ func TestDeniedCountry(t *testing.T) {
385398 cfg .Countries = append (cfg .Countries , "CH" )
386399
387400 ctx := context .Background ()
388- next := http .HandlerFunc (func (_ http.ResponseWriter , _ * http.Request ) {})
401+ next := http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) { _ , _ = w . Write ([] byte ( "Allowed request" )) })
389402
390403 handler , err := geoblock .New (ctx , next , cfg , "GeoBlock" )
391404 if err != nil {
@@ -403,7 +416,19 @@ func TestDeniedCountry(t *testing.T) {
403416
404417 handler .ServeHTTP (recorder , req )
405418
406- assertStatusCode (t , recorder .Result (), http .StatusForbidden )
419+ recorderResult := recorder .Result ()
420+
421+ assertStatusCode (t , recorderResult , http .StatusForbidden )
422+
423+ body , err := io .ReadAll (recorderResult .Body )
424+ if err != nil {
425+ t .Fatal (err )
426+ }
427+
428+ expectedBody := ""
429+ if string (body ) != expectedBody {
430+ t .Fatalf ("expected body %q, got %q" , expectedBody , string (body ))
431+ }
407432}
408433
409434func TestDeniedCountryWithRedirect (t * testing.T ) {
0 commit comments