404_test.go - hugo - [fork] hugo port for 9front
HTML git clone https://git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
404_test.go (2926B)
---
1 // Copyright 2017 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 "fmt"
18 "testing"
19 )
20
21 func Test404(t *testing.T) {
22 t.Parallel()
23
24 files := `
25 -- hugo.toml --
26 baseURL = "http://example.com/"
27 -- layouts/404.html --
28 {{ $home := site.Home }}
29 404:
30 Parent: {{ .Parent.Kind }}
31 IsAncestor: {{ .IsAncestor $home }}/{{ $home.IsAncestor . }}
32 IsDescendant: {{ .IsDescendant $home }}/{{ $home.IsDescendant . }}
33 CurrentSection: {{ .CurrentSection.Kind }}|
34 FirstSection: {{ .FirstSection.Kind }}|
35 InSection: {{ .InSection $home.Section }}|{{ $home.InSection . }}
36 Sections: {{ len .Sections }}|
37 Page: {{ .Page.RelPermalink }}|
38 Data: {{ len .Data }}|
39 `
40
41 b := NewIntegrationTestBuilder(
42 IntegrationTestConfig{
43 T: t,
44 TxtarString: files,
45 // LogLevel: logg.LevelTrace,
46 // Verbose: true,
47 },
48 ).Build()
49
50 // Note: We currently have only 1 404 page. One might think that we should have
51 // multiple, to follow the Custom Output scheme, but I don't see how that would work
52 // right now.
53 b.AssertFileContent("public/404.html", `
54 404:
55 Parent: home
56 IsAncestor: false/true
57 IsDescendant: true/false
58 CurrentSection: home|
59 FirstSection: home|
60 InSection: false|true
61 Sections: 0|
62 Page: /404.html|
63 Data: 1|
64
65 `)
66 }
67
68 func Test404WithBase(t *testing.T) {
69 t.Parallel()
70
71 b := newTestSitesBuilder(t)
72 b.WithSimpleConfigFile().WithTemplates("404.html", `{{ define "main" }}
73 Page not found
74 {{ end }}`,
75 "baseof.html", `Base: {{ block "main" . }}{{ end }}`).WithContent("page.md", ``)
76
77 b.Build(BuildCfg{})
78
79 // Note: We currently have only 1 404 page. One might think that we should have
80 // multiple, to follow the Custom Output scheme, but I don't see how that would work
81 // right now.
82 b.AssertFileContent("public/404.html", `
83 Base:
84 Page not found`)
85 }
86
87 func Test404EditTemplate(t *testing.T) {
88 t.Parallel()
89
90 files := `
91 -- hugo.toml --
92 baseURL = "http://example.com/"
93 disableLiveReload = true
94 [internal]
95 fastRenderMode = true
96 -- layouts/_default/baseof.html --
97 Base: {{ block "main" . }}{{ end }}
98 -- layouts/404.html --
99 {{ define "main" }}
100 Not found.
101 {{ end }}
102
103 `
104
105 b := TestRunning(t, files)
106
107 b.AssertFileContent("public/404.html", `Not found.`)
108
109 b.EditFiles("layouts/404.html", `Not found. Updated.`).Build()
110
111 fmt.Println("Rebuilding")
112 b.BuildPartial("/does-not-exist")
113
114 b.AssertFileContent("public/404.html", `Not found. Updated.`)
115 }