aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/app/util_test.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-01-26 15:19:50 +0100
committerAleksandr Nogikh <wp32pw@gmail.com>2023-01-27 17:31:25 +0100
commitc630e2bf7a6cb84eec2005e2e66e35e0d88054cb (patch)
tree4ac778adfd375a6fc46389ee36240384753558d5 /dashboard/app/util_test.go
parente40567a5893b3aa8372771183a9a2ee9f075895a (diff)
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.
Diffstat (limited to 'dashboard/app/util_test.go')
-rw-r--r--dashboard/app/util_test.go15
1 files changed, 11 insertions, 4 deletions
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{