mirror of
https://github.com/mattermost/mattermost.git
synced 2026-02-13 15:55:34 -05:00
Some checks are pending
API / build (push) Waiting to run
Server CI / Compute Go Version (push) Waiting to run
Server CI / Check mocks (push) Blocked by required conditions
Server CI / Check go mod tidy (push) Blocked by required conditions
Server CI / check-style (push) Blocked by required conditions
Server CI / Check serialization methods for hot structs (push) Blocked by required conditions
Server CI / Vet API (push) Blocked by required conditions
Server CI / Check migration files (push) Blocked by required conditions
Server CI / Generate email templates (push) Blocked by required conditions
Server CI / Check store layers (push) Blocked by required conditions
Server CI / Check mmctl docs (push) Blocked by required conditions
Server CI / Postgres with binary parameters (push) Blocked by required conditions
Server CI / Postgres (push) Blocked by required conditions
Server CI / Postgres (FIPS) (push) Blocked by required conditions
Server CI / Generate Test Coverage (push) Blocked by required conditions
Server CI / Run mmctl tests (push) Blocked by required conditions
Server CI / Run mmctl tests (FIPS) (push) Blocked by required conditions
Server CI / Build mattermost server app (push) Blocked by required conditions
Web App CI / check-lint (push) Waiting to run
Web App CI / check-i18n (push) Waiting to run
Web App CI / check-types (push) Waiting to run
Web App CI / test (push) Waiting to run
Web App CI / build (push) Waiting to run
* [MM-66718] Remove unneeded HTML templates watcher The templates package currently supports filesystem watching to automatically reload templates when files change. This feature is unnecessary in production and adds complexity. Changes: - Removed NewWithWatcher() function from templates package - Removed Close() method from Container - Removed watch-related fields (watch, stop, stopped) from Container - Removed fsnotify dependency usage - Updated server.go to use New() instead of NewWithWatcher() - Updated email/helper_test.go to use New() - Removed watcher-related tests from templates_test.go Template updates now require a server restart, which provides clearer behavior and reduces code complexity. * Remove unused fsnotify dependency
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package templates
|
|
|
|
import (
|
|
"bytes"
|
|
"html/template"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestNew_BadDirectory(t *testing.T) {
|
|
container, err := New("notarealdirectory")
|
|
assert.Nil(t, container)
|
|
assert.Error(t, err)
|
|
}
|
|
|
|
func TestRender(t *testing.T) {
|
|
tpl := template.New("test")
|
|
_, err := tpl.Parse(`{{ define "foo" }}foo{{ .Props.Bar }}{{ end }}`)
|
|
require.NoError(t, err)
|
|
mt := NewFromTemplate(tpl)
|
|
|
|
data := Data{
|
|
Props: map[string]any{
|
|
"Bar": "bar",
|
|
},
|
|
}
|
|
text, err := mt.RenderToString("foo", data)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "foobar", text)
|
|
|
|
buf := &bytes.Buffer{}
|
|
require.NoError(t, mt.Render(buf, "foo", data))
|
|
assert.Equal(t, "foobar", buf.String())
|
|
}
|
|
|
|
func TestRenderError(t *testing.T) {
|
|
tpl := template.New("test")
|
|
_, err := tpl.Parse(`{{ define "foo" }}foo{{ .Foo.Bar }}bar{{ end }}`)
|
|
require.NoError(t, err)
|
|
mt := NewFromTemplate(tpl)
|
|
|
|
text, err := mt.RenderToString("foo", Data{})
|
|
require.Error(t, err)
|
|
assert.Equal(t, "", text)
|
|
|
|
buf := &bytes.Buffer{}
|
|
assert.Error(t, mt.Render(buf, "foo", Data{}))
|
|
assert.Equal(t, "foo", buf.String())
|
|
}
|
|
|
|
func TestRenderUnknownTemplate(t *testing.T) {
|
|
tpl := template.New("")
|
|
mt := NewFromTemplate(tpl)
|
|
|
|
text, err := mt.RenderToString("foo", Data{})
|
|
require.Error(t, err)
|
|
assert.Equal(t, "", text)
|
|
|
|
buf := &bytes.Buffer{}
|
|
assert.Error(t, mt.Render(buf, "foo", Data{}))
|
|
assert.Equal(t, "", buf.String())
|
|
}
|