mockld

package
v2.0.0-alpha.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package mockld provides tools for simulating LaunchDarkly service endpoints.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataItemKind

type DataItemKind string

type Event

type Event ldvalue.Value

Event is a JSON representation of an event. For convenience, this is stored as ldvalue.Value.

func (Event) AsValue

func (e Event) AsValue() ldvalue.Value

func (Event) JSONString

func (e Event) JSONString() string

func (Event) Kind

func (e Event) Kind() string

func (Event) MarshalJSON

func (e Event) MarshalJSON() ([]byte, error)

func (Event) String

func (e Event) String() string

func (*Event) UnmarshalJSON

func (e *Event) UnmarshalJSON(data []byte) error

type Events

type Events []Event

Events is an array of events. This specialized type provides helper methods.

func (Events) JSONString

func (es Events) JSONString() string

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

type SDKData

type SDKData interface {
	SDKKind() SDKKind
	Serialize() []byte
}

func BlockingUnavailableSDKData

func BlockingUnavailableSDKData(sdkKind SDKKind) SDKData

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 SDKKind

type SDKKind string
const (
	ServerSideSDK SDKKind = "server"
	MobileSDK     SDKKind = "mobile"
	JSClientSDK   SDKKind = "jsclient"
)

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 (*ServerSDKDataBuilder) Flag

func (*ServerSDKDataBuilder) RawFlag

func (*ServerSDKDataBuilder) RawSegment

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL