Skip to content

Commit

Permalink
Feat: Add endpoint and unit test to ping for the status of Fern Repor…
Browse files Browse the repository at this point in the history
…ter (#63)

* Feat: Add endpoint and unit test to ping for the status of Fern Reporter

* chore: Updated coverage badge.

---------

Co-authored-by: Kai Lee <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
3 people authored Apr 19, 2024
1 parent e63beef commit c49b62c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/Guidewire/fern-reporter/badge)](https://securityscorecards.dev/viewer/?uri=github.com/Guidewire/fern-reporter)
![Coverage](https://img.shields.io/badge/Coverage-73.2%25-brightgreen)
![Coverage](https://img.shields.io/badge/Coverage-73.9%25-brightgreen)

![Fern](https://github.com/guidewire/fern-reporter/raw/main/docs/images/logo-no-background.png)

Expand Down
6 changes: 6 additions & 0 deletions pkg/api/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,9 @@ func (h *Handler) ReportTestRunById(c *gin.Context) {
"testRuns": []models.TestRun{testRun},
})
}

func (h *Handler) Ping(c *gin.Context) {
c.JSON(200, gin.H{
"message": "Fern Reporter is running!",
})
}
18 changes: 18 additions & 0 deletions pkg/api/handlers/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,24 @@ var _ = Describe("Handlers", func() {
Expect(w.Code).To((Equal(http.StatusNotFound)))

})
})

Context("When Ping handler is invoked", func() {
It("it should return an HTTP status code of 200, indicating that the 'Fern Reporter' service is operational", func() {
gin.SetMode(gin.TestMode)

w := httptest.NewRecorder()
c, r := gin.CreateTestContext(w)

handler := handlers.NewHandler(gormDb)
r.GET("/ping", handler.Ping)
c.Request, _ = http.NewRequest(http.MethodGet, "/ping", nil)
r.ServeHTTP(w, c.Request)

Expect(w.Code).To(Equal(http.StatusOK))
expectedBody := `{"message":"Fern Reporter is running!"}`
Expect(w.Body.String()).To(Equal(expectedBody))
})

})

Expand Down
4 changes: 4 additions & 0 deletions pkg/api/routers/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ func RegisterRouters(router *gin.Engine) {
testRunReport := reports.GET("/", handler.ReportTestRunAll)
testRunReport.GET("/:id", handler.ReportTestRunById)
}
ping := router.Group("/ping")
{
ping.GET("/", handler.Ping)
}
}

0 comments on commit c49b62c

Please sign in to comment.