Skip to content

Commit

Permalink
[SDKS-7687] Add test case in input_validator
Browse files Browse the repository at this point in the history
  • Loading branch information
nmayorsplit committed Nov 27, 2023
1 parent eb2fa87 commit d308e41
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion splitio/client/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func setupRedisFactory(apikey string, cfg *conf.SplitSdkConfig, logger logging.L

if len(cfg.Advanced.FlagSetFilter) != 0 {
cfg.Advanced.FlagSetFilter = []string{}
logger.Debug("FlagSets filter is not applicable for Consumer modes where the SDK does not keep rollout data in sync. FlagSet filter was discarded")
logger.Warning("FlagSets filter is not applicable for Consumer modes where the SDK does not keep rollout data in sync. FlagSet filter was discarded")
}
flagSetFilter := flagsets.NewFlagSetFilter([]string{})

Expand Down
64 changes: 63 additions & 1 deletion splitio/client/input_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/splitio/go-client/v6/splitio/conf"
commonsCfg "github.com/splitio/go-split-commons/v5/conf"
spConf "github.com/splitio/go-split-commons/v5/conf"
"github.com/splitio/go-split-commons/v5/dtos"
"github.com/splitio/go-split-commons/v5/flagsets"
Expand All @@ -26,6 +27,7 @@ import (
"github.com/splitio/go-split-commons/v5/storage/inmemory/mutexmap"
"github.com/splitio/go-split-commons/v5/storage/inmemory/mutexqueue"
"github.com/splitio/go-split-commons/v5/storage/mocks"
"github.com/splitio/go-split-commons/v5/storage/redis"
"github.com/splitio/go-split-commons/v5/synchronizer"
"github.com/splitio/go-toolkit/v5/logging"
)
Expand Down Expand Up @@ -565,6 +567,20 @@ func TestInMemoryFactoryFlagSets(t *testing.T) {
fmt.Fprintln(w, "ok")
postChannel <- "finished"
case "/segmentChanges":
case "/metrics/config":
rBody, _ := ioutil.ReadAll(r.Body)
var dataInPost dtos.Config
err := json.Unmarshal(rBody, &dataInPost)
if err != nil {
t.Error(err)
return
}
if dataInPost.FlagSetsInvalid != 4 {
t.Error("invalid flag sets should be 4")
}
if dataInPost.FlagSetsTotal != 7 {
t.Error("total flag sets should be 7")
}
default:
fmt.Fprintln(w, "ok")
return
Expand All @@ -586,7 +602,7 @@ func TestInMemoryFactoryFlagSets(t *testing.T) {

factory, _ := NewSplitFactory("test", cfg)
client := factory.Client()
errBlock := client.BlockUntilReady(10)
errBlock := client.BlockUntilReady(15)

if errBlock != nil {
t.Error("client should be ready")
Expand All @@ -601,6 +617,52 @@ func TestInMemoryFactoryFlagSets(t *testing.T) {
t.Error("Wrong message")
}
mW.Reset()

client.Destroy()
}

func TestConsumerFactoryFlagSets(t *testing.T) {
logger := getMockedLogger()
sdkConf := conf.Default()
sdkConf.OperationMode = conf.RedisConsumer
sdkConf.Advanced.FlagSetFilter = []string{"a", "b"}
sdkConf.Logger = logger

factory, _ := NewSplitFactory("something", sdkConf)
if !mW.Matches("FlagSets filter is not applicable for Consumer modes where the SDK does not keep rollout data in sync. FlagSet filter was discarded") {
t.Error("Wrong message")
}
if !factory.IsReady() {
t.Error("Factory should be ready immediately")
}
client := factory.Client()
if !client.factory.IsReady() {
t.Error("Client should be ready immediately")
}

err := client.BlockUntilReady(1)
if err != nil {
t.Error("Error was not expected")
}

manager := factory.Manager()
if !manager.factory.IsReady() {
t.Error("Manager should be ready immediately")
}
err = manager.BlockUntilReady(1)
if err != nil {
t.Error("Error was not expected")
}

prefixedClient, _ := redis.NewRedisClient(&commonsCfg.RedisConfig{
Host: "localhost",
Port: 6379,
Password: "",
Prefix: "",
}, logging.NewLogger(&logging.LoggerOptions{}))
deleteDataGenerated(prefixedClient)

client.Destroy()
}

func TestNotReadyYet(t *testing.T) {
Expand Down

0 comments on commit d308e41

Please sign in to comment.