diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-10-11 13:17:50 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-10-15 08:34:09 +0000 |
| commit | b9fb2ea80e9852ae6465fcb3b822ca9ffa3306bd (patch) | |
| tree | 6ef60254c3832271607cd34823308104ed8284cf /dashboard/app/util_test.go | |
| parent | bea340a021473d87bbbd5da6e88e575cc5e71cb0 (diff) | |
dashboard/api: add Client type
Diffstat (limited to 'dashboard/app/util_test.go')
| -rw-r--r-- | dashboard/app/util_test.go | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/dashboard/app/util_test.go b/dashboard/app/util_test.go index f30581095..f865ff612 100644 --- a/dashboard/app/util_test.go +++ b/dashboard/app/util_test.go @@ -26,6 +26,7 @@ import ( "time" "github.com/google/go-cmp/cmp" + "github.com/google/syzkaller/dashboard/api" "github.com/google/syzkaller/dashboard/dashapi" "github.com/google/syzkaller/pkg/email" "github.com/google/syzkaller/pkg/subsystem" @@ -496,18 +497,6 @@ type apiClient struct { } func (c *Ctx) makeClient(client, key string, failOnErrors bool) *apiClient { - doer := func(r *http.Request) (*http.Response, error) { - r = registerRequest(r, c) - r = r.WithContext(c.transformContext(r.Context())) - w := httptest.NewRecorder() - http.DefaultServeMux.ServeHTTP(w, r) - res := &http.Response{ - StatusCode: w.Code, - Status: http.StatusText(w.Code), - Body: io.NopCloser(w.Result().Body), - } - return res, nil - } logger := func(msg string, args ...interface{}) { c.t.Logf("%v: "+msg, append([]interface{}{caller(3)}, args...)...) } @@ -516,7 +505,7 @@ func (c *Ctx) makeClient(client, key string, failOnErrors bool) *apiClient { c.t.Fatalf("\n%v: %v", caller(2), err) } } - dash, err := dashapi.NewCustom(client, "", key, c.inst.NewRequest, doer, logger, errorHandler) + dash, err := dashapi.NewCustom(client, "", key, c.inst.NewRequest, c.httpDoer(), logger, errorHandler) if err != nil { panic(fmt.Sprintf("Impossible error: %v", err)) } @@ -526,6 +515,25 @@ func (c *Ctx) makeClient(client, key string, failOnErrors bool) *apiClient { } } +func (c *Ctx) makeAPIClient() *api.Client { + return api.NewTestClient(c.inst.NewRequest, c.httpDoer()) +} + +func (c *Ctx) httpDoer() func(*http.Request) (*http.Response, error) { + return func(r *http.Request) (*http.Response, error) { + r = registerRequest(r, c) + r = r.WithContext(c.transformContext(r.Context())) + w := httptest.NewRecorder() + http.DefaultServeMux.ServeHTTP(w, r) + res := &http.Response{ + StatusCode: w.Code, + Status: http.StatusText(w.Code), + Body: io.NopCloser(w.Result().Body), + } + return res, nil + } +} + func (client *apiClient) pollBugs(expect int) []*dashapi.BugReport { resp, _ := client.ReportingPollBugs("test") if len(resp.Reports) != expect { |
