Skip to content

Conversation

@ThisaraWeerakoon
Copy link
Contributor

@ThisaraWeerakoon ThisaraWeerakoon commented Oct 13, 2025

Addresses SYNAPSE-1132

Description

This PR introduces an end-to-end (E2E) testing suite for the current implementation. While the existing unit tests cover basic functionality, the codebase currently lacks component-level integration testing for key features like the File Inbound and Call Mediator, as well as full E2E testing for the Synapse server. This PR addresses that gap by adding targeted integration tests and E2E scenarios to ensure robustness and reliability.

Additionally, this PR includes shared test utilities that can be reused by future developers to simplify writing new tests. I've used build tags to separate unit, integration, and E2E tests, and adopted a co-located approach for organizing test files alongside the relevant implementation code.

Key Changes

The main additions in this PR are summarized below:

  1. Call Mediator Tests
    Purpose: Tests HTTP endpoint integration with real network operations.
    Coverage:

    • HTTP method validation (GET, POST, PUT, DELETE)
    • Concurrent request handling (10 simultaneous calls)
    • Error scenario testing with actual server responses
    • Timeout and performance validation
  2. File Inbound Tests
    Purpose: Component-level file processing integration.
    Coverage:

    • JSON/XML file processing with real file operations
    • Concurrent file handling validation
    • Error handling for malformed data
    • Message context integration
  3. Shared Test Utilities
    Purpose: Reusable test components and mocks.
    Features:

    • Mock HTTP servers and test data generators
    • Performance timing utilities
    • JSON validation helpers
    • Test context builders
  4. Synapse Application E2E Tests
    Purpose: End-to-end application lifecycle testing.
    Coverage:

    • Application startup/shutdown simulation
    • Configuration validation and error handling
    • Concurrent operations testing
    • Graceful shutdown scenarios

Testing Instructions

  • Run unit tests: go test ./... (excludes integration/E2E via build tags)
  • Run integration tests: go test -tags=integration ./...
  • Run E2E tests: go test -tags=e2e ./...
  • All tests should pass without external dependencies (mocks are self-contained).

This PR improves test coverage and maintainability without introducing breaking changes to the core functionality. Feedback welcome!

… and E2E test suites

Major Changes:
- Add complete integration test suite for CallMediator with HTTP server testing
- Add end-to-end test suite for Synapse application lifecycle management
- Add file inbound integration tests for component-level validation
- Add shared test utilities and helper functions for reusable test components
- Update Makefile with proper test targets for different test categories

New Files Added:
- internal/pkg/core/artifacts/call_mediator_endpoint_integration_test.go (353 lines)
  * Integration tests for HTTP endpoint calls with real servers
  * Concurrent call testing and timeout handling
  * Error scenario validation with actual network operations

- internal/app/synapse/synapse_e2e_test.go (497 lines)
  * End-to-end application lifecycle testing
  * Configuration validation and deployment simulation
  * Concurrent operations and graceful shutdown testing

- internal/app/adapters/inbound/file/file_inbound_integration_test.go (467 lines)
  * Integration tests for file system and message processing
  * JSON/XML file processing with real file operations
  * Error handling and concurrent file processing validation

- internal/pkg/testutils/helpers.go (328 lines)
  * Shared test utilities, mocks, and data generators
  * Mock HTTP servers and test context builders
  * Performance timing utilities and JSON validation helpers

Makefile Updates:
- Add test-integration, test-e2e, test-all targets for organized test execution
- Remove test-coverage and test-coverage-html targets (simplified)
- Support for build tag-based test categorization

Test Organization:
- Unit tests: Default execution with no build tags
- Integration tests: //go:build integration tag for component integration
- E2E tests: //go:build e2e tag for full application workflows

The testing infrastructure follows Go best practices with proper build tag separation,
co-located test placement, and comprehensive coverage of unit, integration, and
end-to-end testing scenarios. All tests pass successfully and can be executed
individually or in combination.
@GDLMadushanka
Copy link
Contributor

@isudana, shall we add GitHub Copilot as a reviewer to this repo?

msgContext.Headers["PROCESSING_TIME"] = time.Now().Format(time.RFC3339)

// Verify message context integration
suite.Equal(filename, msgContext.Headers["FILE_NAME"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this assertion?
We are setting the header in L433 and asserting it here.
Shouldn't we just provide the filepath to mediation, let it process and assert the message context created by the actual functions we have in Synapse?

processCount int
}

func (m *MockMediator) ProcessMessage(ctx context.Context, msgContext *synctx.MsgContext) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are testing the functionality of this mock function in the test cases.
Shouldn't we test the actual function we have in the inbound endpoint?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants