unleash-client-java icon indicating copy to clipboard operation
unleash-client-java copied to clipboard

FakeUnleash doesn't take into account global activation/deactivation for certain isEnabled method

Open GFriedrich opened this issue 9 months ago • 2 comments

Describe the bug

The FakeUnleash method using the fallbackAction doesn't take into account the global activation/deactivation flags. Right now the code at https://github.com/Unleash/unleash-client-java/blob/b2ac9aee6aecbd3e968ed5c0e51bb5fca1c60452/src/main/java/io/getunleash/FakeUnleash.java#L39-L45 just checks whether a certain flag is configured. But if you use the global flags, then no specific feature is set. Therefore this method always falls back to the default action instead, which is unexpected. Therefore I would suggest to change the line of https://github.com/Unleash/unleash-client-java/blob/b2ac9aee6aecbd3e968ed5c0e51bb5fca1c60452/src/main/java/io/getunleash/FakeUnleash.java#L41 to something like

if ((!enableAll && !disableAll || excludedFeatures.containsKey(toggleName)) && !features.containsKey(toggleName)) {

Steps to reproduce the bug

  1. Use FakeUnleash and enable all flags by calling enableAll
  2. Run a method like isEnabled("abc", (a, b) -> false)
  3. See that it still returns false even though all flags have been enabled.

Expected behavior

FakeUnleash should correctly take into account global flags.

Logs, error output, etc.

No response

Screenshots

No response

Additional context

No response

Unleash version

9.2.0

Subscription type

None

Hosting type

None

SDK information (language and version)

No response

GFriedrich avatar May 03 '24 14:05 GFriedrich

Oh that's a nice catch, this probably isn't something we'll tackle immediately but we'd be more than happy to take a PR

sighphyre avatar May 06 '24 10:05 sighphyre

This is an oversight on our end. Your suggestion makes sense at first sight, feel free to push a PR!

Thanks 👍🏼

ivarconr avatar May 07 '24 21:05 ivarconr