Coverage Increase: token/services/config Package#1529
Conversation
b528e0b to
9fbd0ff
Compare
| if ppRaw, err := retriever(opts); err != nil { | ||
| logger.Warnf("failed to retrieve params for [%s]: [%s]", opts, err) | ||
| } else if len(ppRaw) != 0 { | ||
| for i, retriever := range []func(options *driver.ServiceOptions) ([]byte, error){m.ppFromOpts, m.ppFromStorage, m.ppFromConfig, m.ppFromFetcher} { |
There was a problem hiding this comment.
this is unrelated to the scope of the PR
There was a problem hiding this comment.
These were originally added to troubleshoot and resolve specific integration test failures where TMS configurations weren't being correctly identified due to key formatting mismatches with the network orchestrator (NWO).
I have now reverted these changes to ensure this PR remains strictly focused on code coverage. 🙏
|
|
||
| // Serialize serializes this configuration with the respect to the passed tms ID | ||
| func (m *Configuration) Serialize(tmsID token.TMSID) ([]byte, error) { | ||
| keyID := fmt.Sprintf("%s%s%s", tmsID.Network, tmsID.Channel, tmsID.Namespace) |
There was a problem hiding this comment.
I originally changed this to match the NWO's dash-delimited TmsID format, but I've reverted it now to keep the PR focused strictly on coverage. 🙏
| SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package config |
There was a problem hiding this comment.
I found confusing to have these functions here. Better to move them where they belong (service.go and configuration.go). Even if they are just used by tests, they are exposed and part of the API.
There was a problem hiding this comment.
I’ve deleted export_test.go and moved the test hooks directly into service.go and configuration.go as exported methods, as you suggested. Thanks 🙌
| "github.com/hyperledger-labs/fabric-token-sdk/token/services/logging" | ||
| ) | ||
|
|
||
| var logger = logging.MustGetLogger("token.services.config") |
There was a problem hiding this comment.
no need to pass an argument here, the package path is inferred directly.
There was a problem hiding this comment.
Ok, I've simplified the logger initialization as requested since the package path is inferred automatically. ❤️
| return errors.Wrapf(err, "failed validating configuration [%s]", config.ID()) | ||
| } | ||
| } | ||
| // Updates to an existing TMS should be rejected. |
There was a problem hiding this comment.
I'm really sorry for that, I originally removed this during troubleshooting to allow for dynamic parameter reloads, but I have now restored it to maintain the original behavior. Sorry 🙌
adecaro
left a comment
There was a problem hiding this comment.
Hi @Rozerxshashank , thanks for the effort.
I left comments to be addressed.
To be a PR whose scope is to increase the test coverage. It modifies a lot of existing behaviors. I would expect changes to simplify the testing strategy but no semantic changes.
Please, have a second look to the PR. Thanks 🙏
997db28 to
99c664f
Compare
| } | ||
|
|
||
| cp.MergeConfigReturns(nil) | ||
| err = s.AddConfigurationInternal(vcp, raw) |
There was a problem hiding this comment.
we don't need to call AddConfigurationInternal. Just instantiate a new config service with the reprogrammed provider. This way we can remove the function AddConfigurationInternal and reduce the surface of the exposed functions
| // Initial state has "exist" | ||
| err = s.ResetConfigurations() | ||
| require.NoError(t, err) | ||
| _, _ = s.ConfigurationsInternal() |
There was a problem hiding this comment.
what is this for? Try to remove ConfigurationsInternal by using a different strategy.
|
HI @Rozerxshashank , great effort. We are almost there. I left other two comments and then we should be good with this PR 😄 |
|
Hi @Rozerxshashank , please, update the PR as soon as you have time 🙏 |
0f8471f to
41a5025
Compare
|
Hi @Rozerxshashank , there are still comments that needs to be addressed. Please, have a look ASAP 🙏 |
5f30877 to
a2e667a
Compare
|
Hey @adecaro, I've addressed all the comments. 🙌 But I've noticed the |
|
Hi @Rozerxshashank , yes, I'll submit a PR to fix this ASAP. Thanks 🙏 |
a2e667a to
40da1d8
Compare
13afa9b to
030e86e
Compare
Signed-off-by: Shashank <[email protected]>
Signed-off-by: Shashank <[email protected]>
030e86e to
b254a09
Compare
Description
This PR significantly improves the unit test coverage for the
token/services/configpackage, moving the baseline from 60% to 88.5%. To achieve this, I've introduced a robust mocking infrastructure usingcounterfeiterand refactored the configuration service to be more testable while maintaining a clean public API.Key Changes
Mocking Infrastructure
counterfeiterto generate mocks for core interfaces:Provider,ValidateConfiguration, andValidator.token/services/config/mocksdirectory to align with project best practices.Architectural Improvements
AddConfigurationto use an internaladdConfiguration(Provider, []byte)method. This allows us to inject mocked providers and verify the merge/validation logic without relying on concrete file-system or cryptographic implementations.export_test.goto safely expose unexported service fields and methods to theconfig_testpackage, ensuring our unit tests stay isolated from internal implementation details while still being comprehensive.Enhanced Test Suite
service_unit_test.go: Implemented exhaustive tests for:LookupNamespace(covering success, not-found, and collision scenarios).ConfigurationForerror handling.AddConfigurationvalidation and existing TMS ID conflict detection.configuration_unit_test.go: Added targeted tests for theConfigurationstruct, including its validation logic, serialization paths, and path translation wrappers.Impact
Verification
go test -cover -timeout 30s ./token/services/config/...golangci-lint:0 issues found.