From c05cad9c1dd33c61a7ba79476a5f373ea482398a Mon Sep 17 00:00:00 2001 From: Kai Lee Date: Mon, 13 May 2024 23:05:30 -0700 Subject: [PATCH] Fix: Modify the static header to be dynamically set --- config/config.go | 8 ++++++++ config/config.yaml | 1 + config/config_test.go | 3 +++ pkg/api/handlers/handlers.go | 7 +++++-- pkg/views/test_runs.html | 4 ++-- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index 7d17462..2101541 100644 --- a/config/config.go +++ b/config/config.go @@ -12,6 +12,7 @@ import ( type config struct { Db *dbConfig Server *serverConfig + Header string } type dbConfig struct { @@ -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 } @@ -80,3 +84,7 @@ func GetDb() *dbConfig { func GetServer() *serverConfig { return configuration.Server } + +func GetHeaderName() string { + return configuration.Header +} diff --git a/config/config.yaml b/config/config.yaml index 4b6feb8..0ac848f 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -10,3 +10,4 @@ db: max-idle-conns: 10 server: port: :8080 +header: "Fern Acceptance Test Report" \ No newline at end of file diff --git a/config/config_test.go b/config/config_test.go index 8c78f54..33bc05d 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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() { @@ -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() @@ -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")) }) }) diff --git a/pkg/api/handlers/handlers.go b/pkg/api/handlers/handlers.go index 6834db7..485aaa6 100644 --- a/pkg/api/handlers/handlers.go +++ b/pkg/api/handlers/handlers.go @@ -3,6 +3,7 @@ package handlers import ( "errors" "fmt" + "github.com/guidewire/fern-reporter/config" "log" "net/http" "strconv" @@ -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, }) } @@ -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}, }) } diff --git a/pkg/views/test_runs.html b/pkg/views/test_runs.html index e894cb7..1543131 100644 --- a/pkg/views/test_runs.html +++ b/pkg/views/test_runs.html @@ -3,7 +3,7 @@ - ATMOS Acceptance Tests + {{ .reportHeader }}