Skip to content

Commit

Permalink
Feat: Render testruns data as json instead of html for fern-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
grajeshshekaran authored and gowtham-ra committed May 20, 2024
1 parent 8e063e9 commit 6340b75
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ Fern is a Golang Gin-based API that connects to a PostgreSQL database. It is des

### Accessing Test Reports

- View reports at `http://[your-api-url]/reports/testruns`.
- If using `make docker-run`, reports are available at `http://localhost:8080/reports/testruns`.
To view the test reports, you can use the Fern-UI frontend,
which provides a visual dashboard for the test results.

- 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 set up, access the dashboard at `http://[frontend-api-url]/reports/testruns` to view the test reports.
- If using `make docker-run`, reports are also available at `http://localhost:8080/reports/testruns`.

### Additional Resources

Expand Down
23 changes: 1 addition & 22 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"html/template"
"log"

"github.com/guidewire/fern-reporter/config"
Expand All @@ -10,15 +9,10 @@ import (

"time"

"embed"

"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)

//go:embed pkg/views/test_runs.html
var testRunsTemplate embed.FS

func main() {
initConfig()
initDb()
Expand Down Expand Up @@ -47,24 +41,9 @@ func initServer() {
MaxAge: 12 * time.Hour,
}))

funcMap := template.FuncMap{
"CalculateDuration": CalculateDuration,
}
templ, err := template.New("").Funcs(funcMap).ParseFS(testRunsTemplate, "pkg/views/test_runs.html")
if err != nil {
log.Fatalf("error parsing templates: %v", err)
}
router.SetHTMLTemplate(templ)

// router.LoadHTMLGlob("pkg/views/*")
routers.RegisterRouters(router)
err = router.Run(serverConfig.Port)
err := router.Run(serverConfig.Port)
if err != nil {
log.Fatalf("error starting routes: %v", err)
}
}

func CalculateDuration(start, end time.Time) string {
duration := end.Sub(start)
return duration.String() // or format as needed
}
11 changes: 7 additions & 4 deletions pkg/api/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,22 @@ 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.HTML(http.StatusOK, "test_runs.html", gin.H{

c.JSON(http.StatusOK, gin.H{
"testRuns": testRuns,
"reportHeader": config.GetHeaderName(),
"testRuns": testRuns,
"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.HTML(http.StatusOK, "test_runs.html", gin.H{

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

Expand Down

0 comments on commit 6340b75

Please sign in to comment.