(t *testing.T)
| 549 | } |
| 550 | |
| 551 | func TestDetectFileDump(t *testing.T) { |
| 552 | t.Parallel() |
| 553 | |
| 554 | tests := []struct { |
| 555 | name string |
| 556 | command string |
| 557 | wantHit bool |
| 558 | }{ |
| 559 | { |
| 560 | name: "CatFile", |
| 561 | command: "cat foo.txt", |
| 562 | wantHit: true, |
| 563 | }, |
| 564 | { |
| 565 | name: "NotCatPrefix", |
| 566 | command: "concatenate foo", |
| 567 | wantHit: false, |
| 568 | }, |
| 569 | { |
| 570 | name: "GrepIncludeAll", |
| 571 | command: "grep --include-all pattern", |
| 572 | wantHit: true, |
| 573 | }, |
| 574 | { |
| 575 | name: "RgListFiles", |
| 576 | command: "rg -l pattern", |
| 577 | wantHit: true, |
| 578 | }, |
| 579 | { |
| 580 | name: "GrepRecursive", |
| 581 | command: "grep -r pattern", |
| 582 | wantHit: false, |
| 583 | }, |
| 584 | } |
| 585 | |
| 586 | for _, tc := range tests { |
| 587 | t.Run(tc.name, func(t *testing.T) { |
| 588 | t.Parallel() |
| 589 | ctrl := gomock.NewController(t) |
| 590 | mockConn := agentconnmock.NewMockAgentConn(ctrl) |
| 591 | |
| 592 | mockConn.EXPECT(). |
| 593 | StartProcess(gomock.Any(), gomock.Any()). |
| 594 | Return(workspacesdk.StartProcessResponse{ID: "proc-1"}, nil) |
| 595 | exitCode := 0 |
| 596 | mockConn.EXPECT(). |
| 597 | ProcessOutput(gomock.Any(), "proc-1", gomock.Any()). |
| 598 | Return(workspacesdk.ProcessOutputResponse{ |
| 599 | Running: false, |
| 600 | ExitCode: &exitCode, |
| 601 | Output: "output", |
| 602 | }, nil) |
| 603 | |
| 604 | tool := newExecuteTool(t, mockConn) |
| 605 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 606 | input, err := json.Marshal(map[string]any{ |
| 607 | "command": tc.command, |
| 608 | }) |
nothing calls this directly
no test coverage detected