From 21e2acd4a5236d3926bfa89c15113cd26b70058c Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Tue, 17 Feb 2015 01:34:30 -0800 Subject: [PATCH 1/3] flow: Created branch 'feature/make_json_pretty'. From 1a66b03d0d4504f5fe261c541ecb5a7cf0eea366 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Tue, 17 Feb 2015 01:50:39 -0800 Subject: [PATCH 2/3] add indentation to json output. update test. --- src/docrawler/docrawler_test.go | 33 ++++++++++++++++++++++++++++++++- src/docrawler/output.go | 2 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/docrawler/docrawler_test.go b/src/docrawler/docrawler_test.go index a5a22e9..60bd8cc 100644 --- a/src/docrawler/docrawler_test.go +++ b/src/docrawler/docrawler_test.go @@ -229,7 +229,38 @@ func TestJsonOutput(t *testing.T) { // this is a cheater test because the output is from a run of the code being // test itself. but, it's been examined and I think it's right. and, there's not // many other ways to test this without some significant pain - cheaterTest := `[{"URL":"http://localhost:8765/","Title":"Home","Links":["http://localhost:8765/about.html"],"Assets":["http://localhost:8765/assets/image.png","http://localhost:8765/scripts/blah.js"],"Broken":["http://localhost:8765/zzzbroken.html"],"Remote":null},{"URL":"http://localhost:8765/about.html","Title":"About Test","Links":["http://localhost:8765/"],"Assets":["http://localhost:8765/assets/image.png","http://localhost:8765/scripts/blah.js"],"Broken":null,"Remote":["http://doesntexist23492387492837492374982734.com/"]}]` + cheaterTest := `[ + { + "URL": "http://localhost:8765/", + "Title": "Home", + "Links": [ + "http://localhost:8765/about.html" + ], + "Assets": [ + "http://localhost:8765/assets/image.png", + "http://localhost:8765/scripts/blah.js" + ], + "Broken": [ + "http://localhost:8765/zzzbroken.html" + ], + "Remote": null + }, + { + "URL": "http://localhost:8765/about.html", + "Title": "About Test", + "Links": [ + "http://localhost:8765/" + ], + "Assets": [ + "http://localhost:8765/assets/image.png", + "http://localhost:8765/scripts/blah.js" + ], + "Broken": null, + "Remote": [ + "http://doesntexist23492387492837492374982734.com/" + ] + } +]` j, err := locationsToJSON(l) if err != nil { t.Error("locationsToJSON failed") diff --git a/src/docrawler/output.go b/src/docrawler/output.go index 6691499..15a5ccc 100644 --- a/src/docrawler/output.go +++ b/src/docrawler/output.go @@ -79,7 +79,7 @@ func sitemapToLocations(pages itemSlice) []*Location { // locationsToJSON takes a *Location slice and marshals it into a JSON string func locationsToJSON(locations []*Location) (string, error) { - b, err := json.Marshal(locations) + b, err := json.MarshalIndent(locations, "", " ") if err != nil { return "", err } From 1c0512a98d54bb9b8e62b105b2b2da60d07443f1 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Tue, 17 Feb 2015 01:50:46 -0800 Subject: [PATCH 3/3] flow: Closed 'make_json_pretty'.