From 45090ff79fc25c489d30d9620fef3eb5f6e2f9b8 Mon Sep 17 00:00:00 2001 From: Peter Csajtai Date: Thu, 21 Dec 2023 15:00:51 +0100 Subject: [PATCH] Fix cache key generation --- config_fetcher.go | 2 +- configcat_client_test.go | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/config_fetcher.go b/config_fetcher.go index dcc4026..5e3bd6d 100644 --- a/config_fetcher.go +++ b/config_fetcher.go @@ -78,7 +78,7 @@ func newConfigFetcher(cfg Config, logger *leveledLogger, defaultUser User) fetch f := &configFetcher{ sdkKey: cfg.SDKKey, cache: cfg.Cache, - cacheKey: configcatcache.ProduceCacheKey(cfg.SDKKey, configcatcache.ConfigJSONCacheVersion, configcatcache.ConfigJSONName), + cacheKey: configcatcache.ProduceCacheKey(cfg.SDKKey, configcatcache.ConfigJSONName, configcatcache.ConfigJSONCacheVersion), overrides: cfg.FlagOverrides, hooks: cfg.Hooks, logger: logger, diff --git a/configcat_client_test.go b/configcat_client_test.go index 566f11a..4b79c76 100644 --- a/configcat_client_test.go +++ b/configcat_client_test.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "github.com/configcat/go-sdk/v9/configcatcache" "io/ioutil" "net/http" "reflect" @@ -954,8 +953,21 @@ func TestClient_OfflineOnlineMode(t *testing.T) { func TestCacheKey(t *testing.T) { c := qt.New(t) - c.Assert(configcatcache.ProduceCacheKey("test1", configcatcache.ConfigJSONName, configcatcache.ConfigJSONCacheVersion), qt.Equals, "7f845c43ecc95e202b91e271435935e6d1391e5d") - c.Assert(configcatcache.ProduceCacheKey("test2", configcatcache.ConfigJSONName, configcatcache.ConfigJSONCacheVersion), qt.Equals, "a78b7e323ef543a272c74540387566a22415148a") + tests := []struct { + key string + cacheKey string + }{ + {"test1", "7f845c43ecc95e202b91e271435935e6d1391e5d"}, + {"test2", "a78b7e323ef543a272c74540387566a22415148a"}, + } + + l := newTestLogger(t) + for _, test := range tests { + t.Run(fmt.Sprintf("%v", test), func(t *testing.T) { + f := newConfigFetcher(Config{SDKKey: test.key, PollingMode: Manual}, newLeveledLogger(l, LogLevelWarn, nil), nil).(*configFetcher) + c.Assert(f.cacheKey, qt.Equals, test.cacheKey) + }) + } } func TestSdkKeyValidation(t *testing.T) {