diff options
| author | tarasmadan <89859571+tarasmadan@users.noreply.github.com> | 2021-10-26 10:06:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-26 10:06:56 +0200 |
| commit | d50eb50a564f0774e935b4f77390e3f591b4206d (patch) | |
| tree | 792d4094c5315f8df05209a2ce90f6bb17fe9124 | |
| parent | 5ac98ce3aa210ad314a0229b20b9a7b403538803 (diff) | |
dashboard/app: prettyprint json output (#2848)
| -rw-r--r-- | dashboard/app/getjson_test.go | 53 | ||||
| -rw-r--r-- | dashboard/app/main.go | 5 |
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 } |
