-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from splitio/project/flagsets
Flagsets -- Base branch
- Loading branch information
Showing
38 changed files
with
2,052 additions
and
1,300 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package conf | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/splitio/go-split-commons/v5/flagsets" | ||
) | ||
|
||
type FlagSetValidationError struct { | ||
wrapped []error | ||
} | ||
|
||
func (f FlagSetValidationError) Error() string { | ||
var errors []string | ||
for _, err := range f.wrapped { | ||
errors = append(errors, err.Error()) | ||
} | ||
return strings.Join(errors, ".|| ") | ||
} | ||
|
||
func ValidateFlagsets(sets []string) ([]string, error) { | ||
var toRet error | ||
sanitizedFlagSets, fsErr := flagsets.SanitizeMany(sets) | ||
if fsErr != nil { | ||
toRet = FlagSetValidationError{wrapped: fsErr} | ||
} | ||
return sanitizedFlagSets, toRet | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package conf | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/splitio/go-split-commons/v5/dtos" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFlagSetValidationError(t *testing.T) { | ||
|
||
sanitized, err := ValidateFlagsets([]string{"Flagset1", " flagset2 ", "123#@flagset"}) | ||
assert.NotNil(t, err) | ||
assert.Equal(t, []string{"flagset1", "flagset2"}, sanitized) | ||
|
||
asFVE := err.(FlagSetValidationError) | ||
assert.Equal(t, 3, len(asFVE.wrapped)) | ||
assert.ElementsMatch(t, []error{ | ||
dtos.FlagSetValidatonError{Message: "Flag Set name Flagset1 should be all lowercase - converting string to lowercase"}, | ||
dtos.FlagSetValidatonError{Message: "Flag Set name flagset2 has extra whitespace, trimming"}, | ||
dtos.FlagSetValidatonError{Message: "you passed 123#@flagset, Flag Set must adhere to the regular expressions ^[a-z0-9][_a-z0-9]{0,49}$. This means a Flag Set must " + | ||
"start with a letter or number, be in lowercase, alphanumeric and have a max length of 50 characters. 123#@flagset was discarded."}, | ||
}, asFVE.wrapped) | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.