...

Source file src/github.com/launchdarkly/go-sdk-events/v2/testdata_test.go

Documentation: github.com/launchdarkly/go-sdk-events/v2

     1  package ldevents
     2  
     3  import (
     4  	"encoding/json"
     5  	"time"
     6  
     7  	"github.com/launchdarkly/go-jsonstream/v3/jwriter"
     8  	"github.com/launchdarkly/go-sdk-common/v3/ldcontext"
     9  	"github.com/launchdarkly/go-sdk-common/v3/ldreason"
    10  	"github.com/launchdarkly/go-sdk-common/v3/ldtime"
    11  	"github.com/launchdarkly/go-sdk-common/v3/ldvalue"
    12  )
    13  
    14  const (
    15  	testContextKey = "userKey"
    16  
    17  	sdkKey = "SDK_KEY"
    18  
    19  	fakeBaseURI       = "https://fake-server"
    20  	fakeEventsURI     = fakeBaseURI + "/bulk"
    21  	fakeDiagnosticURI = fakeBaseURI + "/diagnostic"
    22  
    23  	fakeTime = ldtime.UnixMillisecondTime(100000)
    24  
    25  	briefRetryDelay = 50 * time.Millisecond
    26  )
    27  
    28  var (
    29  	testValue                   = ldvalue.String("value")
    30  	testEvalDetailWithoutReason = ldreason.NewEvaluationDetail(testValue, 2, noReason)
    31  	undefInt                    = ldvalue.OptionalInt{}
    32  	arbitraryJSONData           = []byte(`"hello"`)
    33  )
    34  
    35  func fakeTimeFn() ldtime.UnixMillisecondTime { return fakeTime }
    36  
    37  func basicContext() EventInputContext {
    38  	return Context(ldcontext.NewBuilder(testContextKey).Name("Red").Build())
    39  }
    40  
    41  func basicConfigWithoutPrivateAttrs() EventsConfiguration {
    42  	return EventsConfiguration{
    43  		Capacity:              1000,
    44  		FlushInterval:         1 * time.Hour,
    45  		UserKeysCapacity:      1000,
    46  		UserKeysFlushInterval: 1 * time.Hour,
    47  	}
    48  }
    49  
    50  func contextJSON(c EventInputContext, config EventsConfiguration) json.RawMessage {
    51  	formatter := newEventContextFormatter(config)
    52  	w := jwriter.NewWriter()
    53  	formatter.WriteContext(&w, &c)
    54  	if err := w.Error(); err != nil {
    55  		panic(err)
    56  	}
    57  	return w.Bytes()
    58  }
    59  

View as plain text