Update for healthcheck and dev env
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
1d3c1de858
commit
598cf87ca8
@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHealthRoute(t *testing.T) {
|
||||
respRec := httptest.NewRecorder()
|
||||
|
||||
r, err := http.NewRequest(http.MethodGet, "/v1/healthcheck", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg := config{env: "test"}
|
||||
|
||||
app := application{config: cfg, logger: slog.New(slog.NewTextHandler(io.Discard, nil))}
|
||||
|
||||
health := http.HandlerFunc(app.HealthCheckHandler)
|
||||
health.ServeHTTP(respRec, r)
|
||||
|
||||
resp := respRec.Result()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("Got status code %q, wanted status code %q", resp.StatusCode, http.StatusOK)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
body = bytes.TrimSpace(body)
|
||||
|
||||
if !strings.Contains(string(body), "environment: test") {
|
||||
t.Fatalf("Did not find: %q in response body", "environment: test")
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRun(t *testing.T) {
|
||||
// buffer := bytes.Buffer{}
|
||||
// run(&buffer)
|
||||
// got := buffer.String()
|
||||
// want := "Hello API\n"
|
||||
// if got != want {
|
||||
// t.Errorf("got %q, want %q", got, want)
|
||||
// }
|
||||
}
|
Loading…
Reference in New Issue