diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-18 07:45:37 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-18 07:45:37 +0300 |
| commit | 4ffb22e7f69f1c9c79b095d4e60bad3d97aac55b (patch) | |
| tree | 2dc708cbb95975d34084eb5afd376871caa13e27 /internal/tmuxedit/agentutil_test.go | |
| parent | ece7dcfd232b780f5650326c8ac2379ca70387d4 (diff) | |
ik0 replace test seams with dependency injection
Diffstat (limited to 'internal/tmuxedit/agentutil_test.go')
| -rw-r--r-- | internal/tmuxedit/agentutil_test.go | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/internal/tmuxedit/agentutil_test.go b/internal/tmuxedit/agentutil_test.go index 69111b5..eed245c 100644 --- a/internal/tmuxedit/agentutil_test.go +++ b/internal/tmuxedit/agentutil_test.go @@ -199,16 +199,14 @@ func TestParseKeyRepeat(t *testing.T) { func TestSendClearSequence_EscapeKey(t *testing.T) { var calls []string - oldSend := sendKeys - defer func() { sendKeys = oldSend }() - sendKeys = func(paneID string, keys ...string) error { + deps := tmuxEditDeps{sendKeys: func(paneID string, keys ...string) error { calls = append(calls, strings.Join(keys, ",")) return nil - } + }} // sendClearSequence with "Escape" should succeed and send the key. // The 150ms Escape delay is real but acceptable in tests. - err := sendClearSequence("%1", "Escape C-k") + err := deps.sendClearSequence("%1", "Escape C-k") if err != nil { t.Fatalf("unexpected error: %v", err) } @@ -224,13 +222,11 @@ func TestSendClearSequence_EscapeKey(t *testing.T) { } func TestSendClearSequence_SingleKeyError(t *testing.T) { - oldSend := sendKeys - defer func() { sendKeys = oldSend }() - sendKeys = func(string, ...string) error { + deps := tmuxEditDeps{sendKeys: func(string, ...string) error { return fmt.Errorf("send failed") - } + }} - err := sendClearSequence("%1", "C-u") + err := deps.sendClearSequence("%1", "C-u") if err == nil { t.Fatal("expected error from sendKeys failure") } @@ -240,13 +236,11 @@ func TestSendClearSequence_SingleKeyError(t *testing.T) { } func TestSendClearSequence_RepeatedKeyError(t *testing.T) { - oldRepeat := sendRepeatedKey - defer func() { sendRepeatedKey = oldRepeat }() - sendRepeatedKey = func(string, string, int) error { + deps := tmuxEditDeps{sendRepeatedKey: func(string, string, int) error { return fmt.Errorf("repeat failed") - } + }} - err := sendClearSequence("%1", "BSpace*200") + err := deps.sendClearSequence("%1", "BSpace*200") if err == nil { t.Fatal("expected error from sendRepeatedKey failure") } |
