Example #1
0
func TestMenuURL(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	s := setupMenuTests(t, MENU_PAGE_SOURCES)

	for i, this := range []struct {
		me          *MenuEntry
		expectedURL string
	}{
		// issue #888
		{findTestMenuEntryByID(s, "hash", "hash"), "/Zoo/resource#anchor"},
		// issue #1774
		{findTestMenuEntryByID(s, "main", "ext"), "http://gohugo.io"},
		{findTestMenuEntryByID(s, "main", "ext2"), "http://foo.local/Zoo/foo"},
	} {

		if this.me == nil {
			t.Errorf("[%d] MenuEntry not found", i)
			continue
		}

		if this.me.URL != this.expectedURL {
			t.Errorf("[%d] Got URL %s expected %s", i, this.me.URL, this.expectedURL)
		}

	}

}
Example #2
0
func TestMakePath(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	tests := []struct {
		input         string
		expected      string
		removeAccents bool
	}{
		{"  Foo bar  ", "Foo-bar", true},
		{"Foo.Bar/foo_Bar-Foo", "Foo.Bar/foo_Bar-Foo", true},
		{"fOO,bar:foo%bAR", "fOObarfoobAR", true},
		{"FOo/BaR.html", "FOo/BaR.html", true},
		{"трям/трям", "трям/трям", true},
		{"은행", "은행", true},
		{"Банковский кассир", "Банковскии-кассир", true},
		// Issue #1488
		{"संस्कृत", "संस्कृत", false},
	}

	for _, test := range tests {
		viper.Set("RemovePathAccents", test.removeAccents)
		output := MakePath(test.input)
		if output != test.expected {
			t.Errorf("Expected %#v, got %#v\n", test.expected, output)
		}
	}
}
Example #3
0
func TestHighlight(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	if !helpers.HasPygments() {
		t.Skip("Skip test as Pygments is not installed")
	}
	viper.Set("PygmentsStyle", "bw")
	viper.Set("PygmentsUseClasses", false)

	templ := tpl.New()

	code := `
{{< highlight java >}}
void do();
{{< /highlight >}}`

	p, _ := pageFromString(simplePage, "simple.md")
	output, err := HandleShortcodes(code, p, templ)

	if err != nil {
		t.Fatal("Handle shortcode error", err)
	}
	matched, err := regexp.MatchString("(?s)^\n<div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\">.*?void</span> do().*?</pre></div>\n$", output)

	if err != nil {
		t.Fatal("Regexp error", err)
	}

	if !matched {
		t.Error("Hightlight mismatch, got\n", output)
	}
}
Example #4
0
func TestByCountOrderOfTaxonomies(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	taxonomies := make(map[string]string)

	taxonomies["tag"] = "tags"
	taxonomies["category"] = "categories"

	viper.Set("taxonomies", taxonomies)

	site := new(Site)
	page, _ := NewPageFrom(strings.NewReader(pageYamlWithTaxonomiesA), "path/to/page")
	site.Pages = append(site.Pages, page)
	site.assembleTaxonomies()

	st := make([]string, 0)
	for _, t := range site.Taxonomies["tags"].ByCount() {
		st = append(st, t.Name)
	}

	if !compareStringSlice(st, []string{"a", "b", "c"}) {
		t.Fatalf("ordered taxonomies do not match [a, b, c].  Got: %s", st)
	}
}
Example #5
0
func TestMakePathSanitizedDisablePathToLower(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	initCommonTestConfig()
	viper.Set("disablePathToLower", true)
	p := NewPathSpecFromConfig(viper.GetViper())

	tests := []struct {
		input    string
		expected string
	}{
		{"  FOO bar  ", "FOO-bar"},
		{"Foo.Bar/fOO_bAr-Foo", "Foo.Bar/fOO_bAr-Foo"},
		{"FOO,bar:FooBar", "FOObarFooBar"},
		{"foo/BAR.HTML", "foo/BAR.HTML"},
		{"трям/трям", "трям/трям"},
		{"은행", "은행"},
	}

	for _, test := range tests {
		output := p.MakePathSanitized(test.input)
		if output != test.expected {
			t.Errorf("Expected %#v, got %#v\n", test.expected, output)
		}
	}
}
Example #6
0
// Issue #1934
func TestYAMLMenuWithMultipleEntries(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	ps1 := []byte(`---
title: "Yaml 1"
weight: 5
menu: ["p_one", "p_two"]
---
Yaml Front Matter with Menu Pages`)

	ps2 := []byte(`---
title: "Yaml 2"
weight: 5
menu:
    p_three:
    p_four:
---
Yaml Front Matter with Menu Pages`)

	s := setupMenuTests(t, []source.ByteSource{
		{filepath.FromSlash("sect/yaml1.md"), ps1},
		{filepath.FromSlash("sect/yaml2.md"), ps2}})

	p1 := s.Pages[0]
	assert.Len(t, p1.Menus(), 2, "List YAML")
	p2 := s.Pages[1]
	assert.Len(t, p2.Menus(), 2, "Map YAML")

}
Example #7
0
// Issue #1797
func TestReadPagesFromSourceWithEmptySource(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	viper.Set("DefaultExtension", "html")
	viper.Set("verbose", true)
	viper.Set("baseurl", "http://auth/bub")

	sources := []source.ByteSource{}

	s := &Site{
		Source:  &source.InMemorySource{ByteSource: sources},
		targets: targetList{page: &target.PagePub{UglyURLs: true}},
	}

	var err error
	d := time.Second * 2
	ticker := time.NewTicker(d)
	select {
	case err = <-s.ReadPagesFromSource():
		break
	case <-ticker.C:
		err = fmt.Errorf("ReadPagesFromSource() never returns in %s", d.String())
	}
	ticker.Stop()
	if err != nil {
		t.Fatalf("Unable to read source: %s", err)
	}
}
Example #8
0
func TestAbsURL(t *testing.T) {
	defer viper.Reset()
	tests := []struct {
		input    string
		baseURL  string
		expected string
	}{
		{"/test/foo", "http://base/", "http://base/test/foo"},
		{"", "http://base/ace/", "http://base/ace/"},
		{"/test/2/foo/", "http://base", "http://base/test/2/foo/"},
		{"http://abs", "http://base/", "http://abs"},
		{"schema://abs", "http://base/", "schema://abs"},
		{"//schemaless", "http://base/", "//schemaless"},
		{"test/2/foo/", "http://base/path", "http://base/path/test/2/foo/"},
		{"/test/2/foo/", "http://base/path", "http://base/test/2/foo/"},
		{"http//foo", "http://base/path", "http://base/path/http/foo"},
	}

	for _, test := range tests {
		viper.Reset()
		viper.Set("BaseURL", test.baseURL)
		output := AbsURL(test.input)
		if output != test.expected {
			t.Errorf("Expected %#v, got %#v\n", test.expected, output)
		}
	}
}
Example #9
0
func TestSiteInfoParams(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	viper.Set("Params", map[string]interface{}{"MyGlobalParam": "FOOBAR_PARAM"})
	s := &Site{}

	s.initialize()
	if s.Info.Params["MyGlobalParam"] != "FOOBAR_PARAM" {
		t.Errorf("Unable to set site.Info.Param")
	}

	s.prepTemplates("template", SITE_INFO_PARAM_TEMPLATE)

	buf := new(bytes.Buffer)

	err := s.renderThing(s.NewNode(), "template", buf)
	if err != nil {
		t.Errorf("Unable to render template: %s", err)
	}

	if buf.String() != "FOOBAR_PARAM" {
		t.Errorf("Expected FOOBAR_PARAM: got %s", buf.String())
	}
}
Example #10
0
func TestRelURL(t *testing.T) {
	defer viper.Reset()
	//defer viper.Set("canonifyURLs", viper.GetBool("canonifyURLs"))
	tests := []struct {
		input    string
		baseURL  string
		canonify bool
		expected string
	}{
		{"/test/foo", "http://base/", false, "/test/foo"},
		{"test.css", "http://base/sub", false, "/sub/test.css"},
		{"test.css", "http://base/sub", true, "/test.css"},
		{"/test/", "http://base/", false, "/test/"},
		{"/test/", "http://base/sub/", false, "/sub/test/"},
		{"/test/", "http://base/sub/", true, "/test/"},
		{"", "http://base/ace/", false, "/ace/"},
		{"", "http://base/ace", false, "/ace"},
		{"http://abs", "http://base/", false, "http://abs"},
		{"//schemaless", "http://base/", false, "//schemaless"},
	}

	for i, test := range tests {
		viper.Reset()
		viper.Set("BaseURL", test.baseURL)
		viper.Set("canonifyURLs", test.canonify)

		output := RelURL(test.input)
		if output != test.expected {
			t.Errorf("[%d][%t] Expected %#v, got %#v\n", i, test.canonify, test.expected, output)
		}
	}
}
Example #11
0
func TestMakePath(t *testing.T) {
	viper.Reset()
	defer viper.Reset()
	initCommonTestConfig()

	tests := []struct {
		input         string
		expected      string
		removeAccents bool
	}{
		{"  Foo bar  ", "Foo-bar", true},
		{"Foo.Bar/foo_Bar-Foo", "Foo.Bar/foo_Bar-Foo", true},
		{"fOO,bar:foobAR", "fOObarfoobAR", true},
		{"FOo/BaR.html", "FOo/BaR.html", true},
		{"трям/трям", "трям/трям", true},
		{"은행", "은행", true},
		{"Банковский кассир", "Банковскии-кассир", true},
		// Issue #1488
		{"संस्कृत", "संस्कृत", false},
		{"a%C3%B1ame", "a%C3%B1ame", false},         // Issue #1292
		{"this+is+a+test", "this+is+a+test", false}, // Issue #1290
	}

	for _, test := range tests {
		viper.Set("removePathAccents", test.removeAccents)
		p := NewPathSpecFromConfig(viper.GetViper())
		output := p.MakePath(test.input)
		if output != test.expected {
			t.Errorf("Expected %#v, got %#v\n", test.expected, output)
		}
	}
}
Example #12
0
func TestDraftAndFutureRender(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	hugofs.DestinationFS = new(afero.MemMapFs)
	sources := []source.ByteSource{
		{filepath.FromSlash("sect/doc1.md"), []byte("---\ntitle: doc1\ndraft: true\npublishdate: \"2414-05-29\"\n---\n# doc1\n*some content*")},
		{filepath.FromSlash("sect/doc2.md"), []byte("---\ntitle: doc2\ndraft: true\npublishdate: \"2012-05-29\"\n---\n# doc2\n*some content*")},
		{filepath.FromSlash("sect/doc3.md"), []byte("---\ntitle: doc3\ndraft: false\npublishdate: \"2414-05-29\"\n---\n# doc3\n*some content*")},
		{filepath.FromSlash("sect/doc4.md"), []byte("---\ntitle: doc4\ndraft: false\npublishdate: \"2012-05-29\"\n---\n# doc4\n*some content*")},
	}

	siteSetup := func() *Site {
		s := &Site{
			Source: &source.InMemorySource{ByteSource: sources},
		}

		s.initializeSiteInfo()

		if err := s.CreatePages(); err != nil {
			t.Fatalf("Unable to create pages: %s", err)
		}
		return s
	}

	viper.Set("baseurl", "http://auth/bub")

	// Testing Defaults.. Only draft:true and publishDate in the past should be rendered
	s := siteSetup()
	if len(s.Pages) != 1 {
		t.Fatal("Draft or Future dated content published unexpectedly")
	}

	// only publishDate in the past should be rendered
	viper.Set("BuildDrafts", true)
	s = siteSetup()
	if len(s.Pages) != 2 {
		t.Fatal("Future Dated Posts published unexpectedly")
	}

	//  drafts should not be rendered, but all dates should
	viper.Set("BuildDrafts", false)
	viper.Set("BuildFuture", true)
	s = siteSetup()
	if len(s.Pages) != 2 {
		t.Fatal("Draft posts published unexpectedly")
	}

	// all 4 should be included
	viper.Set("BuildDrafts", true)
	viper.Set("BuildFuture", true)
	s = siteSetup()
	if len(s.Pages) != 4 {
		t.Fatal("Drafts or Future posts not included as expected")
	}

	//setting defaults back
	viper.Set("BuildDrafts", false)
	viper.Set("BuildFuture", false)
}
Example #13
0
func TestOrderedPages(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	hugofs.DestinationFS = new(afero.MemMapFs)

	viper.Set("baseurl", "http://auth/bub")
	s := &Site{
		Source: &source.InMemorySource{ByteSource: WEIGHTED_SOURCES},
	}
	s.initializeSiteInfo()

	if err := s.CreatePages(); err != nil {
		t.Fatalf("Unable to create pages: %s", err)
	}

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

	if s.Sections["sect"][0].Weight != 2 || s.Sections["sect"][3].Weight != 6 {
		t.Errorf("Pages in unexpected order. First should be '%d', got '%d'", 2, s.Sections["sect"][0].Weight)
	}

	if s.Sections["sect"][1].Page.Title != "Three" || s.Sections["sect"][2].Page.Title != "Four" {
		t.Errorf("Pages in unexpected order. Second should be '%s', got '%s'", "Three", s.Sections["sect"][1].Page.Title)
	}

	bydate := s.Pages.ByDate()

	if bydate[0].Title != "One" {
		t.Errorf("Pages in unexpected order. First should be '%s', got '%s'", "One", bydate[0].Title)
	}

	rev := bydate.Reverse()
	if rev[0].Title != "Three" {
		t.Errorf("Pages in unexpected order. First should be '%s', got '%s'", "Three", rev[0].Title)
	}

	bypubdate := s.Pages.ByPublishDate()

	if bypubdate[0].Title != "One" {
		t.Errorf("Pages in unexpected order. First should be '%s', got '%s'", "One", bypubdate[0].Title)
	}

	rbypubdate := bypubdate.Reverse()
	if rbypubdate[0].Title != "Three" {
		t.Errorf("Pages in unexpected order. First should be '%s', got '%s'", "Three", rbypubdate[0].Title)
	}

	bylength := s.Pages.ByLength()
	if bylength[0].Title != "One" {
		t.Errorf("Pages in unexpected order. First should be '%s', got '%s'", "One", bylength[0].Title)
	}

	rbylength := bylength.Reverse()
	if rbylength[0].Title != "Four" {
		t.Errorf("Pages in unexpected order. First should be '%s', got '%s'", "Four", rbylength[0].Title)
	}
}
Example #14
0
func doTestMenuWithUnicodeURLs(t *testing.T, canonifyURLs, uglyURLs bool) {
	viper.Reset()
	defer viper.Reset()

	viper.Set("CanonifyURLs", canonifyURLs)
	viper.Set("UglyURLs", uglyURLs)

	s := setupMenuTests(t, MENU_PAGE_SOURCES)

	unicodeRussian := findTestMenuEntryByID(s, "unicode", "unicode-russian")

	expectedBase := "/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8-%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B0"

	if !canonifyURLs {
		expectedBase = "/Zoo" + expectedBase
	}

	var expected string
	if uglyURLs {
		expected = expectedBase + ".html"
	} else {
		expected = expectedBase + "/"
	}

	assert.Equal(t, expected, unicodeRussian.URL, "uglyURLs[%t]", uglyURLs)
}
Example #15
0
func TestPaginate(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	for _, useViper := range []bool{false, true} {
		doTestPaginate(t, useViper)
	}
}
Example #16
0
func TestPaginateWithNegativePaginate(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	viper.Set("paginate", -1)
	s := &Site{}
	_, err := s.newHomeNode().Paginate(createTestPages(2))
	assert.NotNil(t, err)
}
Example #17
0
// Issue #1114
func TestSectionPagesMenu(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	viper.Set("SectionPagesMenu", "spm")

	doTestSectionPagesMenu(true, t)
	doTestSectionPagesMenu(false, t)
}
Example #18
0
func doTestSectionPagesMenu(canonifyUrls bool, t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	viper.Set("SectionPagesMenu", "spm")

	viper.Set("CanonifyURLs", canonifyUrls)
	s := setupMenuTests(t, MENU_PAGE_SECTIONS_SOURCES)

	assert.Equal(t, 3, len(s.Sections))

	firstSectionPages := s.Sections["first"]
	assert.Equal(t, 2, len(firstSectionPages))
	secondSectionPages := s.Sections["second-section"]
	assert.Equal(t, 1, len(secondSectionPages))
	fishySectionPages := s.Sections["fish-and-chips"]
	assert.Equal(t, 1, len(fishySectionPages))

	nodeFirst := s.newSectionListNode("First", "first", firstSectionPages)
	nodeSecond := s.newSectionListNode("Second Section", "second-section", secondSectionPages)
	nodeFishy := s.newSectionListNode("Fish and Chips", "fish-and-chips", fishySectionPages)
	firstSectionMenuEntry := findTestMenuEntryByID(s, "spm", "first")
	secondSectionMenuEntry := findTestMenuEntryByID(s, "spm", "second-section")
	fishySectionMenuEntry := findTestMenuEntryByID(s, "spm", "Fish and Chips")

	assert.NotNil(t, firstSectionMenuEntry)
	assert.NotNil(t, secondSectionMenuEntry)
	assert.NotNil(t, nodeFirst)
	assert.NotNil(t, nodeSecond)
	assert.NotNil(t, fishySectionMenuEntry)
	assert.NotNil(t, nodeFishy)

	firstSectionMenuEntry.URL = firstSectionMenuEntry.URL + "/"
	secondSectionMenuEntry.URL = secondSectionMenuEntry.URL + "/"
	fishySectionMenuEntry.URL = fishySectionMenuEntry.URL + "/"
	assert.True(t, nodeFirst.IsMenuCurrent("spm", firstSectionMenuEntry))
	assert.False(t, nodeFirst.IsMenuCurrent("spm", secondSectionMenuEntry))
	assert.False(t, nodeFirst.IsMenuCurrent("spm", fishySectionMenuEntry))
	assert.True(t, nodeFishy.IsMenuCurrent("spm", fishySectionMenuEntry))
	assert.Equal(t, "Fish and Chips", fishySectionMenuEntry.Name)

	for _, p := range firstSectionPages {
		assert.True(t, p.Page.HasMenuCurrent("spm", firstSectionMenuEntry))
		assert.False(t, p.Page.HasMenuCurrent("spm", secondSectionMenuEntry))
	}

	for _, p := range secondSectionPages {
		assert.False(t, p.Page.HasMenuCurrent("spm", firstSectionMenuEntry))
		assert.True(t, p.Page.HasMenuCurrent("spm", secondSectionMenuEntry))
	}

	for _, p := range fishySectionPages {
		assert.False(t, p.Page.HasMenuCurrent("spm", firstSectionMenuEntry))
		assert.False(t, p.Page.HasMenuCurrent("spm", secondSectionMenuEntry))
		assert.True(t, p.Page.HasMenuCurrent("spm", fishySectionMenuEntry))
	}
}
Example #19
0
// issue #719
func TestMenuWithUnicodeURLs(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	for _, uglyURLs := range []bool{true, false} {
		for _, canonifyURLs := range []bool{true, false} {
			doTestMenuWithUnicodeURLs(t, canonifyURLs, uglyURLs)
		}
	}
}
Example #20
0
func TestWorkingDir(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	viper.Set("workingDir", "/a/b/")

	InitMemFs()

	assert.NotNil(t, WorkingDir())
	assert.IsType(t, new(afero.BasePathFs), WorkingDir())
}
Example #21
0
// issue #888
func TestMenuWithHashInURL(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	s := setupMenuTests(t, MENU_PAGE_SOURCES)

	me := findTestMenuEntryByID(s, "hash", "hash")

	assert.NotNil(t, me)

	assert.Equal(t, "/Zoo/resource/#anchor", me.URL)
}
Example #22
0
func TestInitMemFs(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	InitMemFs()

	assert.NotNil(t, Source())
	assert.IsType(t, new(afero.MemMapFs), Source())
	assert.NotNil(t, Destination())
	assert.IsType(t, new(afero.MemMapFs), Destination())
	assert.IsType(t, new(afero.OsFs), Os())
	assert.Nil(t, WorkingDir())
}
Example #23
0
func TestPageCount(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	hugofs.DestinationFS = new(afero.MemMapFs)

	viper.Set("uglyurls", false)
	viper.Set("paginate", 10)
	s := &Site{
		Source: &source.InMemorySource{ByteSource: urlFakeSource},
	}
	s.initializeSiteInfo()
	s.prepTemplates()
	must(s.addTemplate("indexes/blue.html", INDEX_TEMPLATE))

	if err := s.CreatePages(); err != nil {
		t.Errorf("Unable to create pages: %s", err)
	}
	if err := s.BuildSiteMeta(); err != nil {
		t.Errorf("Unable to build site metadata: %s", err)
	}

	if err := s.RenderSectionLists(); err != nil {
		t.Errorf("Unable to render section lists: %s", err)
	}

	if err := s.RenderAliases(); err != nil {
		t.Errorf("Unable to render site lists: %s", err)
	}

	_, err := hugofs.DestinationFS.Open("blue")
	if err != nil {
		t.Errorf("No indexed rendered.")
	}

	//expected := ".."
	//if string(blueIndex) != expected {
	//t.Errorf("Index template does not match expected: %q, got: %q", expected, string(blueIndex))
	//}

	for _, s := range []string{
		"sd1/foo/index.html",
		"sd2/index.html",
		"sd3/index.html",
		"sd4.html",
	} {
		if _, err := hugofs.DestinationFS.Open(filepath.FromSlash(s)); err != nil {
			t.Errorf("No alias rendered: %s", s)
		}
	}
}
Example #24
0
func TestSiteInfoPermalinks(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	viper.Set("Permalinks", map[string]interface{}{"section": "/:title"})
	s := &Site{}

	s.initialize()
	permalink := s.Info.Permalinks["section"]

	if permalink != "/:title" {
		t.Errorf("Could not set permalink (%#v)", permalink)
	}
}
Example #25
0
func TestPaginationURLFactory(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	viper.Set("PaginatePath", "zoo")
	unicode := newPaginationURLFactory("новости проекта")
	fooBar := newPaginationURLFactory("foo", "bar")

	assert.Equal(t, "/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8-%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B0/", unicode(1))
	assert.Equal(t, "/foo/bar/", fooBar(1))
	assert.Equal(t, "/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8-%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B0/zoo/4/", unicode(4))
	assert.Equal(t, "/foo/bar/zoo/12345/", fooBar(12345))

}
Example #26
0
func TestGitHubFileLinking(t *testing.T) {
	viper.Reset()
	defer viper.Reset()
	site := setupLinkingMockSite(t)

	type resultMap map[string]string

	okresults := map[string]resultMap{
		"index.md": map[string]string{
			"/root-image.png": "/root-image.png",
			"root-image.png":  "/root-image.png",
		}, "rootfile.md": map[string]string{
			"/root-image.png": "/root-image.png",
		}, "level2/2-root.md": map[string]string{
			"/root-image.png": "/root-image.png",
			"common.png":      "/level2/common.png",
		}, "level2/index.md": map[string]string{
			"/root-image.png": "/root-image.png",
			"common.png":      "/level2/common.png",
			"./common.png":    "/level2/common.png",
		}, "level2/level3/3-root.md": map[string]string{
			"/root-image.png": "/root-image.png",
			"common.png":      "/level2/level3/common.png",
			"../common.png":   "/level2/common.png",
		}, "level2/level3/index.md": map[string]string{
			"/root-image.png": "/root-image.png",
			"common.png":      "/level2/level3/common.png",
			"../common.png":   "/level2/common.png",
		},
	}

	for currentFile, results := range okresults {
		currentPage := findPage(site, currentFile)
		if currentPage == nil {
			t.Fatalf("failed to find current page in site")
		}
		for link, url := range results {
			if out, err := site.Info.githubFileLink(link, currentPage, false); err != nil || out != url {
				t.Errorf("Expected %s to resolve to (%s), got (%s) - error: %s", link, url, out, err)
			} else {
				//t.Logf("tested ok %s maps to %s", link, out)
			}
		}
	}
	// TODO: and then the failure cases.
	// 			"https://docker.com":           "",
	// site_test.go:1094: Expected https://docker.com to resolve to (), got () - error: Not a plain filepath link (https://docker.com)

}
Example #27
0
func TestRobotsTXTOutput(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	hugofs.DestinationFS = new(afero.MemMapFs)

	viper.Set("baseurl", "http://auth/bub/")

	s := &Site{
		Source: &source.InMemorySource{ByteSource: WEIGHTED_SOURCES},
	}

	s.initializeSiteInfo()

	s.prepTemplates()
	s.addTemplate("robots.txt", ROBOTSTXT_TEMPLATE)

	if err := s.CreatePages(); err != nil {
		t.Fatalf("Unable to create pages: %s", err)
	}

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

	if err := s.RenderHomePage(); err != nil {
		t.Fatalf("Unable to RenderHomePage: %s", err)
	}

	if err := s.RenderSitemap(); err != nil {
		t.Fatalf("Unable to RenderSitemap: %s", err)
	}

	if err := s.RenderRobotsTXT(); err != nil {
		t.Fatalf("Unable to RenderRobotsTXT :%s", err)
	}

	robotsFile, err := hugofs.DestinationFS.Open("robots.txt")

	if err != nil {
		t.Fatalf("Unable to locate: robots.txt")
	}

	robots := helpers.ReaderToBytes(robotsFile)
	if !bytes.HasPrefix(robots, []byte("User-agent: Googlebot")) {
		t.Errorf("Robots file should start with 'User-agentL Googlebot'. %s", robots)
	}
}
Example #28
0
func TestSitemapOutput(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	hugofs.DestinationFS = new(afero.MemMapFs)

	viper.Set("baseurl", "http://auth/bub/")

	s := &Site{
		Source: &source.InMemorySource{ByteSource: WEIGHTED_SOURCES},
	}

	s.initializeSiteInfo()

	s.prepTemplates()
	s.addTemplate("sitemap.xml", SITEMAP_TEMPLATE)

	if err := s.CreatePages(); err != nil {
		t.Fatalf("Unable to create pages: %s", err)
	}

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

	if err := s.RenderHomePage(); err != nil {
		t.Fatalf("Unable to RenderHomePage: %s", err)
	}

	if err := s.RenderSitemap(); err != nil {
		t.Fatalf("Unable to RenderSitemap: %s", err)
	}

	if err := s.RenderRobotsTXT(); err != nil {
		t.Fatalf("Unable to RenderRobotsTXT :%s", err)
	}

	sitemapFile, err := hugofs.DestinationFS.Open("sitemap.xml")

	if err != nil {
		t.Fatalf("Unable to locate: sitemap.xml")
	}

	sitemap := helpers.ReaderToBytes(sitemapFile)
	if !bytes.HasPrefix(sitemap, []byte("<?xml")) {
		t.Errorf("Sitemap file should start with <?xml. %s", sitemap)
	}
}
Example #29
0
func TestRobotsTXTOutput(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	hugofs.InitMemFs()

	viper.Set("baseurl", "http://auth/bub/")
	viper.Set("enableRobotsTXT", true)

	s := &Site{
		Source: &source.InMemorySource{ByteSource: weightedSources},
	}

	s.initializeSiteInfo()

	s.prepTemplates("robots.txt", robotTxtTemplate)

	if err := s.createPages(); err != nil {
		t.Fatalf("Unable to create pages: %s", err)
	}

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

	if err := s.renderHomePage(); err != nil {
		t.Fatalf("Unable to RenderHomePage: %s", err)
	}

	if err := s.renderSitemap(); err != nil {
		t.Fatalf("Unable to RenderSitemap: %s", err)
	}

	if err := s.renderRobotsTXT(); err != nil {
		t.Fatalf("Unable to RenderRobotsTXT :%s", err)
	}

	robotsFile, err := hugofs.Destination().Open("robots.txt")

	if err != nil {
		t.Fatalf("Unable to locate: robots.txt")
	}

	robots := helpers.ReaderToBytes(robotsFile)
	if !bytes.HasPrefix(robots, []byte("User-agent: Googlebot")) {
		t.Errorf("Robots file should start with 'User-agentL Googlebot'. %s", robots)
	}
}
Example #30
0
func TestLoggingLevelDefault(t *testing.T) {
	viper.Reset()

	flogging.LoggingInit("")

	assertDefaultLoggingLevel(t, flogging.DefaultLoggingLevel())
}