Safe Haskell | None |
---|---|
Language | Haskell2010 |
A mechanism for providing dynamically updatable feature flag state in a simplified form to an SDK client in test scenarios.
Unlike LaunchDarkly.Server.Integrations.FileData, this mechanism does not use any external resources. It provides only
the data that the application has put into it using the update
function.
td <- TestData.newTestData update td =<< (flag td "flag-key-1" <&> booleanFlag <&> variationForAllUsers True) let config = makeConfig "sdkKey" & configSetDataSourceFactory (dataSourceFactory td) client <- makeClient config -- flags can be updated at any time: update td =<< (flag td "flag-key-2" <&> variationForUser "some-user-key" True <&> fallthroughVariation False)
The above example uses a simple boolean flag, but more complex configurations are possible using
the methods of the FlagBuilder
that is returned by flag
. FlagBuilder
supports many of the ways a flag can be configured on the LaunchDarkly dashboard, but does not
currently support:
- Rule operators other than "in" and "not in"
- Percentage rollouts.
If the same TestData
instance is used to configure multiple Client
instances,
any changes made to the data will propagate to all of the Client
s.
see LaunchDarkly.Server.Integrations.FileData
Since: 2.2.1
Synopsis
- data TestData
- newTestData :: IO TestData
- flag :: TestData -> Text -> IO FlagBuilder
- update :: TestData -> FlagBuilder -> IO ()
- dataSourceFactory :: TestData -> DataSourceFactory
- data FlagBuilder
- booleanFlag :: FlagBuilder -> FlagBuilder
- on :: Bool -> FlagBuilder -> FlagBuilder
- fallthroughVariation :: Variation val => val -> FlagBuilder -> FlagBuilder
- offVariation :: Variation val => val -> FlagBuilder -> FlagBuilder
- variationForAllUsers :: Variation val => val -> FlagBuilder -> FlagBuilder
- valueForAllUsers :: ToJSON value => value -> FlagBuilder -> FlagBuilder
- variationForUser :: Variation val => UserKey -> val -> FlagBuilder -> FlagBuilder
- variations :: [Value] -> FlagBuilder -> FlagBuilder
- ifMatch :: UserAttribute -> [Value] -> FlagBuilder -> FlagRuleBuilder
- ifNotMatch :: UserAttribute -> [Value] -> FlagBuilder -> FlagRuleBuilder
- type VariationIndex = Integer
- data FlagRuleBuilder
- andMatch :: UserAttribute -> [Value] -> FlagRuleBuilder -> FlagRuleBuilder
- andNotMatch :: UserAttribute -> [Value] -> FlagRuleBuilder -> FlagRuleBuilder
- thenReturn :: Variation val => val -> FlagRuleBuilder -> FlagBuilder
Documentation
Creates a new instance of the test data source.
:: TestData | |
-> Text | the flag key |
-> IO FlagBuilder | a flag configuration builder |
Creates or copies a FlagBuilder
for building a test flag configuration.
If this flag key has already been defined in this 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 FlagBuilder
methods.
Once you have set the desired configuration, pass the builder to update
.
see update
:: TestData | |
-> FlagBuilder | a flag configuration builder |
-> IO () |
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 Client
instance(s) that you have
already configured to use this TestData
. If no Client
has been started yet,
it simply adds this flag to the test data which will be provided to any Client
that
you subsequently configure.
Any subsequent changes to this FlagBuilder
instance do not affect the test data,
unless you call update
see flag
dataSourceFactory :: TestData -> DataSourceFactory Source #
FlagBuilder
data FlagBuilder Source #
A builder for feature flag configurations to be used with LaunchDarkly.Server.Integrations.TestData.
Instances
Show FlagBuilder Source # | |
Defined in LaunchDarkly.Server.Integrations.TestData.FlagBuilder showsPrec :: Int -> FlagBuilder -> ShowS # show :: FlagBuilder -> String # showList :: [FlagBuilder] -> ShowS # |
booleanFlag :: FlagBuilder -> FlagBuilder Source #
A shortcut for setting the flag to use the standard boolean configuration.
This is the default for all new flags created with flag
. The flag
will have two variations, True
and False
(in that order); it will return
False
whenever targeting is off, and True
when targeting is on if no other
settings specify otherwise.
:: Bool | isOn |
-> FlagBuilder | |
-> FlagBuilder |
Sets targeting to be on or off for this flag.
The effect of this depends on the rest of the flag configuration, just as it does on the
real LaunchDarkly dashboard. In the default configuration that you get from calling
flag
with a new flag key, the flag will return False
whenever targeting is off, and True
when targeting is on.
:: Variation val | |
=> val |
|
-> FlagBuilder | |
-> FlagBuilder |
Specifies the fallthrough variation. The fallthrough is the value that is returned if targeting is on and the user was not matched by a more specific target or rule.
If the flag was previously configured with other variations and the variation specified is a boolean, this also changes it to a boolean flag.
:: Variation val | |
=> val |
|
-> FlagBuilder | |
-> FlagBuilder |
Specifies the off variation for a flag. This is the variation that is returned whenever targeting is off.
If the flag was previously configured with other variations and the variation specified is a boolean, this also changes it to a boolean flag.
:: Variation val | |
=> val |
|
-> FlagBuilder | |
-> FlagBuilder |
Sets the flag to always return the specified variation for all users.
The variation is specified, Targeting is switched on, and any existing targets or rules are removed. The fallthrough variation is set to the specified value. The off variation is left unchanged.
If the flag was previously configured with other variations and the variation specified is a boolean, this also changes it to a boolean flag.
valueForAllUsers :: ToJSON value => value -> FlagBuilder -> FlagBuilder Source #
Sets the flag to always return the specified variation value for all users.
The value may be of any type that implements ToJSON
. This method changes the
flag to have only a single variation, which is this value, and to return the same
variation regardless of whether targeting is on or off. Any existing targets or rules
are removed.
:: Variation val | |
=> UserKey | a user key to target |
-> val |
|
-> FlagBuilder | |
-> FlagBuilder |
Sets the flag to return the specified variation for a specific user key when targeting is on.
This has no effect when targeting is turned off for the flag.
If the flag was previously configured with other variations and the variation specified is a boolean, this also changes it to a boolean flag.
:: [Value] | the desired variations |
-> FlagBuilder | |
-> FlagBuilder |
Changes the allowable variation values for the flag.
The value may be of any JSON type, as defined by Value
. For instance, a boolean flag
normally has [toJSON True, toJSON False]; a string-valued flag might have
[toJSON "red", toJSON "green"]; etc.
:: UserAttribute | attribute the user attribute to match against |
-> [Value] | values to compare to |
-> FlagBuilder | |
-> FlagRuleBuilder | call |
Starts defining a flag rule, using the "is one of" operator.
For example, this creates a rule that returns True
if the name is "Patsy" or "Edina":
testData & flag "flag" & ifMatch "name" [toJSON "Patsy", toJSON "Edina"] & thenReturn True
:: UserAttribute | attribute the user attribute to match against |
-> [Value] | values to compare to |
-> FlagBuilder | |
-> FlagRuleBuilder | call |
Starts defining a flag rule, using the "is not one of" operator.
For example, this creates a rule that returns True
if the name is neither "Saffron" nor "Bubble"
testData & flag "flag" & ifNotMatch "name" [toJSON "Saffron", toJSON "Bubble"] & thenReturn True
type VariationIndex = Integer Source #
FlagRuleBuilder
data FlagRuleBuilder Source #
A builder for feature flag rules to be used with FlagBuilder
.
In the LaunchDarkly model, a flag can have any number of rules, and a rule can have any number of clauses. A clause is an individual test such as "name is 'X'". A rule matches a user if all of the rule's clauses match the user.
To start defining a rule, use one of the matching functions such as ifMatch
or ifNotMatch
.
This defines the first clause for the rule.
Optionally, you may add more clauses with the rule builder functions such as andMatch
and andNotMatch
.
Finally, call thenReturn
to finish defining the rule.
Instances
Show FlagRuleBuilder Source # | |
Defined in LaunchDarkly.Server.Integrations.TestData.FlagBuilder showsPrec :: Int -> FlagRuleBuilder -> ShowS # show :: FlagRuleBuilder -> String # showList :: [FlagRuleBuilder] -> ShowS # |
:: UserAttribute | the user attribute to match against |
-> [Value] | values to compare to |
-> FlagRuleBuilder | |
-> FlagRuleBuilder |
Adds another clause, using the "is one of" operator.
For example, this creates a rule that returns True
if the name is "Patsy" and the
country is "gb":
testData & flag "flag" & ifMatch "name" [toJSON "Patsy"] & andMatch "country" [toJSON "gb"] & thenReturn True
:: UserAttribute | the user attribute to match against |
-> [Value] | values to compare to |
-> FlagRuleBuilder | |
-> FlagRuleBuilder |
Adds another clause, using the "is not one of" operator.
For example, this creates a rule that returns True
if the name is "Patsy" and the
country is not "gb":
testData & flag "flag" & ifMatch "name" [toJSON "Patsy"] & andNotMatch "country" [toJSON "gb"] & thenReturn True
:: Variation val | |
=> val |
|
-> FlagRuleBuilder | |
-> FlagBuilder |
Finishes defining the rule, specifying the result as either a boolean or a variation index.
If the flag was previously configured with other variations and the variation specified is a boolean, this also changes it to a boolean flag.