Skip to content

Commit b042a30

Browse files
committed
Add test for CMAB endpoint environment variable to increase coverage
1 parent 5e7b18b commit b042a30

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

pkg/optimizely/cache_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package optimizely
2020
import (
2121
"context"
2222
"fmt"
23+
"os"
2324
"sync"
2425
"testing"
2526
"time"
@@ -1107,6 +1108,37 @@ func (s *DefaultLoaderTestSuite) TestCMABWithExistingServices() {
11071108
s.NotNil(client.odpCache, "ODP Cache should still be configured")
11081109
}
11091110

1111+
func (s *DefaultLoaderTestSuite) TestCMABEndpointEnvironmentVariable() {
1112+
// Save original value and restore after test
1113+
originalEndpoint := os.Getenv("OPTIMIZELY_CMAB_PREDICTIONENDPOINT")
1114+
defer func() {
1115+
if originalEndpoint == "" {
1116+
os.Unsetenv("OPTIMIZELY_CMAB_PREDICTIONENDPOINT")
1117+
} else {
1118+
os.Setenv("OPTIMIZELY_CMAB_PREDICTIONENDPOINT", originalEndpoint)
1119+
}
1120+
}()
1121+
1122+
// Set custom endpoint
1123+
testEndpoint := "https://test.prediction.endpoint.com/predict/%s"
1124+
os.Setenv("OPTIMIZELY_CMAB_PREDICTIONENDPOINT", testEndpoint)
1125+
1126+
conf := config.ClientConfig{
1127+
SdkKeyRegex: "sdkkey",
1128+
CMAB: config.CMABConfig{
1129+
RequestTimeout: 5 * time.Second,
1130+
Cache: config.CMABCacheConfig{},
1131+
RetryConfig: config.CMABRetryConfig{},
1132+
},
1133+
}
1134+
1135+
loader := defaultLoader(config.AgentConfig{Client: conf}, s.registry, nil, s.upsMap, s.odpCacheMap, s.pcFactory, s.bpFactory)
1136+
client, err := loader("sdkkey")
1137+
1138+
s.NoError(err)
1139+
s.NotNil(client)
1140+
}
1141+
11101142
func TestDefaultLoaderTestSuite(t *testing.T) {
11111143
suite.Run(t, new(DefaultLoaderTestSuite))
11121144
}

0 commit comments

Comments
 (0)