Skip to content

Commit

Permalink
Fix cache key generation
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein committed Dec 21, 2023
1 parent 0d7a3a2 commit 45090ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 15 additions & 3 deletions configcat_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"github.com/configcat/go-sdk/v9/configcatcache"
"io/ioutil"
"net/http"
"reflect"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 45090ff

Please sign in to comment.