chore: add interface to abstract cmd which allows unit testing backends #89
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
: AddedCmdInterface
to abstract the functionality of thego-cmd
package and implementedCmdWrapper
to wrap thecmd.Cmd
struct.Refactoring to use
CmdInterface
:agent/backend/devicediscovery/device_discovery.go
: Replaced direct usage ofcmd.Cmd
withbackend.CmdInterface
and updated related code. [1] [2] [3] [4] [5]agent/backend/networkdiscovery/network_discovery.go
: Similar refactoring to replacecmd.Cmd
withbackend.CmdInterface
. [1] [2] [3] [4] [5]agent/backend/otel/otel.go
: Updated to usebackend.CmdInterface
instead ofcmd.Cmd
. [1] [2] [3] [4] [5]agent/backend/pktvisor/pktvisor.go
: Refactored to usebackend.CmdInterface
. [1] [2] [3] [4]Addition of mock implementation for testing:
agent/backend/mocks/mocks.go
: AddedMockCmd
, a mock implementation ofCmdInterface
, and helper functions to set up different process states for testing.Tests for OpenTelemetry backend:
agent/backend/otel/otel_test.go
: Added tests for the OpenTelemetry backend using the new mock implementation.