summaryrefslogtreecommitdiffstats
path: root/related/related_integration_test.go
blob: 291bfdbf71b174a2d9347a3728075453d2ea2506 (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Copyright 2024 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 related_test

import (
	"fmt"
	"math/rand"
	"testing"

	"github.com/gohugoio/hugo/hugolib"
)

func TestRelatedFragments(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
baseURL = "http://example.com/"
disableKinds = ["taxonomy", "term", "RSS", "sitemap", "robotsTXT"]
[related]
  includeNewer = false
  threshold = 80
  toLower = false
[[related.indices]]
  name = 'pagerefs'
  type = 'fragments'
  applyFilter = true
  weight = 90
[[related.indices]]
  name = 'keywords'
  weight = 80	
-- content/p1.md --
---
title: p1
pagerefs: ['ref1']
---
{{< see-also >}}

## P1 title

-- content/p2.md --
---
title: p2
---

## P2 title 1

## P2 title 2

## First title {#ref1}
{{< see-also "ref1" >}}
-- content/p3.md --
---
title: p3
keywords: ['foo']
---

## P3 title 1

## P3 title 2

## Common p3, p4, p5
-- content/p4.md --
---
title: p4
---

## Common p3, p4, p5

## P4 title 1

-- content/p5.md --
---
title: p5
keywords: ['foo']
---

## P5 title 1

## Common p3, p4, p5

-- layouts/shortcodes/see-also.html --
{{ $p1 := site.GetPage "p1" }}
{{ $p2 := site.GetPage "p2" }}
{{ $p3 := site.GetPage "p3" }}
P1 Fragments: {{ $p1.Fragments.Identifiers }}
P2 Fragments: {{ $p2.Fragments.Identifiers }}
Contains ref1: {{ $p2.Fragments.Identifiers.Contains "ref1" }}
Count ref1: {{ $p2.Fragments.Identifiers.Count "ref1" }}
{{ $opts := dict "document" .Page "fragments" $.Params }}
{{ $related1 := site.RegularPages.Related $opts }}
{{ $related2 := site.RegularPages.Related $p3 }}
Len Related 1: {{ len $related1 }}
Len Related 2: {{ len $related2 }}
Related 1: {{ template "list-related" $related1 }}
Related 2: {{ template "list-related" $related2 }}

{{ define "list-related" }}{{ range $i, $e := . }} {{ $i }}: {{ .Title }}: {{ with .HeadingsFiltered}}{{ range $i, $e := .}}h{{ $i }}: {{ .Title }}|{{ .ID }}|{{ end }}{{ end }}::END{{ end }}{{ end }}

-- layouts/_default/single.html --
Content: {{ .Content }}

	
`

	b := hugolib.Test(t, files)

	expect := `
P1 Fragments: [p1-title]	
P2 Fragments: [p2-title-1 p2-title-2 ref1]
Len Related 1: 1
Related 2: 2
`

	for _, p := range []string{"p1", "p2"} {
		b.AssertFileContent("public/"+p+"/index.html", expect)
	}

	b.AssertFileContent("public/p1/index.html",
		"Related 1:  0: p2: h0: First title|ref1|::END",
		"Related 2:  0: p5: h0: Common p3, p4, p5|common-p3-p4-p5|::END 1: p4: h0: Common p3, p4, p5|common-p3-p4-p5|::END",
	)
}

func BenchmarkRelatedSite(b *testing.B) {
	files := `
-- config.toml --
baseURL = "http://example.com/"
disableKinds = ["taxonomy", "term", "RSS", "sitemap", "robotsTXT"]
[related]
  includeNewer = false
  threshold = 80
  toLower = false
[[related.indices]]
  name = 'keywords'
  weight = 70	
[[related.indices]]
  name = 'pagerefs'
  type = 'fragments'
  weight = 30	
-- layouts/_default/single.html --
Len related: {{ site.RegularPages.Related . | len }}
`

	createContent := func(n int) string {
		base := `---
title: "Page %d"
keywords: ['k%d']
---
`

		for i := 0; i < 32; i++ {
			base += fmt.Sprintf("\n## Title %d", rand.Intn(100))
		}

		return fmt.Sprintf(base, n, rand.Intn(32))
	}

	for i := 1; i < 100; i++ {
		files += fmt.Sprintf("\n-- content/posts/p%d.md --\n"+createContent(i+1), i+1)
	}

	cfg := hugolib.IntegrationTestConfig{
		T:           b,
		TxtarString: files,
	}
	builders := make([]*hugolib.IntegrationTestBuilder, b.N)

	for i := range builders {
		builders[i] = hugolib.NewIntegrationTestBuilder(cfg)
	}

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		builders[i].Build()
	}
}
onitoring_sensor_iterator_next, ipmi_monitoring_ctx_sensor_config_file, ipmi_monitoring_ctx_sdr_cache_directory, ipmi_monitoring_ctx_errormsg, ipmi_monitoring_ctx_create ], [AC_CHECK_HEADER( [ipmi_monitoring.h], [AC_CHECK_HEADER( [ipmi_monitoring_bitmasks.h], [have_ipmimonitoring=yes], [have_ipmimonitoring=no] )], [have_ipmimonitoring=no] )], [have_ipmimonitoring=no] )], [have_ipmimonitoring=no] ) test "${enable_plugin_freeipmi}" = "yes" -a "${have_ipmimonitoring}" != "yes" && \ AC_MSG_ERROR([ipmimonitoring required but not found. Try installing 'libipmimonitoring-dev' or 'libipmimonitoring-devel']) AC_MSG_CHECKING([if freeipmi.plugin should be enabled]) if test "${enable_plugin_freeipmi}" != "no" -a "${have_ipmimonitoring}" = "yes"; then enable_plugin_freeipmi="yes" AC_DEFINE([HAVE_FREEIPMI], [1], [ipmimonitoring usability]) OPTIONAL_IPMIMONITORING_CLFAGS="${IPMIMONITORING_CFLAGS}" OPTIONAL_IPMIMONITORING_LIBS="${IPMIMONITORING_LIBS}" else enable_plugin_freeipmi="no" fi AC_MSG_RESULT([${enable_plugin_freeipmi}]) AM_CONDITIONAL([ENABLE_PLUGIN_FREEIPMI], [test "${enable_plugin_freeipmi}" = "yes"]) # ----------------------------------------------------------------------------- # nfacct.plugin - libmnl, libnetfilter_acct AC_CHECK_HEADERS_ONCE([linux/netfilter/nfnetlink_conntrack.h]) PKG_CHECK_MODULES( [NFACCT], [libnetfilter_acct], [have_libnetfilter_acct=yes], [have_libnetfilter_acct=no] ) PKG_CHECK_MODULES( [LIBMNL], [libmnl], [have_libmnl=yes], [have_libmnl=no] ) test "${enable_plugin_nfacct}" = "yes" -a "${have_libnetfilter_acct}" != "yes" && \ AC_MSG_ERROR([netfilter_acct required but not found]) test "${enable_plugin_nfacct}" = "yes" -a "${have_libmnl}" != "yes" && \ AC_MSG_ERROR([libmnl required but not found. Try installing 'libmnl-dev' or 'libmnl-devel']) AC_MSG_CHECKING([if nfacct.plugin should be enabled]) if test "${enable_plugin_nfacct}" != "no" -a "${have_libnetfilter_acct}" = "yes" -a "${have_libmnl}" = "yes"; then enable_plugin_nfacct="yes" AC_DEFINE([HAVE_LIBMNL], [1], [libmnl usability]) AC_DEFINE([HAVE_LIBNETFILTER_ACCT], [1], [libnetfilter_acct usability]) AC_DEFINE([INTERNAL_PLUGIN_NFACCT], [1], [nfacct plugin usability]) OPTIONAL_NFACCT_CLFAGS="${NFACCT_CFLAGS} ${LIBMNL_CFLAGS}" OPTIONAL_NFACCT_LIBS="${NFACCT_LIBS} ${LIBMNL_LIBS}" else enable_plugin_nfacct="no" fi AC_MSG_RESULT([${enable_plugin_nfacct}]) AM_CONDITIONAL([ENABLE_PLUGIN_NFACCT], [test "${enable_plugin_nfacct}" = "yes"]) # ----------------------------------------------------------------------------- # check for setns() - cgroup-network AC_CHECK_FUNC([setns]) AC_MSG_CHECKING([if cgroup-network can be enabled]) if test "$ac_cv_func_setns" = "yes" ; then have_setns="yes" AC_DEFINE([HAVE_SETNS], [1], [Define 1 if you have setns() function]) else have_setns="no" fi AC_MSG_RESULT([${have_setns}]) AM_CONDITIONAL([ENABLE_PLUGIN_CGROUP_NETWORK], [test "${have_setns}" = "yes"]) # ----------------------------------------------------------------------------- # Link-Time-Optimization if test "${enable_lto}" != "no"; then opt="-flto" AX_CHECK_COMPILE_FLAG(${opt}, [have_lto=yes], [have_lto=no]) fi if test "${have_lto}" = "yes"; then oCFLAGS="${CFLAGS}" CFLAGS="${CFLAGS} -flto ${OPTIONAL_MATH_CLFAGS} ${OPTIONAL_NFACCT_CLFAGS} ${OPTIONAL_ZLIB_CLFAGS} ${OPTIONAL_UUID_CLFAGS} ${OPTIONAL_LIBCAP_CFLAGS} ${OPTIONAL_IPMIMONITORING_CFLAGS}" ac_cv_c_lto_cross_compile="${enable_lto}" test "${ac_cv_c_lto_cross_compile}" != "yes" && ac_cv_c_lto_cross_compile="no" AC_C_LTO CFLAGS="${oCFLAGS}" test "${ac_cv_c_lto}" != "yes" && have_lto="no" fi test "${enable_lto}" = "yes" -a "${have_lto}" != "yes" && \ AC_MSG_ERROR([LTO is required but is not available.]) AC_MSG_CHECKING([if LTO should be enabled]) if test "${enable_lto}" != "no" -a "${have_lto}" = "yes"; then enable_lto="yes" CFLAGS="${CFLAGS} -flto" else enable_lto="no" fi AC_MSG_RESULT([${enable_lto}]) # ----------------------------------------------------------------------------- AC_DEFINE_UNQUOTED([NETDATA_USER], ["${with_user}"], [use this user to drop privileged]) AC_SUBST([varlibdir], ["\$(localstatedir)/lib/netdata"]) AC_SUBST([registrydir], ["\$(localstatedir)/lib/netdata/registry"]) AC_SUBST([cachedir], ["\$(localstatedir)/cache/netdata"]) AC_SUBST([chartsdir], ["\$(libexecdir)/netdata/charts.d"]) AC_SUBST([nodedir], ["\$(libexecdir)/netdata/node.d"]) AC_SUBST([pythondir], ["\$(libexecdir)/netdata/python.d"]) AC_SUBST([configdir], ["\$(sysconfdir)/netdata"]) AC_SUBST([logdir], ["\$(localstatedir)/log/netdata"]) AC_SUBST([pluginsdir], ["\$(libexecdir)/netdata/plugins.d"]) AC_SUBST([webdir]) AC_SUBST([OPTIONAL_MATH_CLFAGS]) AC_SUBST([OPTIONAL_MATH_LIBS]) AC_SUBST([OPTIONAL_NFACCT_CLFAGS]) AC_SUBST([OPTIONAL_NFACCT_LIBS]) AC_SUBST([OPTIONAL_ZLIB_CLFAGS]) AC_SUBST([OPTIONAL_ZLIB_LIBS]) AC_SUBST([OPTIONAL_UUID_CLFAGS]) AC_SUBST([OPTIONAL_UUID_LIBS]) AC_SUBST([OPTIONAL_LIBCAP_CFLAGS]) AC_SUBST([OPTIONAL_LIBCAP_LIBS]) AC_SUBST([OPTIONAL_IPMIMONITORING_CFLAGS]) AC_SUBST([OPTIONAL_IPMIMONITORING_LIBS]) AC_CONFIG_FILES([ Makefile charts.d/Makefile conf.d/Makefile netdata.spec python.d/Makefile node.d/Makefile plugins.d/Makefile src/Makefile system/Makefile web/Makefile diagrams/Makefile makeself/Makefile contrib/Makefile tests/Makefile ]) AC_OUTPUT test "${with_math}" != "yes" && AC_MSG_WARN([You are building without math. math allows accurate calculations. It should be enabled.]) || : test "${with_zlib}" != "yes" && AC_MSG_WARN([You are building without zlib. zlib allows netdata to transfer a lot less data with web clients. It should be enabled.]) || :