github.com/olliephillips/hugo@v0.42.2/hugolib/rss_test.go (about)

     1  // Copyright 2016 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  	"path/filepath"
    18  	"strings"
    19  	"testing"
    20  
    21  	"github.com/gohugoio/hugo/deps"
    22  )
    23  
    24  func TestRSSOutput(t *testing.T) {
    25  	t.Parallel()
    26  	var (
    27  		cfg, fs = newTestCfg()
    28  		th      = testHelper{cfg, fs, t}
    29  	)
    30  
    31  	rssLimit := len(weightedSources) - 1
    32  
    33  	rssURI := "customrss.xml"
    34  
    35  	cfg.Set("baseURL", "http://auth/bub/")
    36  	cfg.Set("rssURI", rssURI)
    37  	cfg.Set("title", "RSSTest")
    38  	cfg.Set("rssLimit", rssLimit)
    39  
    40  	for _, src := range weightedSources {
    41  		writeSource(t, fs, filepath.Join("content", "sect", src[0]), src[1])
    42  	}
    43  
    44  	buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
    45  
    46  	// Home RSS
    47  	th.assertFileContent(filepath.Join("public", rssURI), "<?xml", "rss version", "RSSTest")
    48  	// Section RSS
    49  	th.assertFileContent(filepath.Join("public", "sect", rssURI), "<?xml", "rss version", "Sects on RSSTest")
    50  	// Taxonomy RSS
    51  	th.assertFileContent(filepath.Join("public", "categories", "hugo", rssURI), "<?xml", "rss version", "Hugo on RSSTest")
    52  
    53  	// RSS Item Limit
    54  	content := readDestination(t, fs, filepath.Join("public", rssURI))
    55  	c := strings.Count(content, "<item>")
    56  	if c != rssLimit {
    57  		t.Errorf("incorrect RSS item count: expected %d, got %d", rssLimit, c)
    58  	}
    59  }