Documentation ¶
Overview ¶
Package mockld provides tools for simulating LaunchDarkly service endpoints.
Index ¶
- type DataItemKind
- type Event
- type Events
- type EventsService
- type MockBigSegmentStoreService
- 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 ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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, credential string, logger framework.Logger) *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 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 SDKData ¶
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.
func EmptyServerSDKData ¶
func EmptyServerSDKData() ServerSDKData
func (ServerSDKData) JSONString ¶
func (d ServerSDKData) JSONString() string
func (ServerSDKData) SDKKind ¶
func (d ServerSDKData) SDKKind() SDKKind
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, 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{})
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)