// 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 ( "path/filepath" "testing" "github.com/spf13/afero" "github.com/spf13/hugo/helpers" "github.com/spf13/hugo/hugofs" "github.com/spf13/hugo/source" "github.com/spf13/hugo/target" "github.com/spf13/viper" ) func TestDefaultHandler(t *testing.T) { viper.Reset() defer viper.Reset() hugofs.DestinationFS = new(afero.MemMapFs) sources := []source.ByteSource{ {filepath.FromSlash("sect/doc1.html"), []byte("---\nmarkup: markdown\n---\n# title\nsome *content*")}, {filepath.FromSlash("sect/doc2.html"), []byte("
more content")}, {filepath.FromSlash("sect/doc3.md"), []byte("# doc3\n*some* content")}, {filepath.FromSlash("sect/doc4.md"), []byte("---\ntitle: doc4\n---\n# doc4\n*some content*")}, {filepath.FromSlash("sect/doc3/img1.png"), []byte("‰PNG ��� IHDR����������:~›U��� IDATWcø��ZMoñ����IEND®B`‚")}, {filepath.FromSlash("sect/img2.gif"), []byte("GIF89a��€��ÿÿÿ���,�������D�;")}, {filepath.FromSlash("sect/img2.spf"), []byte("****FAKE-FILETYPE****")}, {filepath.FromSlash("doc7.html"), []byte("doc7 content")}, {filepath.FromSlash("sect/doc8.html"), []byte("---\nmarkup: md\n---\n# title\nsome *content*")}, } viper.Set("DefaultExtension", "html") viper.Set("verbose", true) s := &Site{ Source: &source.InMemorySource{ByteSource: sources}, targets: targetList{page: &target.PagePub{UglyURLs: true}}, } s.initializeSiteInfo() // From site_test.go templatePrep(s) must(s.addTemplate("_default/single.html", "{{.Content}}")) must(s.addTemplate("head", "")) must(s.addTemplate("head_abs", "")) // From site_test.go createAndRenderPages(t, s) tests := []struct { doc string expected string }{ {filepath.FromSlash("sect/doc1.html"), "\n\nsome content
\n"}, {filepath.FromSlash("sect/doc2.html"), "more content"}, {filepath.FromSlash("sect/doc3.html"), "\n\nsome content
\n"}, {filepath.FromSlash("sect/doc3/img1.png"), string([]byte("‰PNG ��� IHDR����������:~›U��� IDATWcø��ZMoñ����IEND®B`‚"))}, {filepath.FromSlash("sect/img2.gif"), string([]byte("GIF89a��€��ÿÿÿ���,�������D�;"))}, {filepath.FromSlash("sect/img2.spf"), string([]byte("****FAKE-FILETYPE****"))}, {filepath.FromSlash("doc7.html"), "doc7 content"}, {filepath.FromSlash("sect/doc8.html"), "\n\nsome content
\n"}, } for _, test := range tests { file, err := hugofs.DestinationFS.Open(test.doc) if err != nil { t.Fatalf("Did not find %s in target.", test.doc) } content := helpers.ReaderToString(file) if content != test.expected { t.Errorf("%s content expected:\n%q\ngot:\n%q", test.doc, test.expected, content) } } }