test: add unit test for flag trigger #773
Merged
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.
Fixes #684
This pull request primarily includes adding unit tests for FlagTrigger and changes to the Bucketeer project's "pkg/feature/api" package. This change focuses on refactoring the
FeatureService
structure and related methods inapi.go
andflag_trigger.go
to use the newv2fs
package for feature storage. Additionally, error handling has been simplified for several methods, and the "generateTriggerURL" method no longer returns an error.Here are the most important changes:
Add unit test for flag trigger.
Refactoring to use
v2fs
package:pkg/feature/api/api.go
: Imported thev2fs
package and itsFeatureStorage
andFlagTriggerStorage
types. These were then added as fields to theFeatureService
struct, replacing direct usage of themysqlClient
. TheNewFeatureService
function was also updated to initialize these new fields. [1] [2] [3]pkg/feature/api/api_test.go
: Similar changes were made in the test file, where mock instances ofFeatureStorage
andFlagTriggerStorage
are now created and used in thecreateFeatureService
andcreateFeatureServiceNew
functions. [1] [2] [3]Simplification of error handling:
pkg/feature/api/flag_trigger.go
: In several methods, the error handling forgenerateTriggerURL
has been removed, as this function no longer returns errors. Instead, the URL is directly assigned totriggerURL
. Additionally, error handling inResetFlagTrigger
andDeleteFlagTrigger
has been simplified to return a single error status. [1] [2] [3] [4] [5] [6] [7] [8] [9]Refactoring of
FeatureService
methods:pkg/feature/api/flag_trigger.go
: All methods in this file that previously created new instances ofFlagTriggerStorage
orFeatureStorage
now use the instances stored in theFeatureService
struct. This includes theGetFlagTrigger
,FlagTriggerWebhook
, andgenerateTriggerURL
methods. [1] [2] [3]