Module ldclient_testdata

TestData server.

Behaviours: gen_server.

Description

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_users(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_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
  1. rule operators other than "in" and "not in", or
  2. percentage rollouts.
If the same ldclient_testdata instance is used to configure multiple ldclient_instance instances, any changes made to the data will propagate to all of the instances

Function Index

child_spec/2
flag/1Creates or copies a ldclient_flagbuilder:flag_builder() for building a test flag configuration.
flag/2Creates or copies a ldclient_flagbuilder:flag_builder() for building a test flag configuration.
update/1Updates the test data with the specified flag configuration.
update/2Updates the test data with the specified flag configuration.

Function Details

child_spec/2

child_spec(Tag::atom(), Args::[term()]) -> supervisor:child_spec()

flag/1

flag(FlagKey::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 users 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.

Once you have set the desired configuration, pass the builder to update/2.

See also: update/1.

flag/2

flag(Tag::atom() | pid(), FlagKey::string()) -> {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 users 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.

Once you have set the desired configuration, pass the builder to update/2.

See also: update/2.

update/1

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 any ldclient_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/2

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 any ldclient_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