aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortarasmadan <89859571+tarasmadan@users.noreply.github.com>2021-10-26 10:06:56 +0200
committerGitHub <noreply@github.com>2021-10-26 10:06:56 +0200
commitd50eb50a564f0774e935b4f77390e3f591b4206d (patch)
tree792d4094c5315f8df05209a2ce90f6bb17fe9124
parent5ac98ce3aa210ad314a0229b20b9a7b403538803 (diff)
dashboard/app: prettyprint json output (#2848)
-rw-r--r--dashboard/app/getjson_test.go53
-rw-r--r--dashboard/app/main.go5
2 files changed, 31 insertions, 27 deletions
diff --git a/dashboard/app/getjson_test.go b/dashboard/app/getjson_test.go
index 59cf1d951..47682728c 100644
--- a/dashboard/app/getjson_test.go
+++ b/dashboard/app/getjson_test.go
@@ -4,36 +4,40 @@
package main
import (
- "bytes"
- "encoding/json"
"fmt"
"testing"
)
func TestJSONAPIIntegration(t *testing.T) {
sampleCrashDescr := []byte(`{
- "version":1,
- "title":"title1",
- "crashes":[{
- "kernel-config":"/text?tag=KernelConfig\u0026x=a989f27ebc47e2dc",
- "kernel-source-commit":"1111111111111111111111111111111111111111",
- "syzkaller-git":"https://github.com/google/syzkaller/commits/syzkaller_commit1",
- "syzkaller-commit":"syzkaller_commit1"
- }]
- }`)
+ "version": 1,
+ "title": "title1",
+ "crashes": [
+ {
+ "kernel-config": "/text?tag=KernelConfig\u0026x=a989f27ebc47e2dc",
+ "kernel-source-commit": "1111111111111111111111111111111111111111",
+ "syzkaller-git": "https://github.com/google/syzkaller/commits/syzkaller_commit1",
+ "syzkaller-commit": "syzkaller_commit1"
+ }
+ ]
+}`,
+ )
sampleCrashWithReproDescr := []byte(`{
- "version":1,
- "title":"title2",
- "crashes":[{
- "syz-reproducer":"/text?tag=ReproSyz\u0026x=13000000000000",
- "c-reproducer":"/text?tag=ReproC\u0026x=17000000000000",
- "kernel-config":"/text?tag=KernelConfig\u0026x=a989f27ebc47e2dc",
- "kernel-source-commit":"1111111111111111111111111111111111111111",
- "syzkaller-git":"https://github.com/google/syzkaller/commits/syzkaller_commit1",
- "syzkaller-commit":"syzkaller_commit1"
- }]
- }`)
+ "version": 1,
+ "title": "title2",
+ "crashes": [
+ {
+ "syz-reproducer": "/text?tag=ReproSyz\u0026x=13000000000000",
+ "c-reproducer": "/text?tag=ReproC\u0026x=17000000000000",
+ "kernel-config": "/text?tag=KernelConfig\u0026x=a989f27ebc47e2dc",
+ "kernel-source-commit": "1111111111111111111111111111111111111111",
+ "syzkaller-git": "https://github.com/google/syzkaller/commits/syzkaller_commit1",
+ "syzkaller-commit": "syzkaller_commit1"
+ }
+ ]
+}`,
+ )
c := NewCtx(t)
defer c.Close()
@@ -58,8 +62,5 @@ func checkBugPageJSONIs(c *Ctx, ID string, expectedContent []byte) {
url := fmt.Sprintf("/bug?extid=%v&json=1", ID)
actualContent, _ := c.client.GET(url)
- var minExpectedContent bytes.Buffer
- json.Compact(&minExpectedContent, expectedContent)
-
- c.expectEQ(string(actualContent), minExpectedContent.String())
+ c.expectEQ(string(actualContent), string(expectedContent))
}
diff --git a/dashboard/app/main.go b/dashboard/app/main.go
index bef434663..d0b9b58e8 100644
--- a/dashboard/app/main.go
+++ b/dashboard/app/main.go
@@ -447,7 +447,10 @@ func isJSONRequested(request *http.Request) bool {
}
func writeJSONVersionOf(writer http.ResponseWriter, bugPage *uiBugPage) error {
- data, err := json.Marshal(GetExtAPIDescrForBugPage(bugPage))
+ data, err := json.MarshalIndent(
+ GetExtAPIDescrForBugPage(bugPage),
+ "",
+ "\t")
if err != nil {
return err
}