Skip to content

Commit

Permalink
Feat: Add JSON and HTML apis for reports/testruns
Browse files Browse the repository at this point in the history
  • Loading branch information
gowtham-ra committed Jun 3, 2024
1 parent 8e063e9 commit 9adb9df
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,22 @@ Fern is a Golang Gin-based API that connects to a PostgreSQL database. It is des

### Integrating the Client into Ginkgo Test Suites

Refer the client repository to integrate the client to Ginkgo Test Suites:
* Refer the client repository to integrate the client to Ginkgo Test Suites:
https://github.com/Guidewire/fern-ginkgo-client
* After adding the client, run your Ginkgo tests normally.

2. **Run Your Tests**: After adding the client, run your Ginkgo tests normally.
### Accessing Test Reports using embedded HTML view

### Accessing Test Reports
- View reports at `http://[your-api-url]/reports/testruns/html`.
- If using `make docker-run-local`, reports are available at `http://localhost:8080/reports/testruns/html`.

- View reports at `http://[your-api-url]/reports/testruns`.
- If using `make docker-run`, reports are available at `http://localhost:8080/reports/testruns`.
### Accessing Test Reports using Fern-UI or as JSON

To view the test reports using the React-based Fern-UI frontend, follow these steps:

- Follow the instructions in the [Fern-UI repository](https://github.com/Guidewire/fern-ui) to set up and run the frontend application.
- Once the Fern-UI is running, access the dashboard at `http://[frontend-api-url]/reports/testruns` to view the test reports.
- If using `make docker-run-local`, reports are also available as JSON at `http://localhost:8080/reports/testruns`.

### Additional Resources

Expand Down
24 changes: 23 additions & 1 deletion pkg/api/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,35 @@ func (h *Handler) DeleteTestRun(c *gin.Context) {
func (h *Handler) ReportTestRunAll(c *gin.Context) {
var testRuns []models.TestRun
h.db.Preload("SuiteRuns.SpecRuns.Tags").Find(&testRuns)

c.JSON(http.StatusOK, gin.H{
"testRuns": testRuns,
"reportHeader": config.GetHeaderName(),
"total": len(testRuns),
})
}

func (h *Handler) ReportTestRunById(c *gin.Context) {
var testRun models.TestRun
id := c.Param("id")
h.db.Preload("SuiteRuns.SpecRuns").Where("id = ?", id).First(&testRun)

c.JSON(http.StatusOK, gin.H{
"reportHeader": config.GetHeaderName(),
"testRuns": []models.TestRun{testRun},
})
}

func (h *Handler) ReportTestRunAllHTML(c *gin.Context) {
var testRuns []models.TestRun
h.db.Preload("SuiteRuns.SpecRuns.Tags").Find(&testRuns)
c.HTML(http.StatusOK, "test_runs.html", gin.H{
"reportHeader": config.GetHeaderName(),
"testRuns": testRuns,
})
}

func (h *Handler) ReportTestRunById(c *gin.Context) {
func (h *Handler) ReportTestRunByIdHTML(c *gin.Context) {
var testRun models.TestRun
id := c.Param("id")
h.db.Preload("SuiteRuns.SpecRuns").Where("id = ?", id).First(&testRun)
Expand Down
8 changes: 6 additions & 2 deletions pkg/api/routers/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ func RegisterRouters(router *gin.Engine) {
}
reports := router.Group("/reports/testruns")
{
testRunReport := reports.GET("/", handler.ReportTestRunAll)
testRunReport.GET("/:id", handler.ReportTestRunById)
reports.GET("/", handler.ReportTestRunAll)
reports.GET("/:id", handler.ReportTestRunById)

reports.GET("/html", handler.ReportTestRunAllHTML)
reports.GET("/html/:id", handler.ReportTestRunByIdHTML)

}
ping := router.Group("/ping")
{
Expand Down

0 comments on commit 9adb9df

Please sign in to comment.