testing

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2025 License: BSD-3-Clause Imports: 4 Imported by: 0

README

Workspace Watcher Testing

This package contains tests for the WorkspaceWatcher component. The tests use a real filesystem and a mock LSP client to verify that the watcher correctly detects and reports file events.

Test Suite Overview

The test suite consists of the following tests:

1. Basic Functionality Tests
  • Tests file creation, modification, and deletion events
  • Confirms that appropriate notifications are sent to the LSP client
  • Verifies that each operation triggers the correct event type (Created, Changed, Deleted)
2. Exclusion Pattern Tests
  • Tests that files matching exclusion patterns are not reported
  • Specifically tests:
    • Files with excluded extensions (.tmp)
    • Files ending with tilde (~)
    • Files in excluded directories (.git)
    • Files matching gitignore patterns
3. Debouncing Tests
  • Tests that rapid changes to the same file result in a single notification
  • Verifies the debouncing mechanism works correctly

Mock LSP Client

The MockLSPClient implements the watcher.LSPClient interface and provides functionality for:

  • Recording file events
  • Testing if files are open
  • Opening files
  • Notifying about file changes
  • Waiting for events with a timeout

Running the Tests

To run the tests:

go test -v ./internal/watcher/testing

For more detailed output, enable debug logging:

go test -v -tags debug ./internal/watcher/testing

Known Issues and Limitations

  1. Gitignore Integration:

    • The watcher uses the go-gitignore package to parse and match gitignore patterns.
    • The tests verify that files matching gitignore patterns are excluded from notifications.
    • Additional tests in gitignore_test.go verify more complex patterns and matching scenarios.
  2. File Deletion in Excluded Directories:

    • Since excluded directories are not watched, file deletion events in these directories are not detected.
  3. Large Binary Files:

    • The tests don't verify the handling of large binary files due to test resource limitations.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileEvent

type FileEvent struct {
	URI  string
	Type protocol.FileChangeType
}

FileEvent represents a file event notification

type MockLSPClient

type MockLSPClient struct {
	// contains filtered or unexported fields
}

MockLSPClient implements the watcher.LSPClient interface for testing

func NewMockLSPClient

func NewMockLSPClient() *MockLSPClient

NewMockLSPClient creates a new mock LSP client for testing

func (*MockLSPClient) CountEvents

func (m *MockLSPClient) CountEvents(uri string, eventType protocol.FileChangeType) int

CountEvents counts events for a specific file and event type

func (*MockLSPClient) DidChangeWatchedFiles

func (m *MockLSPClient) DidChangeWatchedFiles(ctx context.Context, params protocol.DidChangeWatchedFilesParams) error

DidChangeWatchedFiles mocks sending watched file events to the server

func (*MockLSPClient) GetEvents

func (m *MockLSPClient) GetEvents() []FileEvent

GetEvents returns a copy of all recorded events

func (*MockLSPClient) IsFileOpen

func (m *MockLSPClient) IsFileOpen(path string) bool

IsFileOpen checks if a file is already open in the editor

func (*MockLSPClient) NotifyChange

func (m *MockLSPClient) NotifyChange(ctx context.Context, path string) error

NotifyChange mocks notifying the server of a file change

func (*MockLSPClient) OpenFile

func (m *MockLSPClient) OpenFile(ctx context.Context, path string) error

OpenFile mocks opening a file in the editor

func (*MockLSPClient) ResetEvents

func (m *MockLSPClient) ResetEvents()

ResetEvents clears the recorded events

func (*MockLSPClient) WaitForEvent

func (m *MockLSPClient) WaitForEvent(ctx context.Context) bool

WaitForEvent waits for at least one event to be received or context to be done

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL