Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add JSON and HTML apis for reports/testruns #69

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,28 @@ 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/`.
- If using `make docker-run-local`, reports are available at `http://localhost:8080/reports/testruns/`.

### Accessing Test Reports using Fern-UI

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]/testruns` to view the test reports.

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

### Accessing Test Reports using the API
Reports are also available as JSON at `http://[host-url]/api/reports/testruns`.

### Additional Resources

- [Deploying fern reporter service in kubernetes using kubevela](docs/kubevela/README.md)
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 @@ -148,13 +148,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 @@ -33,6 +33,10 @@ func RegisterRouters(router *gin.Engine) {
testRun.POST("/", handler.CreateTestRun)
testRun.PUT("/:id", handler.UpdateTestRun)
testRun.DELETE("/:id", handler.DeleteTestRun)

testReport := api.Group("/reports/testruns")
testReport.GET("/", handler.ReportTestRunAll)
testReport.GET("/:id", handler.ReportTestRunById)
}

var reports *gin.RouterGroup
Expand All @@ -44,8 +48,8 @@ func RegisterRouters(router *gin.Engine) {

reports.Use()
{
testRunReport := reports.GET("/", handler.ReportTestRunAll)
testRunReport.GET("/:id", handler.ReportTestRunById)
reports.GET("/", handler.ReportTestRunAllHTML)
reports.GET("/:id", handler.ReportTestRunByIdHTML)
}

var ping *gin.RouterGroup
Expand Down
Loading