Skip to content

chore: add interface to abstract cmd which allows unit testing backends #89

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

Merged
merged 2 commits into from
Apr 7, 2025

Conversation

leoparente
Copy link
Contributor

This pull request introduces a new abstraction layer for command execution and refactors existing code to use this new abstraction. The changes also include the addition of a mock implementation for testing purposes. The most important changes include the introduction of the CmdInterface, refactoring of multiple backend components to use this interface, and the addition of tests for the OpenTelemetry backend.

Introduction of CmdInterface:

  • agent/backend/cmd.go: Added CmdInterface to abstract the functionality of the go-cmd package and implemented CmdWrapper to wrap the cmd.Cmd struct.

Refactoring to use CmdInterface:

Addition of mock implementation for testing:

  • agent/backend/mocks/mocks.go: Added MockCmd, a mock implementation of CmdInterface, and helper functions to set up different process states for testing.

Tests for OpenTelemetry backend:

@leoparente leoparente self-assigned this Apr 4, 2025
Copy link

github-actions bot commented Apr 4, 2025

Go test coverage

STATUS ELAPSED PACKAGE COVER PASS FAIL SKIP
🟢 PASS 1.03s github.com/netboxlabs/orb-agent/agent 0.0% 1 0 0
🟢 PASS 0.01s github.com/netboxlabs/orb-agent/agent/backend 0.0% 0 0 0
🟢 PASS 0.01s github.com/netboxlabs/orb-agent/agent/backend/devicediscovery 0.0% 0 0 0
🟢 PASS 0.00s github.com/netboxlabs/orb-agent/agent/backend/mocks 0.0% 0 0 0
🟢 PASS 0.00s github.com/netboxlabs/orb-agent/agent/backend/networkdiscovery 0.0% 0 0 0
🟢 PASS 2.02s github.com/netboxlabs/orb-agent/agent/backend/otel 38.3% 1 0 0
🟢 PASS 0.01s github.com/netboxlabs/orb-agent/agent/backend/pktvisor 0.0% 0 0 0
🟢 PASS 0.01s github.com/netboxlabs/orb-agent/agent/backend/worker 0.0% 0 0 0
🟢 PASS 1.06s github.com/netboxlabs/orb-agent/agent/configmgr 47.7% 9 0 0
🟢 PASS 1.01s github.com/netboxlabs/orb-agent/agent/policies 100.0% 15 0 0
🟢 PASS 1.03s github.com/netboxlabs/orb-agent/agent/policymgr 70.3% 10 0 0
🟢 PASS 2.50s github.com/netboxlabs/orb-agent/agent/secretsmgr 51.8% 45 0 0
🟢 PASS 1.01s github.com/netboxlabs/orb-agent/agent/version 100.0% 1 0 0

Total coverage: 31.5%

@leoparente leoparente requested a review from mfiedorowicz April 7, 2025 12:33
@leoparente leoparente merged commit b4ceb47 into develop Apr 7, 2025
5 checks passed
@leoparente leoparente deleted the chore/interface-cmd-for-testing branch April 7, 2025 13:22
Copy link

🎉 This PR is included in version 2.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants