Debian Codegraph @

tpl/os/os_integration_test.go

raw
1 // Copyright 2024 The Hugo Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package os_test
15
16 import (
17 "testing"
18
19 "github.com/gohugoio/hugo/hugolib"
20 )
21
22 // Issue 9599
23 func TestReadDirWorkDir(t *testing.T) {
24 t.Parallel()
25
26 files := `
27 -- hugo.toml --
28 theme = "mytheme"
29 -- myproject.txt --
30 Hello project!
31 -- themes/mytheme/mytheme.txt --
32 Hello theme!
33 -- layouts/home.html --
34 {{ $entries := (readDir ".") }}
35 START:|{{ range $entry := $entries }}{{ if not $entry.IsDir }}{{ $entry.Name }}|{{ end }}{{ end }}:END:
36
37
38 `
39
40 b := hugolib.Test(t, files, hugolib.TestOptOsFs())
41
42 b.AssertFileContent("public/index.html", `
43 START:|hugo.toml|myproject.txt|:END:
44 `)
45 }
46
47 // Issue 9620
48 func TestReadFileNotExists(t *testing.T) {
49 t.Parallel()
50
51 files := `
52 -- hugo.toml --
53 -- layouts/home.html --
54 {{ $fi := (readFile "doesnotexist") }}
55 {{ if $fi }}Failed{{ else }}OK{{ end }}
56
57
58 `
59
60 b := hugolib.Test(t, files, hugolib.TestOptOsFs())
61
62 b.AssertFileContent("public/index.html", `
63 OK
64 `)
65 }