Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: tests
  • Loading branch information
rymut committed Dec 20, 2024
commit e95c59c283eeed103d3ae98d4c21497d1517b9b9
89 changes: 59 additions & 30 deletions tpl/os/os_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,54 +19,84 @@ import (
"github.com/gohugoio/hugo/hugolib"
)

// Issue 9599
func TestReadDirWorkDir(t *testing.T) {
t.Parallel()

files := `
-- config.toml --
theme = "mytheme"
-- myproject.txt --
Hello project!
-- themes/mytheme/mytheme.txt --
Hello theme!
-- layouts/index.html --
{{ $entries := (readDir ".") }}
START:|{{ range $entry := $entries }}{{ if not $entry.IsDir }}{{ $entry.Name }}|{{ end }}{{ end }}:END:


`

b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
NeedsOsFS: true,
},
).Build()

func TestReadDirMountDir2(t *testing.T) {
b.AssertFileContent("public/index.html", `
START:|config.toml|myproject.txt|:END:
`)
}

// Issue 9620
func TestReadFileNotExists(t *testing.T) {
t.Parallel()

files := `
-- config.toml --
-- layouts/index.html --
{{ $fi := (readFile "doesnotexist") }}
{{ if $fi }}Failed{{ else }}OK{{ end }}


`

b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
NeedsOsFS: true,
},
).Build()

b.AssertFileContent("public/index.html", `
OK
`)
}

func TestReadDirMountsTopDirectory(t *testing.T) {
t.Parallel()

files := `
-- hugo.toml --
baseURL = "https://example.com/"
theme = "mytheme"
[module]
[[module.imports]]
path = "module1"
[[module.imports.mounts]]
source = "assets"
target = "assets"
[[module.imports]]
path = "mytheme"
[[module.imports.mounts]]
source = "private"
target = "assets"
[[module.imports.mounts]]
source = "private/test"
target = "assets"

-- myproject.txt --
Hello project!
-- themes/module1/hugo.toml --
-- themes/module1/go.mod --
module github.com/rymut/hugo-issues-mre/hugo-os/hugo-os-module2

go 1.23.2
-- themes/module1/assets/file.json --
{}
-- themes/mytheme/mytheme.txt --
Hello theme!
-- themes/mytheme/data/not.my_content.md --
test
-- themes/mytheme/layouts/partials/mypartial.html --
test
-- themes/mytheme/private/test/should_not_mount.txt --
Empty file
-- layouts/index.html --
{{ $entries := (readDir "" false) }}
START:|{{ range $entry := $entries }}{{ $entry.Name }}|{{ end }}:END:
-- files/layouts/l1.txt --
l1
-- files/layouts/assets/l2.txt --
l2
`
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
Expand All @@ -76,7 +106,6 @@ l2
).Build()

b.AssertFileContent("public/index.html", `
START:|assets|files|hugo.toml|layouts|myproject.txt|themes|:END:
START:|assets|hugo.toml|layouts|myproject.txt|themes|:END:
`)
b.AssertFileContent("public/index.html", `START:||:END`)
}