Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(e2e): add comprehensive end-to-end tests and improve CI workflows #222

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

lvlcn-t
Copy link
Member

@lvlcn-t lvlcn-t commented Nov 17, 2024

Motivation

This PR adds E2E tests to Sparrow to make sure its core features work as expected in (almost) real-world conditions. These tests simulate how the application is used and improving reliability and stability.

I didn’t include E2E tests for the target manager component to keep the PR manageable. Those will come in a follow-up PR. This one is already quite large because I included both the E2E tests and the framework setup in one place to avoid splitting discussions across multiple smaller PRs.


Changes

E2E Testing Framework

A new testing framework was added to make it easier to write and run E2E tests. It includes:

  • Server Management Tools: Makes sure the sparrow is ready before tests start.
  • Remote Config Testing: Handles tests for dynamic configurations.
  • Modular Design: Makes it simple to add new tests / assertions.

New E2E Tests

Here are the tests added in this PR:

  • Health Check Tests: Verify sparrows health check.
  • Latency Tests: Verify sparrows latency check runs correctly.
  • DNS Tests: Make sure DNS resolutions work.
  • File Loader Tests: Test configuration loading from local files.
  • Remote Config Loader Tests: Validate fetching and applying remote configurations.
  • Check Reconfiguration Tests: Test how the app handles updates to configuration during runtime.

In the future, this framework might be extended to cover existing unit tests, but that may require major restructuring (e.g., moving tests into <package>_test or reorganizing packages).


Bug Fixes

This PR also fixes several issues:

  • Fixed race conditions during shutdown and configuration updates.
  • Added the OpenAPI version to make the API spec compliant.
  • Fixed metrics API content type to return application/json instead of text/plain.

Refactoring and Code Simplifications

Some general improvements were made to simplify the code:

  • Combined test workflow files to make CI/CD setups cleaner.
  • Improved naming across the checks.
  • Unexposed private functions and types for better encapsulation.

CI/CD Pipeline Updates

The CI/CD pipeline was improved with these changes:

  • Renamed workflows to kebab-case for consistency.
  • Separated go unit and go E2E tests into separate jobs for faster execution.
  • Added tparse for cleaner test output formatting.
  • Started uploading gosec results to GitHub’s security page and scheduled regular SAST scans.
  • Added customizable logging options to test workflows.

Dependency Updates

The YAML library was updated from yaml.v3 to go-yaml because it’s actively maintained, and works better with modern Go versions.


Tests Done

All tests passed:

  • Unit tests succeeded
  • E2E tests succeeded

Next Steps

  1. Add E2E tests for the target manager component in a future PR.
  2. Explore extending the E2E framework to existing unit tests, which might need some bigger changes to the code structure.

* test: add health check e2e test
* test: add latency check e2e test
* test: add dns check e2e test
* test: add file loader e2e test
* fix: add missing version in openapi spec
* chore: use go-yaml instead of yaml.v3
* chore: skip go files in bash e2e tests

Signed-off-by: lvlcn-t <[email protected]>
* fix: race conditions in check shutdown
* fix: set openapi version on build time
* refactor: check base naming

Signed-off-by: lvlcn-t <[email protected]>
* fix: gosec SAST scan ci job
* feat: upload gosec report to github security page

Signed-off-by: lvlcn-t <[email protected]>
* ci: rename workflows to kebab-case
* chore: introduce naming pattern for test workflows
* chore: bump e2e k3s v1.31.2-k3s1

Signed-off-by: lvlcn-t <[email protected]>
* test: add additional e2e tests for check reconfiguration
* fix: race conditions in all checks when reconfiguring while running checks
* refactor: add check base constructor
* fix: add missing json tags for dns check result struct
* chore: use time ticker instead of time.After for check intervals
* fix: only update check config if it has changed
* chore: improve naming in checks
* chore: unexpose private functions & structs
* refactor: simplify check config & e2e test builder

Signed-off-by: lvlcn-t <[email protected]>
* fix: metrics endpoints content type setting (was ineffective thus always returning text/plain)

Signed-off-by: lvlcn-t <[email protected]>
@lvlcn-t lvlcn-t requested a review from y-eight as a code owner November 17, 2024 22:21
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

1 similar comment
@github-advanced-security

This comment was marked as duplicate.

test/framework/e2e.go Dismissed Show dismissed Hide dismissed
test/framework/e2e.go Dismissed Show dismissed Hide dismissed
@lvlcn-t lvlcn-t self-assigned this Nov 17, 2024
@lvlcn-t lvlcn-t added bug Something isn't working feature Introduces a new feature area/checks Issues/PRs related to Checks area/ci Issues/PRs related to github actions labels Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/checks Issues/PRs related to Checks area/ci Issues/PRs related to github actions bug Something isn't working feature Introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant