Debian Codegraph @

modules/mount_filters_integration_test.go

raw
1 // Copyright 2025 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 modules_test
15
16 import (
17 "testing"
18
19 "github.com/gohugoio/hugo/hugolib"
20 )
21
22 func TestModulesFiltersFiles(t *testing.T) {
23 t.Parallel()
24
25 files := `
26 -- hugo.toml --
27 [module]
28 [[module.mounts]]
29 source = "content"
30 target = "content"
31 files = ["! **b.md", "**.md"] # The order matters here.
32 -- content/a.md --
33 +++
34 title = "A"
35 +++
36 Content A
37 -- content/b.md --
38 +++
39 title = "B"
40 +++
41 Content B
42 -- content/c.md --
43 +++
44 title = "C"
45 +++
46 Content C
47 -- layouts/all.html --
48 All. {{ .Title }}|
49
50 `
51
52 b := hugolib.Test(t, files, hugolib.TestOptInfo())
53 b.AssertLogContains("! deprecated")
54 b.AssertFileContent("public/a/index.html", "All. A|")
55 b.AssertFileContent("public/c/index.html", "All. C|")
56 b.AssertFileExists("public/b/index.html", false)
57 }
58
59 // File filter format <= 0.152.0.
60 func TestModulesFiltersFilesLegacy(t *testing.T) {
61 // This cannot be parallel.
62
63 files := `
64 -- hugo.toml --
65 [module]
66 [[module.mounts]]
67 source = "content"
68 target = "content"
69 includefiles = ["**{a,c}.md"] #includes was evaluated before excludes <= 0.152.0
70 excludefiles = ["**b.md"]
71 -- content/a.md --
72 +++
73 title = "A"
74 +++
75 Content A
76 -- content/b.md --
77 +++
78 title = "B"
79 +++
80 Content B
81 -- content/c.md --
82 +++
83 title = "C"
84 +++
85 Content C
86 -- layouts/all.html --
87 All. {{ .Title }}|
88
89 `
90
91 b := hugolib.Test(t, files, hugolib.TestOptInfo())
92
93 b.AssertFileContent("public/a/index.html", "All. A|")
94 b.AssertFileContent("public/c/index.html", "All. C|")
95 b.AssertFileExists("public/b/index.html", false)
96 }