Compare commits

...

6 Commits

Author SHA1 Message Date
Bjørn Erik Pedersen c626d8df8a tpl/data: Deprecate data.GetJSON and data.GetCSV 2024-01-28 16:11:12 +01:00
razonyang 60d954c785 modules: Print required Hugo version for incompatible modules 2024-01-28 15:23:21 +01:00
Bjørn Erik Pedersen 63e0a92894 hugolib: Remove unused test image 2024-01-28 15:14:53 +01:00
Kandula Naveen ce7daa6156 navigation: Improve menu cache 2024-01-28 15:11:57 +01:00
Bjørn Erik Pedersen 2a0329423c testing: Rename integration_test.go to PACKAGE_integration_test.go
Primary motivation making them easier to find in the code editor.
2024-01-28 11:41:59 +01:00
Bjørn Erik Pedersen 50dc327d1a Port some integration tests to new test setup
The method I'm currently using (if other want to help) is:

* Add fmt.Println(b.DumpTxtar()) after the Build step
* Add that to a files var and pass that to Test(t, files) or similar
* Then, if possible, try to reduce the files/content down to what's needed in test.

Note that if the test is small, it's probably faster just to manually re-create the test.
2024-01-28 11:29:23 +01:00
39 changed files with 44 additions and 61 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

