github.com/lyeb/hugo@v0.47.1/hugolib/siteJSONEncode_test.go (about)

     1  // Copyright 2015 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  	"encoding/json"
    18  	"testing"
    19  
    20  	"path/filepath"
    21  
    22  	"github.com/gohugoio/hugo/deps"
    23  )
    24  
    25  // Issue #1123
    26  // Testing prevention of cyclic refs in JSON encoding
    27  // May be smart to run with: -timeout 4000ms
    28  func TestEncodePage(t *testing.T) {
    29  	t.Parallel()
    30  	cfg, fs := newTestCfg()
    31  
    32  	writeSource(t, fs, filepath.Join("content", "page.md"), `---
    33  title: Simple
    34  ---
    35  Summary text
    36  
    37  <!--more-->
    38  `)
    39  
    40  	s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
    41  
    42  	_, err := json.Marshal(s)
    43  	check(t, err)
    44  
    45  	_, err = json.Marshal(s.RegularPages[0])
    46  	check(t, err)
    47  }
    48  
    49  func check(t *testing.T, err error) {
    50  	if err != nil {
    51  		t.Fatalf("Failed %s", err)
    52  	}
    53  }