hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

breaking_changes_test.go (3544B)

    1 // Copyright 2020 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 	"fmt"
   18 	"testing"
   19 
   20 	qt "github.com/frankban/quicktest"
   21 )
   22 
   23 func Test073(t *testing.T) {
   24 	assertDisabledTaxonomyAndTerm := func(b *sitesBuilder, taxonomy, term bool) {
   25 		b.Assert(b.CheckExists("public/tags/index.html"), qt.Equals, taxonomy)
   26 		b.Assert(b.CheckExists("public/tags/tag1/index.html"), qt.Equals, term)
   27 	}
   28 
   29 	assertOutputTaxonomyAndTerm := func(b *sitesBuilder, taxonomy, term bool) {
   30 		b.Assert(b.CheckExists("public/tags/index.json"), qt.Equals, taxonomy)
   31 		b.Assert(b.CheckExists("public/tags/tag1/index.json"), qt.Equals, term)
   32 	}
   33 
   34 	for _, this := range []struct {
   35 		name   string
   36 		config string
   37 		assert func(err error, out string, b *sitesBuilder)
   38 	}{
   39 		{
   40 			"Outputs for both taxonomy and taxonomyTerm",
   41 			`[outputs]
   42  taxonomy = ["JSON"]
   43  taxonomyTerm = ["JSON"]
   44 
   45 `,
   46 			func(err error, out string, b *sitesBuilder) {
   47 				b.Assert(err, qt.IsNil)
   48 				assertOutputTaxonomyAndTerm(b, true, true)
   49 			},
   50 		},
   51 		{
   52 			"Outputs for taxonomyTerm",
   53 			`[outputs]
   54 taxonomyTerm = ["JSON"]
   55 
   56 `,
   57 			func(err error, out string, b *sitesBuilder) {
   58 				b.Assert(err, qt.IsNil)
   59 				assertOutputTaxonomyAndTerm(b, true, false)
   60 			},
   61 		},
   62 		{
   63 			"Outputs for taxonomy only",
   64 			`[outputs]
   65 taxonomy = ["JSON"]
   66 
   67 `,
   68 			func(err error, out string, b *sitesBuilder) {
   69 				b.Assert(err, qt.Not(qt.IsNil))
   70 				b.Assert(out, qt.Contains, `ignoreErrors = ["error-output-taxonomy"]`)
   71 			},
   72 		},
   73 		{
   74 			"Outputs for taxonomy only, ignore error",
   75 			`
   76 ignoreErrors = ["error-output-taxonomy"]
   77 [outputs]
   78 taxonomy = ["JSON"]
   79 
   80 `,
   81 			func(err error, out string, b *sitesBuilder) {
   82 				b.Assert(err, qt.IsNil)
   83 				assertOutputTaxonomyAndTerm(b, true, false)
   84 			},
   85 		},
   86 		{
   87 			"Disable both taxonomy and taxonomyTerm",
   88 			`disableKinds = ["taxonomy", "taxonomyTerm"]`,
   89 			func(err error, out string, b *sitesBuilder) {
   90 				b.Assert(err, qt.IsNil)
   91 				assertDisabledTaxonomyAndTerm(b, false, false)
   92 			},
   93 		},
   94 		{
   95 			"Disable only taxonomyTerm",
   96 			`disableKinds = ["taxonomyTerm"]`,
   97 			func(err error, out string, b *sitesBuilder) {
   98 				b.Assert(err, qt.IsNil)
   99 				assertDisabledTaxonomyAndTerm(b, false, true)
  100 			},
  101 		},
  102 		{
  103 			"Disable only taxonomy",
  104 			`disableKinds = ["taxonomy"]`,
  105 			func(err error, out string, b *sitesBuilder) {
  106 				b.Assert(err, qt.Not(qt.IsNil))
  107 				b.Assert(out, qt.Contains, `ignoreErrors = ["error-disable-taxonomy"]`)
  108 			},
  109 		},
  110 		{
  111 			"Disable only taxonomy, ignore error",
  112 			`disableKinds = ["taxonomy"]
  113 			ignoreErrors = ["error-disable-taxonomy"]`,
  114 			func(err error, out string, b *sitesBuilder) {
  115 				b.Assert(err, qt.IsNil)
  116 				assertDisabledTaxonomyAndTerm(b, false, true)
  117 			},
  118 		},
  119 	} {
  120 		t.Run(this.name, func(t *testing.T) {
  121 			b := newTestSitesBuilder(t).WithConfigFile("toml", this.config)
  122 			b.WithTemplatesAdded("_default/list.json", "JSON")
  123 			out, err := captureStdout(func() error {
  124 				return b.BuildE(BuildCfg{})
  125 			})
  126 			fmt.Println(out)
  127 			this.assert(err, out, b)
  128 		})
  129 	}
  130 }