Skip to content

Commit

Permalink
Add test case to validate flag set warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nmayorsplit committed Nov 15, 2023
1 parent b2cca49 commit ed04468
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
6 changes: 3 additions & 3 deletions splitio/client/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ func setupInMemoryFactory(
logger logging.LoggerInterface,
metadata dtos.Metadata,
) (*SplitFactory, error) {
advanced, errs := conf.NormalizeSDKConf(cfg.Advanced)
printWarnings(logger, errs)
advanced, warnings := conf.NormalizeSDKConf(cfg.Advanced)
printWarnings(logger, warnings)
if strings.TrimSpace(cfg.SplitSyncProxyURL) != "" {
advanced.StreamingEnabled = false
}
Expand Down Expand Up @@ -656,7 +656,7 @@ func buildImpressionManager(
func printWarnings(logger logging.LoggerInterface, errs []error) {
if len(errs) != 0 {
for _, err := range errs {
if errType, ok := err.(*dtos.FlagSetValidatonError); ok {
if errType, ok := err.(dtos.FlagSetValidatonError); ok {
logger.Warning(errType.Message)
}
}
Expand Down
35 changes: 35 additions & 0 deletions splitio/client/factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package client

import (
"testing"

"github.com/splitio/go-split-commons/v5/flagsets"
)

func TestPrintWarnings(t *testing.T) {

flagSets, warnings := flagsets.SanitizeMany([]string{"set1", " set2"})
if len(flagSets) != 2 {
t.Error("flag set size should be 2")
}
printWarnings(getMockedLogger(), warnings)
if !mW.Matches("Flag Set name set2 has extra whitespace, trimming") {
t.Error("Wrong message")
}
flagSets, warnings = flagsets.SanitizeMany([]string{"set1", "Set2"})
if len(flagSets) != 2 {
t.Error("flag set size should be 2")
}
printWarnings(getMockedLogger(), warnings)
if !mW.Matches("Flag Set name Set2 should be all lowercase - converting string to lowercase") {
t.Error("Wrong message")
}
flagSets, warnings = flagsets.SanitizeMany([]string{"set1", "@set4"})
if len(flagSets) != 1 {
t.Error("flag set size should be 1")
}
printWarnings(getMockedLogger(), warnings)
if !mW.Matches("you passed @set4, 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. @set4 was discarded.") {
t.Error("Wrong message")
}
}

0 comments on commit ed04468

Please sign in to comment.