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

Fix: Modify the static header to be dynamically set #68

Merged
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
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type config struct {
Db *dbConfig
Server *serverConfig
Header string
}

type dbConfig struct {
Expand Down Expand Up @@ -69,6 +70,9 @@ func LoadConfig() (*config, error) {
if os.Getenv("FERN_DATABASE") != "" {
configuration.Db.Database = os.Getenv("FERN_DATABASE")
}
if os.Getenv("FERN_HEADER_NAME") != "" {
configuration.Header = os.Getenv("FERN_HEADER_NAME")
}

return configuration, nil
}
Expand All @@ -80,3 +84,7 @@ func GetDb() *dbConfig {
func GetServer() *serverConfig {
return configuration.Server
}

func GetHeaderName() string {
return configuration.Header
}
1 change: 1 addition & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ db:
max-idle-conns: 10
server:
port: :8080
header: "Fern Acceptance Test Report"
3 changes: 3 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var _ = Describe("When LoadConfig is invoked", func() {
Expect(appConfig.Db.DetailLog).To(BeTrue())
Expect(appConfig.Db.MaxOpenConns).To(Equal(100))
Expect(appConfig.Db.MaxIdleConns).To(Equal(10))
Expect(appConfig.Header).To(Equal("Fern Acceptance Test Report"))
})

It("should get non-nil DB", func() {
Expand Down Expand Up @@ -63,6 +64,7 @@ var _ = Describe("When LoadConfig is invoked", func() {
os.Setenv("FERN_HOST", "localhost")
os.Setenv("FERN_PORT", "5432")
os.Setenv("FERN_DATABASE", "fern")
os.Setenv("FERN_HEADER_NAME", "Custom Fern Report Header")

//v := viper.New()
result, err := config.LoadConfig()
Expand All @@ -74,6 +76,7 @@ var _ = Describe("When LoadConfig is invoked", func() {
Expect(result.Db.Host).To(Equal("localhost"))
Expect(result.Db.Port).To(Equal("5432"))
Expect(result.Db.Database).To(Equal("fern"))
Expect(result.Header).To(Equal("Custom Fern Report Header"))
})

})
7 changes: 5 additions & 2 deletions pkg/api/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handlers
import (
"errors"
"fmt"
"github.com/guidewire/fern-reporter/config"
"log"
"net/http"
"strconv"
Expand Down Expand Up @@ -149,7 +150,8 @@ 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{
"testRuns": testRuns,
"reportHeader": config.GetHeaderName(),
"testRuns": testRuns,
})
}

Expand All @@ -158,7 +160,8 @@ func (h *Handler) ReportTestRunById(c *gin.Context) {
id := c.Param("id")
h.db.Preload("SuiteRuns.SpecRuns").Where("id = ?", id).First(&testRun)
c.HTML(http.StatusOK, "test_runs.html", gin.H{
"testRuns": []models.TestRun{testRun},
"reportHeader": config.GetHeaderName(),
"testRuns": []models.TestRun{testRun},
})
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/views/test_runs.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ATMOS Acceptance Tests</title>
<title>{{ .reportHeader }}</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
<style>
body {
Expand Down Expand Up @@ -66,7 +66,7 @@
</head>
<body>
<div class="container">
<h1 class="title is-3 has-text-centered has-background-primary has-text-white p-4">ATMOS Acceptance Tests</h1>
<h1 class="title is-3 has-text-centered has-background-primary has-text-white p-4">{{ .reportHeader }}</h1>
<div>
<table style="width: 100%;">
<tr>
Expand Down
Loading