summaryrefslogtreecommitdiffstats
path: root/.clang-format
AgeCommit message (Expand)Author
2019-04-17Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/netDavid S. Miller
2019-04-12clang-format: Update with the latest for_each macro listMiguel Ojeda
2019-03-21rhashtable: rename rht_for_each*continue as *from.NeilBrown
2019-03-12Merge branch 'work.iov_iter' of git://git.kernel.org/pub/scm/linux/kernel/git...Linus Torvalds
2019-02-19RDMA: Add and use rdma_for_each_portJason Gunthorpe
2019-02-11lib/scatterlist: Provide a DMA page iteratorJason Gunthorpe
2019-02-04uio: remove the unused iov_for_each macroChristoph Hellwig
2019-01-19clang-format: Update .clang-format with the latest for_each macro listJason Gunthorpe
2018-10-21page cache: Convert find_get_pages_contig to XArrayMatthew Wilcox
2018-08-01clang-format: Set IndentWrappedFunctionNames falseJason Gunthorpe
2018-04-11clang-format: add configuration fileMiguel Ojeda
n> Mirror of https://github.com/gohugoio/hugomatthias
summaryrefslogtreecommitdiffstats
path: root/hugolib/site_show_plan_test.go
blob: db5bec7b612798204606285127b0f406f783c9e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright 2015 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package hugolib

import (
	"bytes"
	"path/filepath"
	"strings"
	"testing"

	"github.com/spf13/hugo/helpers"
	"github.com/spf13/hugo/source"
	"github.com/spf13/hugo/target"
	"github.com/spf13/viper"
)

const aliasDoc1 = "---\ntitle: alias doc\naliases:\n  - \"alias1/\"\n  - \"alias-2/\"\n---\naliases\n"

var fakeSource = []source.ByteSource{
	{
		Name:    filepath.FromSlash("foo/bar/file.md"),
		Content: []byte(simplePage),
	},
	{
		Name:    filepath.FromSlash("alias/test/file1.md"),
		Content: []byte(aliasDoc1),
	},
	{
		Name:    filepath.FromSlash("section/somecontent.html"),
		Content: []byte(renderNoFrontmatter),
	},
}

func checkShowPlanExpected(t *testing.T, s *Site, expected string) {
	out := new(bytes.Buffer)
	if err := s.ShowPlan(out); err != nil {
		t.Fatalf("ShowPlan unexpectedly returned an error: %s", err)
	}
	got := out.String()

	expected = filepath.FromSlash(expected)
	// hackety hack: alias is an Url
	expected = strings.Replace(expected, (helpers.FilePathSeparator + " =>"), "/ =>", -1)
	expected = strings.Replace(expected, "n"+(helpers.FilePathSeparator+"a"), "n/a", -1)
	gotList := strings.Split(got, "\n")
	expectedList := strings.Split(expected, "\n")

	diff := helpers.DiffStringSlices(gotList, expectedList)

	if len(diff) > 0 {
		t.Errorf("Got diff in show plan: %v", diff)
	}
}

// TODO(bep) The tests below fail in a multilanguage setup. They can be fixed, but they
// feel fragile and old. Suggest delete.
func _TestDegenerateNoFiles(t *testing.T) {
	checkShowPlanExpected(t, new(Site), "No source files provided.\n")
}

func _TestDegenerateNoTarget(t *testing.T) {
	s := &Site{
		Source: &source.InMemorySource{ByteSource: fakeSource},
	}
	must(s.createPages())
	expected := "foo/bar/file.md (renderer: markdown)\n canonical => !no target specified!\n\n" +
		"alias/test/file1.md (renderer: markdown)\n canonical => !no target specified!\n\n" +
		"section/somecontent.html (renderer: n/a)\n canonical => !no target specified!\n\n"
	checkShowPlanExpected(t, s, expected)
}

func _TestFileTarget(t *testing.T) {
	testCommonResetState()

	viper.Set("DefaultExtension", "html")

	s := &Site{
		Source: &source.InMemorySource{ByteSource: fakeSource},
	}
	s.aliasTarget()
	s.pageTarget()
	must(s.createPages())
	expected := "foo/bar/file.md (renderer: markdown)\n canonical => public/foo/bar/file/index.html\n\n" +
		"alias/test/file1.md (renderer: markdown)\n" +
		" canonical => public/alias/test/file1/index.html\n" +
		" alias1/ => public/alias1/index.html\n" +
		" alias-2/ => public/alias-2/index.html\n\n" +
		"section/somecontent.html (renderer: n/a)\n canonical => public/section/somecontent/index.html\n\n"

	checkShowPlanExpected(t, s, expected)
}

func _TestPageTargetUgly(t *testing.T) {
	testCommonResetState()

	viper.Set("DefaultExtension", "html")
	viper.Set("UglyURLs", true)

	s := &Site{
		targets:  targetList{page: &target.PagePub{UglyURLs: true, PublishDir: "public"}},
		Source:   &source.InMemorySource{ByteSource: fakeSource},
		Language: helpers.NewDefaultLanguage(),
	}

	if err := buildAndRenderSite(s); err != nil {
		t.Fatalf("Failed to build site: %s", err)
	}

	expected := "foo/bar/file.md (renderer: markdown)\n canonical => public/foo/bar/file.html\n\n" +
		"alias/test/file1.md (renderer: markdown)\n" +
		" canonical => public/alias/test/file1.html\n" +
		" alias1/ => public/alias1/index.html\n" +
		" alias-2/ => public/alias-2/index.html\n\n" +
		"public/section/somecontent.html (renderer: n/a)\n canonical => public/section/somecontent.html\n\n"
	checkShowPlanExpected(t, s, expected)
}

func _TestFileTargetPublishDir(t *testing.T) {
	testCommonResetState()

	viper.Set("DefaultExtension", "html")

	s := &Site{

		targets: targetList{
			page:  &target.PagePub{PublishDir: "../public"},
			alias: &target.HTMLRedirectAlias{PublishDir: "../public"},
		},
		Source: &source.InMemorySource{ByteSource: fakeSource},
	}

	must(s.createPages())
	expected := "foo/bar/file.md (renderer: markdown)\n canonical => ../foo/bar/file/index.html\n\n" +
		"alias/test/file1.md (renderer: markdown)\n" +
		" canonical => ../alias/test/file1/index.html\n" +
		" alias1/ => ../alias1/index.html\n" +
		" alias-2/ => ../alias-2/index.html\n\n" +
		"section/somecontent.html (renderer: n/a)\n canonical => ../section/somecontent/index.html\n\n"
	checkShowPlanExpected(t, s, expected)
}