Created
December 9, 2016 16:42
-
-
Save pkieltyka/a4bbf38318b321c3dd21504d26c73821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package middleware | |
import ( | |
"io/ioutil" | |
"net/http" | |
"net/http/httptest" | |
"sync" | |
"testing" | |
"github.com/pressly/chi" | |
) | |
func TestCloseNotify(t *testing.T) { | |
testContent := []byte("hi") | |
r := chi.NewRouter() | |
r.Use(CloseNotify) | |
r.Get("/", func(w http.ResponseWriter, r *http.Request) { | |
w.Write(testContent) | |
}) | |
server := httptest.NewServer(r) | |
var wg sync.WaitGroup | |
for i := 0; i < 50; i++ { | |
wg.Add(1) | |
go func(i int) { | |
defer wg.Done() | |
res, err := http.Get(server.URL) | |
assertNoError(t, err) | |
assertEqual(t, http.StatusOK, res.StatusCode) | |
buf, err := ioutil.ReadAll(res.Body) | |
assertNoError(t, err) | |
assertEqual(t, testContent, buf) | |
}(i) | |
} | |
wg.Wait() | |
server.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment