...

Source file src/github.com/launchdarkly/go-server-sdk/v6/internal/datasource/data_source_test_helpers_test.go

Documentation: github.com/launchdarkly/go-server-sdk/v6/internal/datasource

     1  package datasource
     2  
     3  import (
     4  	"net/http"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/launchdarkly/go-server-sdk/v6/internal/sharedtest/mocks"
     9  
    10  	"github.com/launchdarkly/go-server-sdk/v6/internal/datastore"
    11  	"github.com/launchdarkly/go-server-sdk/v6/internal/sharedtest"
    12  	"github.com/launchdarkly/go-server-sdk/v6/subsystems"
    13  
    14  	th "github.com/launchdarkly/go-test-helpers/v3"
    15  )
    16  
    17  const testSDKKey = "test-sdk-key"
    18  
    19  func basicClientContext() subsystems.ClientContext {
    20  	return sharedtest.NewSimpleTestContext(testSDKKey)
    21  }
    22  
    23  func withMockDataSourceUpdates(action func(*mocks.MockDataSourceUpdates)) {
    24  	d := mocks.NewMockDataSourceUpdates(datastore.NewInMemoryDataStore(sharedtest.NewTestLoggers()))
    25  	// currently don't need to defer any cleanup actions
    26  	action(d)
    27  }
    28  
    29  func waitForReadyWithTimeout(t *testing.T, closeWhenReady <-chan struct{}, timeout time.Duration) {
    30  	if !th.AssertChannelClosed(t, closeWhenReady, timeout) {
    31  		t.FailNow()
    32  	}
    33  }
    34  
    35  type urlAppendingHTTPTransport string
    36  
    37  func urlAppendingHTTPClientFactory(suffix string) func() *http.Client {
    38  	return func() *http.Client {
    39  		return &http.Client{Transport: urlAppendingHTTPTransport(suffix)}
    40  	}
    41  }
    42  
    43  func (t urlAppendingHTTPTransport) RoundTrip(r *http.Request) (*http.Response, error) {
    44  	req := *r
    45  	req.URL.Path = req.URL.Path + string(t)
    46  	return http.DefaultTransport.RoundTrip(&req)
    47  }
    48  

View as plain text