From c630e2bf7a6cb84eec2005e2e66e35e0d88054cb Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 26 Jan 2023 15:19:50 +0100 Subject: dashboard: test subsystem filtering In order to do that, we need to tweak the subsystem extraction code. Use context values, as this should simplify the flow. --- dashboard/app/util_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'dashboard/app/util_test.go') diff --git a/dashboard/app/util_test.go b/dashboard/app/util_test.go index af9bbc2e3..d01fb0d27 100644 --- a/dashboard/app/util_test.go +++ b/dashboard/app/util_test.go @@ -38,6 +38,7 @@ type Ctx struct { ctx context.Context mockedTime time.Time emailSink chan *aemail.Message + contextVars map[interface{}]interface{} client *apiClient client2 *apiClient publicClient *apiClient @@ -67,10 +68,11 @@ func NewCtx(t *testing.T) *Ctx { t.Fatal(err) } c := &Ctx{ - t: t, - inst: inst, - mockedTime: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), - emailSink: make(chan *aemail.Message, 100), + t: t, + inst: inst, + mockedTime: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), + contextVars: make(map[interface{}]interface{}), + emailSink: make(chan *aemail.Message, 100), } c.client = c.makeClient(client1, password1, true) c.client2 = c.makeClient(client2, password2, true) @@ -374,6 +376,11 @@ 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) + newCtx := r.Context() + for key, val := range c.contextVars { + newCtx = context.WithValue(newCtx, key, val) + } + r = r.WithContext(newCtx) w := httptest.NewRecorder() http.DefaultServeMux.ServeHTTP(w, r) res := &http.Response{ -- cgit mrf-deployment