package main import ( "net/http" "testing" "git.runcible.io/learning/ratchet/internal/assert" ) // func testingLogger() *slog.Logger { // return slog.New(slog.NewTextHandler(io.Discard, nil)) // } // WITHOUT testutils_test.go helpers // func TestPingIntegration(t *testing.T) { // rs := server.NewRatchetApp(testingLogger(), nil, nil, nil) // // We then use the httptest.NewTLSServer() function to create a new test // // server, passing in the value returned by our app.routes() method as the // // handler for the server. This starts up a HTTPS server which listens on a // // randomly-chosen port of your local machine for the duration of the test. // // Notice that we defer a call to ts.Close() so that the server is shutdown // // when the test finishes. // ts := httptest.NewTLSServer(rs) // defer ts.Close() // resp, err := ts.Client().Get(ts.URL + "/ping") // if err != nil { // t.Fatal(err) // } // assert.Equal(t, resp.StatusCode, http.StatusOK) // defer resp.Body.Close() // body, err := io.ReadAll(resp.Body) // if err != nil { // t.Fatal(err) // } // body = bytes.TrimSpace(body) // assert.Equal(t, string(body), "OK") // } func TestPingIntegration(t *testing.T) { // Tests marked using t.Parallel() will be run in parallel with — and only with — other parallel tests. // By default, the maximum number of tests that will be run simultaneously is the current value of // GOMAXPROCS. You can override this by setting a specific value via the -parallel flag. t.Parallel() app := newTestApplication(t) ts := newTestServer(t, app) defer ts.Close() code, _, body := ts.get(t, "/ping") assert.Equal(t, code, http.StatusOK) assert.Equal(t, body, "OK") }