add indentation to json output. update test.
This commit is contained in:
1 parent
21e2acd4a5
commit
1a66b03d0d
2 files changed
+33
-2
No files matched your search
@@ -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
|
// 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
|
// 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
|
// 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)
|
j, err := locationsToJSON(l)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("locationsToJSON failed")
|
t.Error("locationsToJSON failed")
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ func sitemapToLocations(pages itemSlice) []*Location {
|
|||||||
|
|
||||||
// locationsToJSON takes a *Location slice and marshals it into a JSON string
|
// locationsToJSON takes a *Location slice and marshals it into a JSON string
|
||||||
func locationsToJSON(locations []*Location) (string, error) {
|
func locationsToJSON(locations []*Location) (string, error) {
|
||||||
b, err := json.Marshal(locations)
|
b, err := json.MarshalIndent(locations, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user