Behaviours: gen_server.
TestData server
A mechanism for providing dynamically updatable feature flag state in a simplified form to an SDK client in test scenarios.
Unlike the file data mechanism, this does not use any external resources. It provides only the data that the application has put into it using the update/2 function.
{ok, Flag} = ldclient_testdata:flag("flag-key-1"), ldclient_testdata:update(ldclient_flagbuilder:variation_for_all(true, Flag)), Options = #{ datasource => testdata, send_events => false, feature_store => ldclient_storage_map }, ldclient:start_instance(SdkKey, Options), %% flags can be updated at any time: {ok, Flag2} = ldclient_testdata:flag("flag-key-2"), UpdatedFlag2 = ldclient_flagbuilder:fallthrough_variation(false, ldclient_flagbuilder:variation_for_context(<<"user">>, <<"some-user-key">>, true, Flag2)),
The above example uses a simple boolean flag, but more complex configurations
are possible using the functions in ldclient_flagbuilder
.
ldclient_flagbuilder
supports many of the ways a flag can be configured
on the LaunchDarkly dashboard, but does not currently support
ldclient_testdata
instance is used to configure multiple ldclient_instance
instances, any changes made to the data will propagate to all of the instances
child_spec/2 | |
flag/1 | Creates or copies a ldclient_flagbuilder:flag_builder()
for building a test flag configuration. |
flag/2 | Creates or copies a ldclient_flagbuilder:flag_builder()
for building a test flag configuration. |
update/1 | Updates the test data with the specified flag configuration. |
update/2 | Updates the test data with the specified flag configuration. |
child_spec(Tag::atom(), Args::[term()]) -> supervisor:child_spec()
flag(FlagKey::binary() | string()) -> {ok, ldclient_flagbuilder:flag_builder()}
FlagKey: the flag key
returns: a flag configuration builder
Creates or copies a ldclient_flagbuilder:flag_builder()
for building a test flag configuration.
If this flag key has already been defined in this ldclient_testdata
instance,
then the builder starts with the same configuration that was last provided for this flag.
Otherwise, it starts with a new default configuration in which the flag has true
and false
variations, is true
for all contexts when targeting is turned on and
false
otherwise, and currently has targeting turned on.
You can change any of those properties, and provide more complex behavior,
using the functions in ldclient_flagbuilder
.
update/2
.
See also: update/1.
flag(Tag::atom() | pid(), FlagKey::binary()) -> {ok, ldclient_flagbuilder:flag_builder()}
Tag: the tag or pid of the ldclient_testdata
instance
FlagKey: the flag key
returns: a flag configuration builder
Creates or copies a ldclient_flagbuilder:flag_builder()
for building a test flag configuration.
If this flag key has already been defined in this ldclient_testdata
instance,
then the builder starts with the same configuration that was last provided for this flag.
Otherwise, it starts with a new default configuration in which the flag has true
and false
variations, is true
for all contexts when targeting is turned on and
false
otherwise, and currently has targeting turned on.
You can change any of those properties, and provide more complex behavior,
using the functions in ldclient_flagbuilder
.
update/2
.
See also: update/2.
update(Flag::ldclient_flagbuilder:flag_builder()) -> ok
Flag: a flag configuration builder
Updates the test data with the specified flag configuration.
This has the same effect as if a flag were added or modified on the LaunchDarkly dashboard. It immediately propagates the flag change to anyldclient_instance(s)
that you have
already configured to use this ldclient_testdata
. If no ldclient_instance
has
been started yet, it simply adds this flag to the test data which will be provided
to any ldclient_instance
that you subsequently configure.
See also: flag/1.
update(Tag::atom() | pid(), Flag::ldclient_flagbuilder:flag_builder()) -> ok
Flag: a flag configuration builder
Updates the test data with the specified flag configuration.
This has the same effect as if a flag were added or modified on the LaunchDarkly dashboard. It immediately propagates the flag change to anyldclient_instance(s)
that you have
already configured to use this ldclient_testdata
. If no ldclient_instance
has
been started yet, it simply adds this flag to the test data which will be provided
to any ldclient_instance
that you subsequently configure.
See also: flag/2.
Generated by EDoc