Conversation
- Includes pinned Python dependencies with hashes for use in documentation generation workflows.
…stallation with hashes
… registry behavior, metrics aggregation, and HTTP sniffing.
…, including operations like `Read`, `Write`, `Close`, `Reset`, and header and identifier validation.
…, namespace controller, service CRUD, and Kubernetes discovery integrations
Covers `LogBuffer` behavior including initialization, bounded size, entry addition, retrieval (all, last), clearing, hook levels, logging hooks, and concurrency.
Refactor and expand test coverage for namespace controller, service CRUD, and Kubernetes discovery methods. Includes mock integrations for methods like `AddNamespace`, `ListNamespaces`, `GetNamespace`, `RemoveNamespace`, and corresponding service operations.
Covers `GetWatcherByKey` and `NamespaceWatcher.Done` methods, including watcher retrieval, channel handling, and validation.
Covers service retrieval methods including `Get`, `GetAll`, `GetByNamespace`, and handling of empty and non-existent services, as well as multiple contexts and namespaces.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #340 +/- ##
==========================================
+ Coverage 61.54% 63.67% +2.13%
==========================================
Files 69 69
Lines 11071 11071
==========================================
+ Hits 6814 7050 +236
+ Misses 3981 3738 -243
- Partials 276 283 +7 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 PR adds comprehensive unit tests to improve code coverage across multiple packages, bringing overall coverage from ~62% to 63.5% with significant improvements in individual packages.
Coverage Improvements
pkg/fwdmcppkg/fwdmetricspkg/fwdapipkg/fwdnspkg/fwdsvcregistryNew Test Files
pkg/fwdmcp/httpclient_test.goAdded tests for HTTP client adapter functions:
TestStateReaderHTTP_GetForward- Tests getting a single forwardTestMetricsProviderHTTP_GetServiceSnapshot- Tests service snapshot retrievalTestDiagnosticsProviderHTTP_GetServiceDiagnostic- Tests service diagnosticsTestDiagnosticsProviderHTTP_GetForwardDiagnostic- Tests forward diagnosticsTestDiagnosticsProviderHTTP_GetNetworkStatus- Tests network statusTestNewAPIUnavailableError- Tests API error constructorpkg/fwdmetrics/registry_test.goAdded tests for metrics registry operations:
TestRegistryRegisterUnregisterService- Service registration lifecycleTestRegistryGetServiceNotFound- Non-existent service handlingTestRegistryUnregisterPortForward- Port forward unregistrationTestRegistryUnregisterPortForwardWithMultiple- Multiple port forwardsTestRegistryGetAllServices- Get all servicesTestRegistryGetTotals- Aggregated totals across servicesTestServiceMetricsGetTotals- Service-level totalsTestServiceMetricsRemovePortForward- Port forward removalTestPortForwardMetricsKey- Key generationTestPortForwardMetricsServiceKey- Service key generationTestPortForwardMetricsEnableHTTPSniffing- HTTP sniffing featurepkg/fwdmetrics/stream_test.goAdded tests for metrics stream wrapper:
TestMetricsStreamClose- Stream close delegationTestMetricsStreamReset- Stream reset delegationTestMetricsStreamHeaders- Headers passthroughTestMetricsStreamIdentifier- Stream identifierTestMetricsStreamMultipleOperations- Combined operationspkg/fwdapi/logbuffer_test.goAdded tests for log buffer functionality:
TestBoundedSize- Size boundary checks (CodeQL CWE-770 compliance)TestNewLogBuffer- Buffer creationTestLogBufferAdd- Entry additionTestLogBufferAddWrap- Ring buffer wrappingTestLogBufferGetLast- Recent entry retrievalTestLogBufferGetAll- All entries retrievalTestLogBufferClear- Buffer clearingTestLogBufferHookLevels- Logrus hook levelsTestLogBufferHookFire- Hook firingTestGetLogBuffer- Global buffer singletonTestGetLogBufferProvider- Provider interfaceTestInitLogBuffer- InitializationTestLogBufferConcurrency- Thread safetypkg/fwdapi/manager_test.go(extended)Added tests for manager interface setters:
TestManager_SetDiagnosticsProviderTestManager_SetNamespaceControllerTestManager_SetServiceCRUDTestManager_SetKubernetesDiscoveryTestManager_GetNamespaceManagerTestNamespaceControllerMethods- Interface methodsTestServiceCRUDMethods- CRUD interface methodsTestKubernetesDiscoveryMethods- K8s discovery interfacepkg/fwdns/manager_test.go(extended)Added tests for namespace manager:
TestManager_GetWatcherByKey- Watcher lookup by keyTestNamespaceWatcher_Done- Done channel behaviorpkg/fwdsvcregistry/fwdsvcregistry_test.go(extended)Added tests using fake K8s client:
TestGet_ExistingService- Get existing serviceTestGet_NonExistentService- Get non-existent serviceTestGetAll- Get all servicesTestGetAll_Empty- Empty registryTestGetByNamespace- Filter by namespaceTestGetByNamespace_DifferentContexts- Multi-context filteringTesting Approach
httptest-based testing - Used Go's
net/http/httptestpackage for HTTP client tests infwdmcpFake K8s client - Used
k8s.io/client-go/kubernetes/fakefor testing code that interacts with Kubernetes APIsInterface mocking - Created mock implementations for interfaces like
StateReader,MetricsProvider,ServiceController, etc.Concurrency testing - Added tests for thread-safe operations with
sync.WaitGroupand race condition checksPackages Not Addressed
Some packages remain at lower coverage due to their nature:
pkg/fwdtui(20.6%) - Requires Bubble Tea TUI mocking frameworkpkg/fwdport(57.2%) - Requires SPDY port-forward connection mockingcmd/kubefwd/services(14.8%) - Integration-level orchestration codecmd/kubefwd(0%) - CLI entry pointRunning Tests
Related Issues