Skip to content

Commit

Permalink
feat: update config url to support v2 configs (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
suthar26 authored Aug 20, 2024
1 parent eea4d97 commit 1e99be1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-test-harness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: DevCycleHQ/test-harness@main
env:
SDK_CAPABILITIES: '["cloud","edgeDB","clientCustomData","multithreading","defaultReason","etagReporting","lastModifiedHeader","sdkConfigEvent","clientUUID"]'
SDK_CAPABILITIES: '["cloud","edgeDB","clientCustomData","multithreading","defaultReason","etagReporting","lastModifiedHeader","sdkConfigEvent","clientUUID","v2Config"]'
with:
sdks-to-test: '["go"]'
sdk-github-sha: ${{github.event.pull_request.head.sha}}
Expand Down
5 changes: 3 additions & 2 deletions configmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/devcyclehq/go-server-sdk/v2/api"
"io"
"net/http"
"sync"
"time"

"github.com/devcyclehq/go-server-sdk/v2/api"

"github.com/devcyclehq/go-server-sdk/v2/util"
)

Expand Down Expand Up @@ -392,7 +393,7 @@ func (e *EnvironmentConfigManager) setConfig(config []byte, eTag, rayId, lastMod
func (e *EnvironmentConfigManager) getConfigURL() string {
configBasePath := e.cfg.ConfigCDNBasePath

return fmt.Sprintf("%s/config/v1/server/%s.json", configBasePath, e.sdkKey)
return fmt.Sprintf("%s/config/v2/server/%s.json", configBasePath, e.sdkKey)
}

func (e *EnvironmentConfigManager) HasConfig() bool {
Expand Down
23 changes: 13 additions & 10 deletions configmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package devcycle

import (
"fmt"
"github.com/devcyclehq/go-server-sdk/v2/api"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/require"
"sync"
"testing"
"time"

"github.com/devcyclehq/go-server-sdk/v2/api"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/require"
)

type recordingConfigReceiver struct {
Expand Down Expand Up @@ -62,6 +63,8 @@ func (r *recordingConfigReceiver) GetLastModified() string {
return r.lastModified
}

const CONFIG_SDK_URL = "https://config-cdn.devcycle.com/config/v2/server/%s.json"

func TestEnvironmentConfigManager_fetchConfig_success(t *testing.T) {

sdkKey, _ := httpConfigMock(200)
Expand Down Expand Up @@ -113,7 +116,7 @@ func TestEnvironmentConfigManager_fetchConfig_refuseOld(t *testing.T) {
secondResponse := httpCustomConfigMock(sdkKey, 200, test_config, true, olderHeaders)
thirdResponse := httpCustomConfigMock(sdkKey, 200, test_config, true, newestHeaders)

httpmock.RegisterResponder("GET", "https://config-cdn.devcycle.com/config/v1/server/"+sdkKey+".json",
httpmock.RegisterResponder("GET", fmt.Sprintf(CONFIG_SDK_URL, sdkKey),
firstResponse.Then(secondResponse).Then(thirdResponse),
)
localBucketing := &recordingConfigReceiver{}
Expand Down Expand Up @@ -191,7 +194,7 @@ func TestEnvironmentConfigManager_fetchConfig_retries500(t *testing.T) {

error500Response := httpCustomConfigMock(sdkKey, 500, "Connection error", true)

httpmock.RegisterResponder("GET", "https://config-cdn.devcycle.com/config/v1/server/"+sdkKey+".json",
httpmock.RegisterResponder("GET", fmt.Sprintf(CONFIG_SDK_URL, sdkKey),
errorResponseChain(sdkKey, error500Response, CONFIG_RETRIES),
)

Expand Down Expand Up @@ -226,7 +229,7 @@ func TestEnvironmentConfigManager_fetchConfig_retries_until_abort(t *testing.T)
firstResponse := httpCustomConfigMock(sdkKey, 200, test_config, true, initialHeaders)
secondResponse := httpCustomConfigMock(sdkKey, 200, test_config, true, olderHeaders)

httpmock.RegisterResponder("GET", "https://config-cdn.devcycle.com/config/v1/server/"+sdkKey+".json",
httpmock.RegisterResponder("GET", fmt.Sprintf(CONFIG_SDK_URL, sdkKey),
firstResponse.Then(secondResponse).Then(secondResponse).Then(secondResponse),
)
localBucketing := &recordingConfigReceiver{}
Expand Down Expand Up @@ -275,7 +278,7 @@ func TestEnvironmentConfigManager_fetchConfig_retries_until_abort(t *testing.T)
func TestEnvironmentConfigManager_fetchConfig_retries_errors(t *testing.T) {
sdkKey := generateTestSDKKey()
connectionErrorResponse := httpCustomConfigMock(sdkKey, 500, "Connection error", true)
httpmock.RegisterResponder("GET", "https://config-cdn.devcycle.com/config/v1/server/"+sdkKey+".json",
httpmock.RegisterResponder("GET", fmt.Sprintf(CONFIG_SDK_URL, sdkKey),
errorResponseChain(sdkKey, connectionErrorResponse, CONFIG_RETRIES),
)

Expand All @@ -301,7 +304,7 @@ func TestEnvironmentConfigManager_fetchConfig_retries_errors_sse(t *testing.T) {
httpSSEConnectionMock()

connectionErrorResponse := httpmock.NewErrorResponder(fmt.Errorf("connection error"))
httpmock.RegisterResponder("GET", "https://config-cdn.devcycle.com/config/v1/server/"+sdkKey+".json",
httpmock.RegisterResponder("GET", fmt.Sprintf(CONFIG_SDK_URL, sdkKey),
errorResponseChain(sdkKey, connectionErrorResponse, CONFIG_RETRIES, httpSSEConfigMock),
)

Expand All @@ -321,7 +324,7 @@ func TestEnvironmentConfigManager_fetchConfig_returns_errors(t *testing.T) {
sdkKey := generateTestSDKKey()
connectionErrorResponse := httpmock.NewErrorResponder(fmt.Errorf("connection error"))

httpmock.RegisterResponder("GET", "https://config-cdn.devcycle.com/config/v1/server/"+sdkKey+".json",
httpmock.RegisterResponder("GET", fmt.Sprintf(CONFIG_SDK_URL, sdkKey),
errorResponseChain(sdkKey, connectionErrorResponse, CONFIG_RETRIES+1),
)

Expand All @@ -338,7 +341,7 @@ func TestEnvironmentConfigManager_fetchConfig_returns_errors_sse(t *testing.T) {

connectionErrorResponse := httpmock.NewErrorResponder(fmt.Errorf("connection error"))
sdkKey := generateTestSDKKey()
httpmock.RegisterResponder("GET", "https://config-cdn.devcycle.com/config/v1/server/"+sdkKey+".json",
httpmock.RegisterResponder("GET", fmt.Sprintf(CONFIG_SDK_URL, sdkKey),
errorResponseChain(sdkKey, connectionErrorResponse, CONFIG_RETRIES+1),
)

Expand Down
4 changes: 3 additions & 1 deletion testing_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package devcycle
import (
_ "embed"
"flag"
"fmt"
"log"
"math/rand"
"net/http"
Expand Down Expand Up @@ -107,7 +108,8 @@ func httpCustomConfigMock(sdkKey string, respcode int, config string, skipRegist
return resp, nil
}
if !skipRegister {
httpmock.RegisterResponder("GET", "https://config-cdn.devcycle.com/config/v1/server/"+sdkKey+".json", responder)
const CONFIG_URL_FORMAT = "https://config-cdn.devcycle.com/config/v2/server/%s.json"
httpmock.RegisterResponder("GET", fmt.Sprintf(CONFIG_URL_FORMAT, sdkKey), responder)
}
return responder
}
Expand Down

0 comments on commit 1e99be1

Please sign in to comment.