Documentation ¶
Overview ¶
Package mockld provides tools for simulating LaunchDarkly service endpoints.
Index ¶
- Constants
- type CallHistory
- type ClientSDKData
- type ClientSDKDataBuilder
- func (b *ClientSDKDataBuilder) Build() ClientSDKData
- func (b *ClientSDKDataBuilder) Flag(key string, props ClientSDKFlag) *ClientSDKDataBuilder
- func (b *ClientSDKDataBuilder) FlagWithValue(key string, version int, value ldvalue.Value, variationIndex int) *ClientSDKDataBuilder
- func (b *ClientSDKDataBuilder) FullFlag(props ClientSDKFlagWithKey) *ClientSDKDataBuilder
- type ClientSDKFlag
- type ClientSDKFlagWithKey
- type DataItemKind
- type Event
- type Events
- type EventsService
- type HookCallbackService
- type MigrationCallbackService
- type MockBigSegmentStoreService
- type PollingService
- type RokuServer
- type SDKData
- type SDKKind
- type ServerSDKData
- type ServerSDKDataBuilder
- func (b *ServerSDKDataBuilder) Build() ServerSDKData
- func (b *ServerSDKDataBuilder) Flag(flags ...ldmodel.FeatureFlag) *ServerSDKDataBuilder
- func (b *ServerSDKDataBuilder) RawFlag(key string, data json.RawMessage) *ServerSDKDataBuilder
- func (b *ServerSDKDataBuilder) RawSegment(key string, data json.RawMessage) *ServerSDKDataBuilder
- func (b *ServerSDKDataBuilder) Segment(segments ...ldmodel.Segment) *ServerSDKDataBuilder
- type StreamingService
- func (s *StreamingService) PushDelete(namespace, key string, version int)
- func (s *StreamingService) PushEvent(eventName string, eventData interface{})
- func (s *StreamingService) PushUpdate(namespace, key string, data json.RawMessage)
- func (s *StreamingService) RefreshAll()
- func (s *StreamingService) Replay(channel, id string) chan eventsource.Event
- func (s *StreamingService) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *StreamingService) SetInitialData(data SDKData)
Constants ¶
const ( PollingPathServerSide = "/sdk/latest-all" PollingPathMobileGet = "/msdk/evalx/contexts/{context}" PollingPathMobileReport = "/msdk/evalx/context" PollingPathJSClientGet = "/sdk/evalx/{env}/contexts/{context}" PollingPathJSClientReport = "/sdk/evalx/{env}/context" // The following endpoint paths were used by older SDKs based on the user model rather than // the context model. New context-aware SDKs should always use the new paths. However, our // mock service still supports the old paths (just as the real LD services do). We have // specific tests to verify that the SDKs use the new paths; in all other tests, if the SDK // uses an old path, it will still work so that we don't confusingly see every test fail. // We do *not* support the very old "eval" (as opposed to "evalx") paths since the only SDKs // that used them are long past EOL. PollingPathMobileGetUser = "/msdk/evalx/users/{context}" PollingPathMobileReportUser = "/msdk/evalx/user" PollingPathJSClientGetUser = "/sdk/evalx/{env}/users/{context}" PollingPathJSClientReportUser = "/sdk/evalx/{env}/user" PollingPathPHPAllFlags = "/sdk/flags" PollingPathPHPFlag = "/sdk/flags/{key}" PollingPathPHPSegment = "/sdk/segments/{key}" PollingPathContextBase64Param = "{context}" PollingPathEnvIDParam = "{env}" )
const ( StreamingPathServerSide = "/all" StreamingPathMobileGet = "/meval/{context}" StreamingPathMobileReport = "/meval" StreamingPathRokuHandshake = "/handshake" StreamingPathRokuEvaluate = "/mevalalternate" StreamingPathJSClientGet = "/eval/{env}/{context}" StreamingPathJSClientReport = "/eval/{env}" StreamingPathContextBase64Param = "{context}" StreamingPathEnvIDParam = "{env}" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallHistory ¶ added in v2.2.0
type CallHistory struct {
// contains filtered or unexported fields
}
func (*CallHistory) GetCallOrder ¶ added in v2.2.0
func (c *CallHistory) GetCallOrder() int
func (*CallHistory) GetOrigin ¶ added in v2.2.0
func (c *CallHistory) GetOrigin() ldmigration.Origin
type ClientSDKData ¶
type ClientSDKData map[string]ClientSDKFlag
ClientSDKData contains simulated LaunchDarkly environment data for a client-side SDK.
This does not include flag or segment configurations, but only flag evaluation results for a specific user.
func EmptyClientSDKData ¶
func EmptyClientSDKData() ClientSDKData
func (ClientSDKData) JSONString ¶
func (d ClientSDKData) JSONString() string
func (ClientSDKData) Serialize ¶
func (d ClientSDKData) Serialize() []byte
func (ClientSDKData) WithoutReasons ¶
func (d ClientSDKData) WithoutReasons() ClientSDKData
type ClientSDKDataBuilder ¶
type ClientSDKDataBuilder struct {
// contains filtered or unexported fields
}
func NewClientSDKDataBuilder ¶
func NewClientSDKDataBuilder() *ClientSDKDataBuilder
func (*ClientSDKDataBuilder) Build ¶
func (b *ClientSDKDataBuilder) Build() ClientSDKData
func (*ClientSDKDataBuilder) Flag ¶
func (b *ClientSDKDataBuilder) Flag(key string, props ClientSDKFlag) *ClientSDKDataBuilder
func (*ClientSDKDataBuilder) FlagWithValue ¶
func (b *ClientSDKDataBuilder) FlagWithValue( key string, version int, value ldvalue.Value, variationIndex int, ) *ClientSDKDataBuilder
func (*ClientSDKDataBuilder) FullFlag ¶
func (b *ClientSDKDataBuilder) FullFlag(props ClientSDKFlagWithKey) *ClientSDKDataBuilder
type ClientSDKFlag ¶
type ClientSDKFlag struct { Value ldvalue.Value `json:"value"` Variation o.Maybe[int] `json:"variation"` Reason o.Maybe[ldreason.EvaluationReason] `json:"reason"` Version int `json:"version"` FlagVersion o.Maybe[int] `json:"flagVersion"` TrackEvents bool `json:"trackEvents"` TrackReason bool `json:"trackReason"` DebugEventsUntilDate o.Maybe[ldtime.UnixMillisecondTime] `json:"debugEventsUntilDate"` }
ClientSDKFlag contains the flag evaluation results for a single flag in ClientSDKData.
type ClientSDKFlagWithKey ¶
type ClientSDKFlagWithKey struct { ClientSDKFlag Key string `json:"key"` }
ClientSDKFlagWithKey is used only in stream updates, where the key is within the same object.
type DataItemKind ¶
type DataItemKind string
type Event ¶
Event is a JSON representation of an event. For convenience, this is stored as ldvalue.Value.
func (Event) JSONString ¶
func (Event) MarshalJSON ¶
func (*Event) UnmarshalJSON ¶
type Events ¶
type Events []Event
Events is an array of events. This specialized type provides helper methods.
func (Events) JSONString ¶
type EventsService ¶
type EventsService struct { AnalyticsEventPayloads chan Events // contains filtered or unexported fields }
EventsService is a simulation of the LaunchDarkly event-recorder service, allowing tests to receive event data from an SDK. This is a low-level component that tests normally don't need to interact with directly; most tests use the sdktests.SDKEventSink facade.
func NewEventsService ¶
func NewEventsService(sdkKind SDKKind, logger framework.Logger, requireGzip bool) *EventsService
func (*EventsService) AwaitAnalyticsEventPayload ¶
func (s *EventsService) AwaitAnalyticsEventPayload(timeout time.Duration) (Events, bool)
func (*EventsService) ServeHTTP ¶
func (s *EventsService) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*EventsService) SetHostTimeOverride ¶
func (s *EventsService) SetHostTimeOverride(t time.Time)
func (*EventsService) SetIgnoreDuplicatePayload ¶
func (s *EventsService) SetIgnoreDuplicatePayload(ignore bool)
SetIgnoreDuplicatePayload sets whether we should keep track of X-LaunchDarkly-Payload-Id header values we have seen at this endpoint and ignore any posts containing the same header value. This is true by default; tests would only set it to false if they want to verify that a failed post was retried.
The rationale for this being the default behavior is that an SDK might, due to unpredictable network issues, think an event post had failed when it really succeeded, and retry the post. We don't want that to disrupt tests. The payload ID is always the same in the case of a retry for this very reason-- it allows event-recorder to ignore accidental redundant posts. We trust that SDKs will generate reasonably unique payload IDs for posts that are not retries.
type HookCallbackService ¶ added in v2.9.0
type HookCallbackService struct { CallChannel chan servicedef.HookExecutionPayload // contains filtered or unexported fields }
func NewHookCallbackService ¶ added in v2.9.0
func NewHookCallbackService( testHarness *harness.TestHarness, logger framework.Logger, ) *HookCallbackService
func (*HookCallbackService) Close ¶ added in v2.9.0
func (h *HookCallbackService) Close()
func (*HookCallbackService) GetURL ¶ added in v2.9.0
func (h *HookCallbackService) GetURL() string
type MigrationCallbackService ¶ added in v2.2.0
type MigrationCallbackService struct {
// contains filtered or unexported fields
}
func NewMigrationCallbackService ¶ added in v2.2.0
func NewMigrationCallbackService( testHarness *harness.TestHarness, logger framework.Logger, oldHandler func(w http.ResponseWriter, req *http.Request), newHandler func(w http.ResponseWriter, req *http.Request), ) *MigrationCallbackService
func (*MigrationCallbackService) Close ¶ added in v2.2.0
func (m *MigrationCallbackService) Close()
func (*MigrationCallbackService) GetCallHistory ¶ added in v2.2.0
func (m *MigrationCallbackService) GetCallHistory() []CallHistory
func (*MigrationCallbackService) NewEndpoint ¶ added in v2.2.0
func (m *MigrationCallbackService) NewEndpoint() *harness.MockEndpoint
func (*MigrationCallbackService) OldEndpoint ¶ added in v2.2.0
func (m *MigrationCallbackService) OldEndpoint() *harness.MockEndpoint
type MockBigSegmentStoreService ¶
type MockBigSegmentStoreService struct {
// contains filtered or unexported fields
}
MockBigSegmentStoreService is the low-level component providing the mock endpoints for the Big Segments test fixture. The higher-level component sdktests.BigSegmentStore decorates this to make it more convenient to use in test logic.
func NewMockBigSegmentStoreService ¶
func NewMockBigSegmentStoreService( getMetadata func() (ldtime.UnixMillisecondTime, error), getContextMembership func(string) (map[string]bool, error), logger framework.Logger, ) *MockBigSegmentStoreService
func (*MockBigSegmentStoreService) ServeHTTP ¶
func (m *MockBigSegmentStoreService) ServeHTTP(w http.ResponseWriter, r *http.Request)
type PollingService ¶
type PollingService struct {
// contains filtered or unexported fields
}
func NewPollingService ¶
func NewPollingService( initialData SDKData, sdkKind SDKKind, debugLogger framework.Logger, ) *PollingService
func (*PollingService) ServeHTTP ¶
func (p *PollingService) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*PollingService) SetData ¶
func (p *PollingService) SetData(data SDKData)
func (*PollingService) SetEtag ¶
func (p *PollingService) SetEtag(etag string)
func (*PollingService) WithGzipCompression ¶ added in v2.8.0
func (p *PollingService) WithGzipCompression(enable bool) *PollingService
type RokuServer ¶
type RokuServer struct {
// contains filtered or unexported fields
}
func (*RokuServer) ServeHandshake ¶
func (srv *RokuServer) ServeHandshake(baseWriter http.ResponseWriter, req *http.Request)
type SDKData ¶
type SDKData interface {
Serialize() []byte
}
func BlockingUnavailableSDKData ¶
BlockingUnavailableSDKData returns an object that will cause the mock streaming service *not* to provide any data. It will accept connections, but then hang. This allows us to simulate a state where the SDK client times out without initializing, because it has not received any "put" event.
type ServerSDKData ¶
type ServerSDKData map[DataItemKind]map[string]json.RawMessage
ServerSDKData contains simulated LaunchDarkly environment data for a server-side SDK.
This includes the full JSON configuration of every flag and segment, in the same format that is used in streaming and polling responses.
We use this for both regular server-side SDKs and the PHP SDK.
func EmptyServerSDKData ¶
func EmptyServerSDKData() ServerSDKData
func (ServerSDKData) JSONString ¶
func (d ServerSDKData) JSONString() string
func (ServerSDKData) Serialize ¶
func (d ServerSDKData) Serialize() []byte
func (*ServerSDKData) UnmarshalJSON ¶
func (d *ServerSDKData) UnmarshalJSON(data []byte) error
type ServerSDKDataBuilder ¶
type ServerSDKDataBuilder struct {
// contains filtered or unexported fields
}
func NewServerSDKDataBuilder ¶
func NewServerSDKDataBuilder() *ServerSDKDataBuilder
func (*ServerSDKDataBuilder) Build ¶
func (b *ServerSDKDataBuilder) Build() ServerSDKData
func (*ServerSDKDataBuilder) Flag ¶
func (b *ServerSDKDataBuilder) Flag(flags ...ldmodel.FeatureFlag) *ServerSDKDataBuilder
func (*ServerSDKDataBuilder) RawFlag ¶
func (b *ServerSDKDataBuilder) RawFlag(key string, data json.RawMessage) *ServerSDKDataBuilder
func (*ServerSDKDataBuilder) RawSegment ¶
func (b *ServerSDKDataBuilder) RawSegment(key string, data json.RawMessage) *ServerSDKDataBuilder
func (*ServerSDKDataBuilder) Segment ¶
func (b *ServerSDKDataBuilder) Segment(segments ...ldmodel.Segment) *ServerSDKDataBuilder
type StreamingService ¶
type StreamingService struct {
// contains filtered or unexported fields
}
func NewStreamingService ¶
func NewStreamingService( initialData SDKData, sdkKind SDKKind, debugLogger framework.Logger, ) *StreamingService
func (*StreamingService) PushDelete ¶
func (s *StreamingService) PushDelete(namespace, key string, version int)
func (*StreamingService) PushEvent ¶
func (s *StreamingService) PushEvent(eventName string, eventData interface{})
PushEvent sends an SSE event to all clients that are currently connected to the stream-- or, if no client has connected yet, queues the event so that it will be sent (after the initial data) to the first client that connects. (The latter is necessary to avoid race conditions, since even after a connection is received on the stream endpoint, it is hard for the test logic to know when the HTTP handler has actually created a stream subscription for that connection. If we called the eventsource Publish method before a subscription existed, the event would be lost.)
func (*StreamingService) PushUpdate ¶
func (s *StreamingService) PushUpdate(namespace, key string, data json.RawMessage)
func (*StreamingService) RefreshAll ¶
func (s *StreamingService) RefreshAll()
func (*StreamingService) Replay ¶
func (s *StreamingService) Replay(channel, id string) chan eventsource.Event
func (*StreamingService) ServeHTTP ¶
func (s *StreamingService) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*StreamingService) SetInitialData ¶
func (s *StreamingService) SetInitialData(data SDKData)