diff --git a/splitio/client/factory.go b/splitio/client/factory.go index 7b70fd5..48d35ed 100644 --- a/splitio/client/factory.go +++ b/splitio/client/factory.go @@ -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 } @@ -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) } } diff --git a/splitio/client/factory_test.go b/splitio/client/factory_test.go new file mode 100644 index 0000000..a751260 --- /dev/null +++ b/splitio/client/factory_test.go @@ -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") + } +}