Stamp the build version into the binary (closes #253)
All checks were successful
check / check (push) Successful in 3m12s
All checks were successful
check / check (push) Successful in 3m12s
This commit was merged in pull request #260.
This commit is contained in:
38
internal/handlers/footer_version_test.go
Normal file
38
internal/handlers/footer_version_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package handlers_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sneak.berlin/go/webhooker/internal/globals"
|
||||
"sneak.berlin/go/webhooker/internal/handlers"
|
||||
"sneak.berlin/go/webhooker/internal/session"
|
||||
)
|
||||
|
||||
// The footer in base.html falls back to the literal "dev" when the
|
||||
// template data carries no version, which is what every page rendered
|
||||
// while nothing supplied one. The operator uses the footer to tell
|
||||
// which build is live, so it has to carry the stamped value.
|
||||
func TestFooterReportsStampedVersion(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var (
|
||||
h *handlers.Handlers
|
||||
sess *session.Session
|
||||
g *globals.Globals
|
||||
)
|
||||
|
||||
app := newTestApp(t, &h, &sess, &g)
|
||||
app.RequireStart()
|
||||
|
||||
t.Cleanup(app.RequireStop)
|
||||
|
||||
g.Version = "v9.9.9-test"
|
||||
|
||||
html := renderPage(t, h, sess, "login.html", map[string]any{
|
||||
dataKeyError: "",
|
||||
})
|
||||
|
||||
assert.Contains(t, html, "<span>v9.9.9-test</span>")
|
||||
assert.NotContains(t, html, "<span>dev</span>")
|
||||
}
|
||||
@@ -184,6 +184,7 @@ type UserInfo struct {
|
||||
type templateDataWrapper struct {
|
||||
User *UserInfo
|
||||
CSRFToken string
|
||||
Version string
|
||||
Data any
|
||||
}
|
||||
|
||||
@@ -234,9 +235,16 @@ func (s *Handlers) renderTemplate(
|
||||
userInfo := s.getUserInfo(r)
|
||||
csrfToken := middleware.CSRFToken(r)
|
||||
|
||||
// The footer in base.html renders .Version. Every page reaches it
|
||||
// through here, so this is the one place that has to supply it;
|
||||
// left unset, the footer falls back to its literal "dev" and the
|
||||
// UI reports a build that is not the one running.
|
||||
version := s.params.Globals.Version
|
||||
|
||||
if m, ok := data.(map[string]any); ok {
|
||||
m["User"] = userInfo
|
||||
m["CSRFToken"] = csrfToken
|
||||
m["Version"] = version
|
||||
s.executeTemplate(w, tmpl, m)
|
||||
|
||||
return
|
||||
@@ -245,6 +253,7 @@ func (s *Handlers) renderTemplate(
|
||||
wrapper := templateDataWrapper{
|
||||
User: userInfo,
|
||||
CSRFToken: csrfToken,
|
||||
Version: version,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user