Skip to content

Commit

Permalink
add polling test
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld committed Nov 18, 2024
1 parent 3ebf86e commit 3ba5253
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sdktests/client_side_poll_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func doClientSidePollRequestTest(t *ldtest.T) {
pollTests.InitialRequestIncludesCorrectEtag(t)
}

if t.Capabilities().Has(servicedef.CapabilityHTTPProxy) {
pollTests.RequestViaHTTPProxy(t)
}

requestPathMatcher := func(method flagRequestMethod) m.Matcher {
switch sdkKind {
case mockld.RokuSDK:
Expand Down
36 changes: 36 additions & 0 deletions sdktests/common_tests_poll_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sdktests

import (
"fmt"
"net/url"
"strings"
"time"

Expand Down Expand Up @@ -404,3 +405,38 @@ func (c CommonPollingTests) InitialRequestIncludesCorrectEtag(t *ldtest.T) {
})
})
}

func (c CommonPollingTests) RequestViaHTTPProxy(t *ldtest.T) {
t.Run("http proxy", func(t *ldtest.T) {
dataSource := NewSDKDataSource(t, nil, DataSourceOptionPolling())

// The idea here is that we'll configure the SDK's service endpoints with an arbitrary host, but with the
// correct path that the test harness expects (like /endpoints/1). Then, we'll inject the actual test harness's
// endpoint via the HTTP Proxy configuration.
//
// The SDK should therefore:
// 1. Open a socket to the test harness's host and port
// 2. Send an HTTP request that has the arbitrary host and the correct path
//
// If the SDK didn't support proxying, then it would attempt to connect to the arbitrary host and
// the harness should fail the connection assertion.
pollURI := strings.Replace(dataSource.Endpoint().BaseURL(), "localhost", "not.valid.local", 1)

u, err := url.Parse(dataSource.Endpoint().BaseURL())
if err != nil {
t.Errorf("unexpected error parsing URL: %s", err)
t.FailNow()
}
u.Path = ""

_ = NewSDKClient(t, c.baseSDKConfigurationPlus(
WithPollingConfig(servicedef.SDKConfigPollingParams{
BaseURI: pollURI,
}),
c.withHTTPProxy(u.String()),
)...)

_, err = dataSource.Endpoint().AwaitConnection(time.Second)
assert.NoError(t, err)
})
}

0 comments on commit 3ba5253

Please sign in to comment.