+30 -47
View File
@@ -657,30 +657,24 @@ min_version = 0.55.0
func TestMountsProject(t *testing.T) {
t.Parallel()
config := `
files := `
-- config.toml --
baseURL="https://example.org"
[module]
[[module.mounts]]
source="mycontent"
target="content"
`
b := newTestSitesBuilder(t).
WithConfigFile("toml", config).
WithSourceFile(filepath.Join("mycontent", "mypage.md"), `
-- layouts/_default/single.html --
Permalink: {{ .Permalink }}|
-- mycontent/mypage.md --
---
title: "My Page"
---
`
b := Test(t, files)
`)
b.Build(BuildCfg{})
// helpers.PrintFs(b.H.Fs.Source, "public", os.Stdout)
b.AssertFileContent("public/mypage/index.html", "Permalink: https://example.org/mypage/")
b.AssertFileContent("public/mypage/index.html", "Permalink: https://example.org/mypage/|")
}
// https://github.com/gohugoio/hugo/issues/6684
@@ -706,25 +700,20 @@ Home: {{ .Title }}|{{ .Content }}|
func TestSiteWithGoModButNoModules(t *testing.T) {
t.Parallel()
c := qt.New(t)
// We need to use the OS fs for this.
workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-no-mod")
c.Assert(err, qt.IsNil)
tempDir := t.TempDir()
cfg := config.New()
cfg.Set("workingDir", workDir)
cfg.Set("publishDir", "public")
fs := hugofs.NewFromOld(hugofs.Os, cfg)
files := `
-- hugo.toml --
baseURL = "https://example.org"
-- go.mod --
defer clean()
`
b := newTestSitesBuilder(t)
b.Fs = fs
b := Test(t, files, TestOptWithConfig(func(cfg *IntegrationTestConfig) {
cfg.WorkingDir = tempDir
}))
b.WithWorkingDir(workDir).WithViper(cfg)
b.WithSourceFile("go.mod", "")
b.Build(BuildCfg{})
b.Build()
}
// https://github.com/gohugoio/hugo/issues/6622
@@ -783,7 +772,9 @@ P1: {{ $p1.Title }}|{{ $p1.RelPermalink }}|Filename: {{ $p1.File.Filename }}
// Issue 9426
func TestMountSameSource(t *testing.T) {
config := `baseURL = 'https://example.org/'
files := `
-- hugo.toml --
baseURL = 'https://example.org/'
languageCode = 'en-us'
title = 'Hugo GitHub Issue #9426'
@@ -800,18 +791,15 @@ target = "content/resources-a"
[[module.mounts]]
source = "extra-content"
target = "content/resources-b"
-- layouts/_default/single.html --
Single
-- content/p1.md --
-- extra-content/_index.md --
-- extra-content/subdir/_index.md --
-- extra-content/subdir/about.md --
"
`
b := newTestSitesBuilder(t).WithConfigFile("toml", config)
b.WithContent("p1.md", "")
b.WithSourceFile(
"extra-content/_index.md", "",
"extra-content/subdir/_index.md", "",
"extra-content/subdir/about.md", "",
)
b.Build(BuildCfg{})
b := Test(t, files)
b.AssertFileContent("public/resources-a/subdir/about/index.html", "Single")
b.AssertFileContent("public/resources-b/subdir/about/index.html", "Single")
@@ -836,12 +824,7 @@ message: Hugo Rocks
{{ site.Data.extra.test.message }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", "Hugo Rocks")
}
+1
View File
@@ -90,6 +90,7 @@ func TestRunning(t testing.TB, files string, opts ...TestOpt) *IntegrationTestBu
return NewIntegrationTestBuilder(cfg).Build()
}
// In most cases you should not use this function directly, but the Test or TestRunning function.
func NewIntegrationTestBuilder(conf IntegrationTestConfig) *IntegrationTestBuilder {
// Code fences.
conf.TxtarString = strings.ReplaceAll(conf.TxtarString, "§§§", "```")
+1 -1
View File
@@ -126,7 +126,7 @@ func (m ModulesConfig) HasConfigFile() bool {
func (m *ModulesConfig) setActiveMods(logger loggers.Logger) error {
for _, mod := range m.AllModules {
if !mod.Config().HugoVersion.IsValid() {
logger.Warnf(`Module %q is not compatible with this Hugo version; run "hugo mod graph" for more information.`, mod.Path())
logger.Warnf(`Module %q is not compatible with this Hugo version: %s; run "hugo mod graph" for more information.`, mod.Path(), mod.Config().HugoVersion)
}
}
+7 -13
View File
@@ -35,6 +35,7 @@ func (entry menuCacheEntry) matches(menuList []Menu) bool {
return true
}
// newMenuCache creates a new menuCache instance.
func newMenuCache() *menuCache {
return &menuCache{m: make(map[string][]menuCacheEntry)}
}
@@ -44,31 +45,23 @@ type menuCache struct {
m map[string][]menuCacheEntry
}
// menuEqual checks if two menus are equal.
func menuEqual(m1, m2 Menu) bool {
if m1 == nil && m2 == nil {
return true
}
if m1 == nil || m2 == nil {
return false
}
if len(m1) != len(m2) {
return false
}
if len(m1) == 0 {
return true
}
for i := 0; i < len(m1); i++ {
for i := range m1 {
if m1[i] != m2[i] {
return false
}
}
return true
}
// get retrieves a menu from the cache based on the provided key and menuLists.
// If the menu is not found, it applies the provided function and caches the result.
func (c *menuCache) get(key string, apply func(m Menu), menuLists ...Menu) (Menu, bool) {
return c.getP(key, func(m *Menu) {
if apply != nil {
@@ -77,6 +70,7 @@ func (c *menuCache) get(key string, apply func(m Menu), menuLists ...Menu) (Menu
}, menuLists...)
}
// getP is similar to get but also returns a boolean indicating whether the menu was found in the cache.
func (c *menuCache) getP(key string, apply func(m *Menu), menuLists ...Menu) (Menu, bool) {
c.Lock()
defer c.Unlock()
+5
View File
@@ -25,6 +25,7 @@ import (
"strings"
"github.com/gohugoio/hugo/cache/filecache"
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/config/security"
@@ -63,6 +64,8 @@ type Namespace struct {
// If you provide multiple parts for the URL they will be joined together to the final URL.
// GetCSV returns nil or a slice slice to use in a short code.
func (ns *Namespace) GetCSV(sep string, args ...any) (d [][]string, err error) {
hugo.Deprecate("data.GetJSON", "use resources.Get or resources.GetRemote with transform.Unmarshal.", "v0.123.0")
url, headers := toURLAndHeaders(args)
cache := ns.cacheGetCSV
@@ -102,6 +105,8 @@ func (ns *Namespace) GetCSV(sep string, args ...any) (d [][]string, err error) {
// If you provide multiple parts they will be joined together to the final URL.
// GetJSON returns nil or parsed JSON to use in a short code.
func (ns *Namespace) GetJSON(args ...any) (any, error) {
hugo.Deprecate("data.GetJSON", "use resources.Get or resources.GetRemote with transform.Unmarshal.", "v0.123.0")
var v any
url, headers := toURLAndHeaders(args)
cache := ns.cacheGetJSON