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
tests: refactor code
  • Loading branch information
rymut committed Dec 23, 2024
commit 13062129770455186958011f93cfb55fe5acee35
71 changes: 71 additions & 0 deletions tpl/os/os_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,40 @@ OK
`)
}

func TestReadDirMountsVirtualDirectorySizeIsZero(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
[module]
[[module.imports]]
path = "module1"
[[module.imports.mounts]]
source = "assets"
target = "assets/virtual"
[[module.imports.mounts]]
source = "assets/file.json"
target = "assets/testing.json"
-- themes/module1/assets/file.json --
{}
-- layouts/index.html --
{{ $entries := readDir "assets" false }}
START:|{{ range $entry := $entries }}{{ $entry.Name }}={{ $entry.Size }}|{{ end }}:END:
{{ $entries = readDir "assets/virtual" false }}
START:|{{ range $entry := $entries }}{{ $entry.Name }}={{ $entry.Size }}|{{ end }}:END:
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
NeedsOsFS: true,
},
).Build()

b.AssertFileContent("public/index.html", `
START:|file.json=2|virtual=0|:END:
`)
}

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

Expand Down Expand Up @@ -109,3 +143,40 @@ START:|{{ range $entry := $entries }}{{ $entry.Name }}|{{ end }}:END:
START:|assets|hugo.toml|layouts|myproject.txt|themes|:END:
`)
}

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

files := `
-- hugo.toml --
baseURL = "https://example.com/"
[module]
[[module.imports]]
path = "module1"
[[module.imports]]
path = "module2"

-- myproject.txt --
Hello project!
-- themes/module1/assets/file1.json --
{}
-- themes/module2/assets/files/raw.txt --
Nothing here
-- themes/module2/assets/file2.json --
{}
-- layouts/index.html --
{{ $entries := (readDir "assets" false) }}
START:|{{ range $entry := $entries }}{{ $entry.Name }}|{{ end }}:END:
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
NeedsOsFS: true,
},
).Build()

b.AssertFileContent("public/index.html", `
START:|file1.json|file2.json|files|:END:
`)
}