summaryrefslogtreecommitdiffstats
path: root/hugolib/siteJSONEncode_test.go
diff options
context:
space:
mode:
authorbep <bjorn.erik.pedersen@gmail.com>2015-05-23 12:28:01 +0200
committerbep <bjorn.erik.pedersen@gmail.com>2015-05-23 12:28:08 +0200
commitbe7c3bbb097eb104c7029d742c6501c5d18d8684 (patch)
tree4b0c5ab41e2f464a13d9be6e0c44369e129ea1eb /hugolib/siteJSONEncode_test.go
parentbe778c31606b08e7320cafb6082700e4240be2fd (diff)
Prevent cyclic ref crash in JSON encode
Note that this commit makes no promise about great JSON output from the encoder, but the cyclic refs should be broken. Fixes #1123
Diffstat (limited to 'hugolib/siteJSONEncode_test.go')
-rw-r--r--hugolib/siteJSONEncode_test.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/hugolib/siteJSONEncode_test.go b/hugolib/siteJSONEncode_test.go
new file mode 100644
index 000000000..7c4bb48e3
--- /dev/null
+++ b/hugolib/siteJSONEncode_test.go
@@ -0,0 +1,32 @@
+package hugolib
+
+import (
+ "encoding/json"
+ "fmt"
+ "testing"
+)
+
+// Issue #1123
+// Testing prevention of cyclic refs in JSON encoding
+// May be smart to run with: -timeout 4000ms
+func TestEncodePage(t *testing.T) {
+
+ // borrowed from menu_test.go
+ s := createTestSite(MENU_PAGE_SOURCES)
+ testSiteSetup(s, t)
+
+ j, err := json.Marshal(s)
+ check(t, err)
+ fmt.Println("Site as JSON", string(j))
+
+ p, err := json.Marshal(s.Pages[0])
+ check(t, err)
+ fmt.Println("Page as JSON", string(p))
+
+}
+
+func check(t *testing.T, err error) {
+ if err != nil {
+ t.Fatalf("Failed %s", err)
+ }
+}