MCPcopy Index your code
hub / github.com/coder/coder / TestHandleAction_HoldKey

Function TestHandleAction_HoldKey

agent/x/agentdesktop/api_test.go:579–627  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

577}
578
579func TestHandleAction_HoldKey(t *testing.T) {
580 t.Parallel()
581
582 logger := slogtest.Make(t, nil)
583 fake := &fakeDesktop{
584 startCfg: agentdesktop.DisplayConfig{Width: 1920, Height: 1080},
585 }
586 mClk := quartz.NewMock(t)
587 trap := mClk.Trap().NewTimer("agentdesktop", "hold_key")
588 defer trap.Close()
589 api := agentdesktop.NewAPI(logger, fake, mClk)
590 defer api.Close()
591
592 text := "Shift_L"
593 dur := 100
594 body := agentdesktop.DesktopAction{
595 Action: "hold_key",
596 Text: &text,
597 Duration: &dur,
598 }
599 b, err := json.Marshal(body)
600 require.NoError(t, err)
601
602 rr := httptest.NewRecorder()
603 req := httptest.NewRequest(http.MethodPost, "/action", bytes.NewReader(b))
604 req.Header.Set("Content-Type", "application/json")
605
606 handler := api.Routes()
607
608 done := make(chan struct{})
609 go func() {
610 defer close(done)
611 handler.ServeHTTP(rr, req)
612 }()
613
614 trap.MustWait(req.Context()).MustRelease(req.Context())
615 mClk.Advance(time.Duration(dur) * time.Millisecond).MustWait(req.Context())
616
617 <-done
618
619 assert.Equal(t, http.StatusOK, rr.Code)
620
621 var resp agentdesktop.DesktopActionResponse
622 err = json.NewDecoder(rr.Body).Decode(&resp)
623 require.NoError(t, err)
624 assert.Equal(t, "hold_key action performed", resp.Output)
625 assert.Equal(t, "Shift_L", fake.lastKeyDown)
626 assert.Equal(t, "Shift_L", fake.lastKeyUp)
627}
628
629func TestHandleAction_HoldKeyMissingText(t *testing.T) {
630 t.Parallel()

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
RoutesMethod · 0.95
NewAPIFunction · 0.92
DurationMethod · 0.80
CloseMethod · 0.65
SetMethod · 0.65
ContextMethod · 0.65
MarshalMethod · 0.45
ServeHTTPMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected