Debian Codegraph @

hugolib/gitinfo_github_test.go

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
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 hugolib
15
16 import (
17 "testing"
18 )
19
20 func TestGitInfoFromGitModuleWithVersionQuery(t *testing.T) {
21 t.Parallel()
22
23 files := `
24 -- hugo.toml --
25 baseURL = "https://example.com/"
26 enableGitInfo = true
27
28 [module]
29 [[module.imports]]
30 path = "github.com/bep/hugo-testing-git-versions"
31 version = "v3.0.0"
32 [[module.imports.mounts]]
33 source = "content"
34 target = "content"
35 [[module.imports]]
36 path = "github.com/bep/hugo-testing-git-versions"
37 version = "v3.0.1"
38 [[module.imports.mounts]]
39 source = "content"
40 target = "content/301"
41 -- layouts/page.html --
42 Title: {{ .Title }}|
43 GitInfo: {{ with .GitInfo }}Hash: {{ .Hash }}|Subject: {{ .Subject }}|AuthorName: {{ .AuthorName }}{{ end }}|
44 Content: {{ .Content }}|
45 -- layouts/_default/list.html --
46 List: {{ .Title }}
47 `
48
49 b := Test(t, files, TestOptOsFs())
50
51 b.AssertFileContent("public/docs/functions/mean/index.html",
52 "Hash: 9769b63d4a4abdd406e333be5fb8b5d48737d3a9|",
53 "AuthorName: Bjørn Erik Pedersen|",
54 )
55
56 b.AssertFileContent("public/docs/functions/standard-deviation/index.html",
57 "Hash: 2d92492a7f1ec4968529ee12cf62ed652eb45950|Subject: v3.0.0 edits|",
58 "AuthorName: Bjørn Erik Pedersen|",
59 )
60
61 b.AssertFileContent("public/301/docs/functions/standard-deviation/index.html",
62 "Hash: 3e0f3930f1ec9a29a7442da5f1bfc0b7e58f167a|Subject: v3.0.1 edit|",
63 "AuthorName: Bjørn Erik Pedersen|",
64 )
65 }
66
67 func TestGitInfoFromGitModuleWithGoMod(t *testing.T) {
68 t.Parallel()
69
70 files := `
71 -- hugo.toml --
72 baseURL = "https://example.com/"
73 enableGitInfo = true
74
75 [module]
76 [[module.imports]]
77 path = "github.com/bep/hugo-mod-testing-content"
78 [[module.imports.mounts]]
79 source = "content"
80 target = "content"
81 -- layouts/page.html --
82 Title: {{ .Title }}|
83 GitInfo: {{ with .GitInfo }}Hash: {{ .Hash }}|Subject: {{ .Subject }}|AuthorName: {{ .AuthorName }}{{ end }}|
84 Content: {{ .Content }}|
85 -- layouts/_default/list.html --
86 List: {{ .Title }}
87 -- go.mod --
88 module hugotest
89 `
90
91 b := Test(t, files, TestOptOsFs())
92
93 b.AssertFileContent("public/docs/functions/kurtosis/index.html",
94 "Hash: 668663b54d0937df05185d144765d13c3ffda489|",
95 "AuthorName: Bjørn Erik Pedersen|",
96 )
97 }
98
99 // See issue 14942.
100 func TestGitInfoFromGitModuleWithGoModInSubdir(t *testing.T) {
101 t.Parallel()
102
103 files := `
104 -- hugo.toml --
105 baseURL = "https://example.com/"
106 enableGitInfo = true
107
108 [module]
109 [[module.imports]]
110 path = "github.com/bep/hugo-mod-misc/dummy-content"
111 version = "v0.3.0"
112 [[module.imports.mounts]]
113 source = "content"
114 target = "content"
115 -- layouts/page.html --
116 Title: {{ .Title }}|
117 GitInfo: {{ with .GitInfo }}Hash: {{ .Hash }}|Subject: {{ .Subject }}|AuthorName: {{ .AuthorName }}{{ end }}|
118 -- layouts/_default/list.html --
119 List: {{ .Title }}
120 -- go.mod --
121 module hugotest
122 `
123
124 b := Test(t, files, TestOptOsFs())
125
126 b.AssertFileContent("public/blog/music/satin-doll/index.html",
127 "Hash: 522ee6c486ff24b2e3d45e9b90061564e9427030|",
128 "AuthorName: Bjørn Erik Pedersen|",
129 )
130 }