mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(macros): implement template cache (#2049)
* feat(macros): implement template cache * fix: typo in error * fix(macros): set DefaultTTL * fix: accidentally removed SetTimerResolution * revert: set NoTTL in MustParse
This commit is contained in:
parent
bfda849ef5
commit
c7efcf1b75
2 changed files with 52 additions and 12 deletions
|
@ -290,3 +290,28 @@ func TestMacros_Parse(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMacros_TemplateCache(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
release := Release{
|
||||
TorrentName: "Test Movie 2024",
|
||||
Year: 2024,
|
||||
}
|
||||
|
||||
m := NewMacro(release)
|
||||
template := "{{.TorrentName}} ({{.Year}})"
|
||||
|
||||
// parse and cache
|
||||
got1, err := m.Parse(template)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "Test Movie 2024 (2024)", got1)
|
||||
|
||||
// use cached template
|
||||
got2, err := m.Parse(template)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "Test Movie 2024 (2024)", got2)
|
||||
|
||||
_, ok := templateCache.Get(template)
|
||||
assert.True(t, ok, "template should be in cache")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue