flipper 1.4.2 → 1.5.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +70 -10
- data/lib/flipper/adapter.rb +24 -0
- data/lib/flipper/adapter_builder.rb +12 -1
- data/lib/flipper/adapters/actor_limit.rb +4 -3
- data/lib/flipper/adapters/cache_base.rb +17 -0
- data/lib/flipper/adapters/dual_write.rb +12 -0
- data/lib/flipper/adapters/failover.rb +15 -0
- data/lib/flipper/adapters/failsafe.rb +16 -0
- data/lib/flipper/adapters/http/client.rb +7 -3
- data/lib/flipper/adapters/http/redacted_debug_output.rb +70 -0
- data/lib/flipper/adapters/http.rb +42 -8
- data/lib/flipper/adapters/instrumented.rb +28 -0
- data/lib/flipper/adapters/memoizable.rb +21 -5
- data/lib/flipper/adapters/memory.rb +63 -31
- data/lib/flipper/adapters/poll.rb +51 -6
- data/lib/flipper/adapters/pstore.rb +15 -0
- data/lib/flipper/adapters/read_only.rb +1 -1
- data/lib/flipper/adapters/strict.rb +17 -1
- data/lib/flipper/adapters/sync/feature_synchronizer.rb +3 -1
- data/lib/flipper/adapters/sync/synchronizer.rb +20 -1
- data/lib/flipper/adapters/sync.rb +8 -0
- data/lib/flipper/adapters/wrapper.rb +7 -0
- data/lib/flipper/cli.rb +87 -22
- data/lib/flipper/cloud/configuration.rb +138 -19
- data/lib/flipper/cloud/dsl.rb +6 -0
- data/lib/flipper/cloud/memory_adapter.rb +43 -0
- data/lib/flipper/cloud/message_verifier.rb +1 -0
- data/lib/flipper/cloud/middleware.rb +8 -3
- data/lib/flipper/cloud/migrate.rb +3 -1
- data/lib/flipper/cloud/routes.rb +24 -2
- data/lib/flipper/cloud/shared_memory.rb +84 -0
- data/lib/flipper/cloud/telemetry.rb +56 -28
- data/lib/flipper/cloud/url_validator.rb +26 -0
- data/lib/flipper/cloud.rb +22 -4
- data/lib/flipper/configuration.rb +86 -3
- data/lib/flipper/dsl.rb +47 -3
- data/lib/flipper/engine.rb +64 -8
- data/lib/flipper/errors.rb +18 -0
- data/lib/flipper/export.rb +4 -0
- data/lib/flipper/exporters/json/export.rb +6 -0
- data/lib/flipper/exporters/json/v1.rb +5 -9
- data/lib/flipper/expression/constant.rb +6 -0
- data/lib/flipper/expression.rb +105 -1
- data/lib/flipper/expressions/comparable.rb +5 -0
- data/lib/flipper/expressions/feature_enabled.rb +11 -7
- data/lib/flipper/expressions/number.rb +2 -0
- data/lib/flipper/expressions/percentage.rb +3 -1
- data/lib/flipper/expressions/percentage_of_actors.rb +9 -0
- data/lib/flipper/expressions/random.rb +2 -0
- data/lib/flipper/expressions/sem_ver.rb +24 -0
- data/lib/flipper/expressions/time.rb +9 -1
- data/lib/flipper/feature.rb +153 -43
- data/lib/flipper/feature_check_context.rb +19 -1
- data/lib/flipper/gates/actor.rb +4 -1
- data/lib/flipper/gates/expression.rb +17 -2
- data/lib/flipper/gates/group.rb +1 -1
- data/lib/flipper/gates/percentage_of_actors.rb +19 -2
- data/lib/flipper/gates/percentage_of_time.rb +4 -1
- data/lib/flipper/groups.rb +66 -0
- data/lib/flipper/instrumentation/log_subscriber.rb +6 -1
- data/lib/flipper/instrumentation/subscriber.rb +21 -2
- data/lib/flipper/middleware/memoizer.rb +5 -2
- data/lib/flipper/named_configuration.rb +194 -0
- data/lib/flipper/named_proxy.rb +46 -0
- data/lib/flipper/poller.rb +39 -17
- data/lib/flipper/sem_ver.rb +84 -0
- data/lib/flipper/spec/shared_adapter_specs.rb +40 -0
- data/lib/flipper/sync_version.rb +61 -0
- data/lib/flipper/test_help.rb +50 -0
- data/lib/flipper/typecast.rb +15 -0
- data/lib/flipper/types/group.rb +2 -2
- data/lib/flipper/version.rb +1 -1
- data/lib/flipper.rb +183 -65
- data/lib/generators/flipper/setup_generator.rb +18 -0
- data/lib/generators/flipper/table_prefix.rb +44 -0
- data/lib/generators/flipper/templates/initializer.rb +7 -0
- data/lib/generators/flipper/templates/update/migrations/01_create_flipper_tables.rb.erb +13 -7
- data/lib/generators/flipper/templates/update/migrations/02_change_flipper_gates_value_to_text.rb.erb +12 -7
- data/lib/generators/flipper/update_generator.rb +3 -0
- metadata +42 -171
- data/.codeclimate.yml +0 -3
- data/.github/FUNDING.yml +0 -1
- data/.github/dependabot.yml +0 -6
- data/.github/workflows/ci.yml +0 -110
- data/.github/workflows/examples.yml +0 -105
- data/.github/workflows/release.yml +0 -54
- data/.rspec +0 -1
- data/.superset/config.json +0 -4
- data/CLAUDE.md +0 -93
- data/CODE_OF_CONDUCT.md +0 -46
- data/Dockerfile +0 -27
- data/Gemfile +0 -41
- data/Rakefile +0 -54
- data/benchmark/enabled_ips.rb +0 -10
- data/benchmark/enabled_multiple_actors_ips.rb +0 -20
- data/benchmark/enabled_profile.rb +0 -20
- data/benchmark/instrumentation_ips.rb +0 -21
- data/benchmark/typecast_ips.rb +0 -27
- data/docker-compose.yml +0 -37
- data/docs/DockerCompose.md +0 -18
- data/docs/README.md +0 -1
- data/docs/images/banner.jpg +0 -0
- data/docs/images/flipper_cloud.png +0 -0
- data/examples/api/basic.ru +0 -18
- data/examples/api/custom_memoized.ru +0 -36
- data/examples/api/memoized.ru +0 -42
- data/examples/basic.rb +0 -19
- data/examples/cloud/app.ru +0 -12
- data/examples/cloud/backoff_policy.rb +0 -13
- data/examples/cloud/basic.rb +0 -22
- data/examples/cloud/cloud_setup.rb +0 -20
- data/examples/cloud/forked.rb +0 -36
- data/examples/cloud/import.rb +0 -17
- data/examples/cloud/poll_interval/README.md +0 -111
- data/examples/cloud/poll_interval/client.rb +0 -108
- data/examples/cloud/poll_interval/server.rb +0 -98
- data/examples/cloud/threaded.rb +0 -33
- data/examples/configuring_default.rb +0 -19
- data/examples/dsl.rb +0 -57
- data/examples/enabled_for_actor.rb +0 -37
- data/examples/expressions.rb +0 -237
- data/examples/group.rb +0 -38
- data/examples/group_dynamic_lookup.rb +0 -75
- data/examples/group_with_members.rb +0 -83
- data/examples/importing.rb +0 -29
- data/examples/individual_actor.rb +0 -28
- data/examples/instrumentation.rb +0 -42
- data/examples/instrumentation_last_accessed_at.rb +0 -38
- data/examples/memoizing.rb +0 -35
- data/examples/mirroring.rb +0 -59
- data/examples/percentage_of_actors.rb +0 -31
- data/examples/percentage_of_actors_enabled_check.rb +0 -35
- data/examples/percentage_of_actors_group.rb +0 -35
- data/examples/percentage_of_time.rb +0 -27
- data/examples/strict.rb +0 -18
- data/flipper-cloud.gemspec +0 -19
- data/flipper.gemspec +0 -42
- data/package-lock.json +0 -41
- data/package.json +0 -10
- data/spec/fixtures/environment.rb +0 -1
- data/spec/fixtures/feature.json +0 -31
- data/spec/fixtures/flipper_pstore_1679087600.json +0 -46
- data/spec/flipper/actor_spec.rb +0 -56
- data/spec/flipper/adapter_builder_spec.rb +0 -72
- data/spec/flipper/adapter_spec.rb +0 -166
- data/spec/flipper/adapters/actor_limit_spec.rb +0 -75
- data/spec/flipper/adapters/dual_write_spec.rb +0 -82
- data/spec/flipper/adapters/failover_spec.rb +0 -141
- data/spec/flipper/adapters/failsafe_spec.rb +0 -58
- data/spec/flipper/adapters/http/client_spec.rb +0 -61
- data/spec/flipper/adapters/http_spec.rb +0 -596
- data/spec/flipper/adapters/instrumented_spec.rb +0 -167
- data/spec/flipper/adapters/memoizable_spec.rb +0 -377
- data/spec/flipper/adapters/memory_spec.rb +0 -36
- data/spec/flipper/adapters/operation_logger_spec.rb +0 -128
- data/spec/flipper/adapters/poll_spec.rb +0 -41
- data/spec/flipper/adapters/pstore_spec.rb +0 -16
- data/spec/flipper/adapters/read_only_spec.rb +0 -100
- data/spec/flipper/adapters/strict_spec.rb +0 -122
- data/spec/flipper/adapters/sync/feature_synchronizer_spec.rb +0 -247
- data/spec/flipper/adapters/sync/interval_synchronizer_spec.rb +0 -33
- data/spec/flipper/adapters/sync/synchronizer_spec.rb +0 -175
- data/spec/flipper/adapters/sync_spec.rb +0 -213
- data/spec/flipper/cli_spec.rb +0 -217
- data/spec/flipper/cloud/configuration_spec.rb +0 -251
- data/spec/flipper/cloud/dsl_spec.rb +0 -82
- data/spec/flipper/cloud/message_verifier_spec.rb +0 -104
- data/spec/flipper/cloud/middleware_spec.rb +0 -289
- data/spec/flipper/cloud/migrate_spec.rb +0 -160
- data/spec/flipper/cloud/telemetry/backoff_policy_spec.rb +0 -107
- data/spec/flipper/cloud/telemetry/metric_spec.rb +0 -87
- data/spec/flipper/cloud/telemetry/metric_storage_spec.rb +0 -58
- data/spec/flipper/cloud/telemetry/submitter_spec.rb +0 -145
- data/spec/flipper/cloud/telemetry_spec.rb +0 -208
- data/spec/flipper/cloud_spec.rb +0 -186
- data/spec/flipper/configuration_spec.rb +0 -50
- data/spec/flipper/dsl_spec.rb +0 -346
- data/spec/flipper/engine_spec.rb +0 -374
- data/spec/flipper/export_spec.rb +0 -13
- data/spec/flipper/exporter_spec.rb +0 -16
- data/spec/flipper/exporters/json/export_spec.rb +0 -60
- data/spec/flipper/exporters/json/v1_spec.rb +0 -33
- data/spec/flipper/expression/builder_spec.rb +0 -248
- data/spec/flipper/expression_spec.rb +0 -188
- data/spec/flipper/expressions/all_spec.rb +0 -15
- data/spec/flipper/expressions/any_spec.rb +0 -15
- data/spec/flipper/expressions/boolean_spec.rb +0 -15
- data/spec/flipper/expressions/equal_spec.rb +0 -24
- data/spec/flipper/expressions/greater_than_or_equal_to_spec.rb +0 -28
- data/spec/flipper/expressions/greater_than_spec.rb +0 -28
- data/spec/flipper/expressions/less_than_or_equal_to_spec.rb +0 -28
- data/spec/flipper/expressions/less_than_spec.rb +0 -32
- data/spec/flipper/expressions/not_equal_spec.rb +0 -15
- data/spec/flipper/expressions/now_spec.rb +0 -11
- data/spec/flipper/expressions/number_spec.rb +0 -21
- data/spec/flipper/expressions/percentage_of_actors_spec.rb +0 -20
- data/spec/flipper/expressions/percentage_spec.rb +0 -15
- data/spec/flipper/expressions/property_spec.rb +0 -13
- data/spec/flipper/expressions/random_spec.rb +0 -9
- data/spec/flipper/expressions/string_spec.rb +0 -11
- data/spec/flipper/expressions/time_spec.rb +0 -29
- data/spec/flipper/feature_check_context_spec.rb +0 -65
- data/spec/flipper/feature_spec.rb +0 -1227
- data/spec/flipper/gate_spec.rb +0 -39
- data/spec/flipper/gate_values_spec.rb +0 -103
- data/spec/flipper/gates/actor_spec.rb +0 -7
- data/spec/flipper/gates/boolean_spec.rb +0 -74
- data/spec/flipper/gates/expression_spec.rb +0 -190
- data/spec/flipper/gates/group_spec.rb +0 -62
- data/spec/flipper/gates/percentage_of_actors_spec.rb +0 -131
- data/spec/flipper/gates/percentage_of_time_spec.rb +0 -37
- data/spec/flipper/identifier_spec.rb +0 -12
- data/spec/flipper/instrumentation/log_subscriber_spec.rb +0 -122
- data/spec/flipper/instrumentation/statsd_subscriber_spec.rb +0 -95
- data/spec/flipper/instrumenters/memory_spec.rb +0 -43
- data/spec/flipper/instrumenters/noop_spec.rb +0 -27
- data/spec/flipper/middleware/memoizer_spec.rb +0 -518
- data/spec/flipper/middleware/setup_env_spec.rb +0 -94
- data/spec/flipper/model/active_record_spec.rb +0 -72
- data/spec/flipper/poller_spec.rb +0 -390
- data/spec/flipper/registry_spec.rb +0 -140
- data/spec/flipper/serializers/gzip_spec.rb +0 -13
- data/spec/flipper/serializers/json_spec.rb +0 -13
- data/spec/flipper/typecast_spec.rb +0 -232
- data/spec/flipper/types/actor_spec.rb +0 -132
- data/spec/flipper/types/boolean_spec.rb +0 -23
- data/spec/flipper/types/group_spec.rb +0 -112
- data/spec/flipper/types/percentage_of_actors_spec.rb +0 -5
- data/spec/flipper/types/percentage_of_time_spec.rb +0 -5
- data/spec/flipper/types/percentage_spec.rb +0 -46
- data/spec/flipper_integration_spec.rb +0 -783
- data/spec/flipper_spec.rb +0 -422
- data/spec/spec_helper.rb +0 -112
- data/spec/support/actor_names.yml +0 -1
- data/spec/support/descriptions.yml +0 -1
- data/spec/support/fail_on_output.rb +0 -8
- data/spec/support/fake_backoff_policy.rb +0 -15
- data/spec/support/fake_udp_socket.rb +0 -27
- data/spec/support/skippable.rb +0 -18
- data/spec/support/spec_helpers.rb +0 -111
- data/test/adapters/actor_limit_test.rb +0 -20
- data/test/adapters/memory_test.rb +0 -9
- data/test/adapters/pstore_test.rb +0 -17
- data/test/test_helper.rb +0 -7
- data/test_rails/generators/flipper/setup_generator_test.rb +0 -69
- data/test_rails/generators/flipper/update_generator_test.rb +0 -96
- data/test_rails/helper.rb +0 -31
- data/test_rails/system/test_help_test.rb +0 -52
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
require "flipper/adapters/memory"
|
|
2
|
-
require "flipper/adapters/actor_limit"
|
|
3
|
-
require "flipper/instrumenters/memory"
|
|
4
|
-
require "flipper/adapters/sync/synchronizer"
|
|
5
|
-
|
|
6
|
-
RSpec.describe Flipper::Adapters::Sync::Synchronizer do
|
|
7
|
-
let(:local) { Flipper::Adapters::Memory.new }
|
|
8
|
-
let(:remote) { Flipper::Adapters::Memory.new }
|
|
9
|
-
let(:local_flipper) { Flipper.new(local) }
|
|
10
|
-
let(:remote_flipper) { Flipper.new(remote) }
|
|
11
|
-
let(:instrumenter) { Flipper::Instrumenters::Memory.new }
|
|
12
|
-
|
|
13
|
-
subject { described_class.new(local, remote, instrumenter: instrumenter) }
|
|
14
|
-
|
|
15
|
-
it "instruments call" do
|
|
16
|
-
subject.call
|
|
17
|
-
expect(instrumenter.events_by_name("synchronizer_exception.flipper").size).to be(0)
|
|
18
|
-
|
|
19
|
-
events = instrumenter.events_by_name("synchronizer_call.flipper")
|
|
20
|
-
expect(events.size).to be(1)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "raises errors by default" do
|
|
24
|
-
exception = StandardError.new
|
|
25
|
-
expect(remote).to receive(:get_all).and_raise(exception)
|
|
26
|
-
|
|
27
|
-
expect { subject.call }.to raise_error(exception)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
context "when raise disabled" do
|
|
31
|
-
subject do
|
|
32
|
-
options = {
|
|
33
|
-
instrumenter: instrumenter,
|
|
34
|
-
raise: false,
|
|
35
|
-
}
|
|
36
|
-
described_class.new(local, remote, options)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "does not raise, but instruments exceptions for visibility" do
|
|
40
|
-
exception = StandardError.new
|
|
41
|
-
expect(remote).to receive(:get_all).and_raise(exception)
|
|
42
|
-
|
|
43
|
-
expect { subject.call }.not_to raise_error
|
|
44
|
-
|
|
45
|
-
events = instrumenter.events_by_name("synchronizer_exception.flipper")
|
|
46
|
-
expect(events.size).to be(1)
|
|
47
|
-
|
|
48
|
-
event = events[0]
|
|
49
|
-
expect(event.payload[:exception]).to eq(exception)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
describe '#call' do
|
|
54
|
-
it 'returns nothing' do
|
|
55
|
-
expect(subject.call).to be(nil)
|
|
56
|
-
expect(instrumenter.events_by_name("synchronizer_exception.flipper").size).to be(0)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it 'syncs each remote feature to local' do
|
|
60
|
-
remote_flipper.enable(:search)
|
|
61
|
-
remote_flipper.enable_percentage_of_time(:logging, 10)
|
|
62
|
-
|
|
63
|
-
subject.call
|
|
64
|
-
expect(instrumenter.events_by_name("synchronizer_exception.flipper").size).to be(0)
|
|
65
|
-
|
|
66
|
-
expect(local_flipper[:search].boolean_value).to eq(true)
|
|
67
|
-
expect(local_flipper[:logging].percentage_of_time_value).to eq(10)
|
|
68
|
-
expect(local_flipper.features.map(&:key).sort).to eq(%w(logging search))
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it 'adds features in remote that are not in local' do
|
|
72
|
-
remote_flipper.add(:search)
|
|
73
|
-
|
|
74
|
-
subject.call
|
|
75
|
-
expect(instrumenter.events_by_name("synchronizer_exception.flipper").size).to be(0)
|
|
76
|
-
|
|
77
|
-
expect(local_flipper.features.map(&:key)).to eq(["search"])
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it 'removes features in local that are not in remote' do
|
|
81
|
-
local_flipper.add(:stats)
|
|
82
|
-
|
|
83
|
-
subject.call
|
|
84
|
-
expect(instrumenter.events_by_name("synchronizer_exception.flipper").size).to be(0)
|
|
85
|
-
|
|
86
|
-
expect(local_flipper.features.map(&:key)).to eq([])
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it 'emits feature_operation.flipper events when syncing' do
|
|
90
|
-
remote_flipper.enable(:search)
|
|
91
|
-
|
|
92
|
-
subject.call
|
|
93
|
-
|
|
94
|
-
events = instrumenter.events_by_name("feature_operation.flipper")
|
|
95
|
-
enable_events = events.select { |e| e.payload[:operation] == :enable }
|
|
96
|
-
expect(enable_events).not_to be_empty
|
|
97
|
-
|
|
98
|
-
feature_names = enable_events.map { |e| e.payload[:feature_name].to_s }
|
|
99
|
-
expect(feature_names).to include("search")
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
it 'emits feature_operation.flipper events when adding features' do
|
|
103
|
-
remote_flipper.add(:new_feature)
|
|
104
|
-
|
|
105
|
-
subject.call
|
|
106
|
-
|
|
107
|
-
events = instrumenter.events_by_name("feature_operation.flipper")
|
|
108
|
-
add_events = events.select { |e| e.payload[:operation] == :add }
|
|
109
|
-
expect(add_events).not_to be_empty
|
|
110
|
-
|
|
111
|
-
feature_names = add_events.map { |e| e.payload[:feature_name].to_s }
|
|
112
|
-
expect(feature_names).to include("new_feature")
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it 'emits feature_operation.flipper events when removing features' do
|
|
116
|
-
local_flipper.add(:old_feature)
|
|
117
|
-
|
|
118
|
-
subject.call
|
|
119
|
-
|
|
120
|
-
events = instrumenter.events_by_name("feature_operation.flipper")
|
|
121
|
-
remove_events = events.select { |e| e.payload[:operation] == :remove }
|
|
122
|
-
expect(remove_events).not_to be_empty
|
|
123
|
-
|
|
124
|
-
feature_names = remove_events.map { |e| e.payload[:feature_name].to_s }
|
|
125
|
-
expect(feature_names).to include("old_feature")
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
context 'with ActorLimit adapter wrapping local' do
|
|
130
|
-
let(:limit) { 10 }
|
|
131
|
-
let(:limited_local) { Flipper::Adapters::ActorLimit.new(local, limit) }
|
|
132
|
-
let(:limited_local_flipper) { Flipper.new(limited_local) }
|
|
133
|
-
|
|
134
|
-
subject { described_class.new(limited_local, remote, instrumenter: instrumenter) }
|
|
135
|
-
|
|
136
|
-
it 'syncs actors even when remote has more actors than local limit' do
|
|
137
|
-
# Remote has more actors than local limit allows
|
|
138
|
-
20.times { |i| remote_flipper[:search].enable_actor Flipper::Actor.new("User;#{i}") }
|
|
139
|
-
|
|
140
|
-
# This should NOT raise - sync should bypass actor limits
|
|
141
|
-
expect { subject.call }.not_to raise_error
|
|
142
|
-
|
|
143
|
-
# All actors should be synced
|
|
144
|
-
expect(limited_local_flipper[:search].actors_value.size).to eq(20)
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
it 'syncs new actors added to remote after initial sync' do
|
|
148
|
-
# Initial state: remote has 20 actors, local limit is 10
|
|
149
|
-
20.times { |i| remote_flipper[:search].enable_actor Flipper::Actor.new("User;#{i}") }
|
|
150
|
-
|
|
151
|
-
# First sync - should work despite exceeding limit
|
|
152
|
-
subject.call
|
|
153
|
-
expect(limited_local_flipper[:search].actors_value.size).to eq(20)
|
|
154
|
-
|
|
155
|
-
# Add a 21st actor to remote (simulating Cloud adding a new actor)
|
|
156
|
-
remote_flipper[:search].enable_actor Flipper::Actor.new("User;20")
|
|
157
|
-
|
|
158
|
-
# Sync again - should pick up the new actor
|
|
159
|
-
expect { subject.call }.not_to raise_error
|
|
160
|
-
expect(limited_local_flipper[:search].actors_value.size).to eq(21)
|
|
161
|
-
expect(limited_local_flipper[:search].actors_value).to include("User;20")
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
it 'still enforces limit for direct enable operations' do
|
|
165
|
-
# First sync 20 actors from remote
|
|
166
|
-
20.times { |i| remote_flipper[:search].enable_actor Flipper::Actor.new("User;#{i}") }
|
|
167
|
-
subject.call
|
|
168
|
-
|
|
169
|
-
# Direct enable should still fail because we're over limit
|
|
170
|
-
expect {
|
|
171
|
-
limited_local_flipper[:search].enable_actor Flipper::Actor.new("User;new")
|
|
172
|
-
}.to raise_error(Flipper::Adapters::ActorLimit::LimitExceeded)
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
end
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
require 'flipper/adapters/sync'
|
|
2
|
-
require 'flipper/adapters/operation_logger'
|
|
3
|
-
require 'active_support/notifications'
|
|
4
|
-
|
|
5
|
-
RSpec.describe Flipper::Adapters::Sync do
|
|
6
|
-
let(:local_adapter) do
|
|
7
|
-
Flipper::Adapters::OperationLogger.new Flipper::Adapters::Memory.new
|
|
8
|
-
end
|
|
9
|
-
let(:remote_adapter) do
|
|
10
|
-
Flipper::Adapters::OperationLogger.new Flipper::Adapters::Memory.new
|
|
11
|
-
end
|
|
12
|
-
let(:local) { Flipper.new(local_adapter) }
|
|
13
|
-
let(:remote) { Flipper.new(remote_adapter) }
|
|
14
|
-
let(:sync) { Flipper.new(subject) }
|
|
15
|
-
|
|
16
|
-
subject do
|
|
17
|
-
described_class.new(local_adapter, remote_adapter, interval: 1)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it_should_behave_like 'a flipper adapter'
|
|
21
|
-
|
|
22
|
-
context 'when local has never been synced' do
|
|
23
|
-
it 'syncs boolean' do
|
|
24
|
-
remote.enable(:search)
|
|
25
|
-
expect(sync[:search].boolean_value).to be(true)
|
|
26
|
-
expect(subject.features.sort).to eq(%w(search))
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it 'syncs actor' do
|
|
30
|
-
actor = Flipper::Actor.new("User;1000")
|
|
31
|
-
remote.enable_actor(:search, actor)
|
|
32
|
-
expect(sync[:search].actors_value).to eq(Set[actor.flipper_id])
|
|
33
|
-
expect(subject.features.sort).to eq(%w(search))
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it 'syncs group' do
|
|
37
|
-
remote.enable_group(:search, :staff)
|
|
38
|
-
expect(sync[:search].groups_value).to eq(Set["staff"])
|
|
39
|
-
expect(subject.features.sort).to eq(%w(search))
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it 'syncs percentage of actors' do
|
|
43
|
-
remote.enable_percentage_of_actors(:search, 25)
|
|
44
|
-
expect(sync[:search].percentage_of_actors_value).to eq(25)
|
|
45
|
-
expect(subject.features.sort).to eq(%w(search))
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it 'syncs percentage of time' do
|
|
49
|
-
remote.enable_percentage_of_time(:search, 15)
|
|
50
|
-
expect(sync[:search].percentage_of_time_value).to eq(15)
|
|
51
|
-
expect(subject.features.sort).to eq(%w(search))
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it 'enables boolean locally when remote feature boolean enabled' do
|
|
56
|
-
remote.disable(:search)
|
|
57
|
-
local.disable(:search)
|
|
58
|
-
remote.enable(:search)
|
|
59
|
-
subject # initialize forces sync
|
|
60
|
-
expect(local[:search].boolean_value).to be(true)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it 'disables boolean locally when remote feature disabled' do
|
|
64
|
-
remote.enable(:search)
|
|
65
|
-
local.enable(:search)
|
|
66
|
-
remote.disable(:search)
|
|
67
|
-
subject # initialize forces sync
|
|
68
|
-
expect(local[:search].boolean_value).to be(false)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it 'adds local actor when remote actor is added' do
|
|
72
|
-
actor = Flipper::Actor.new("User;235")
|
|
73
|
-
remote.enable_actor(:search, actor)
|
|
74
|
-
subject # initialize forces sync
|
|
75
|
-
expect(local[:search].actors_value).to eq(Set[actor.flipper_id])
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it 'removes local actor when remote actor is removed' do
|
|
79
|
-
actor = Flipper::Actor.new("User;235")
|
|
80
|
-
remote.enable_actor(:search, actor)
|
|
81
|
-
local.enable_actor(:search, actor)
|
|
82
|
-
remote.disable(:search, actor)
|
|
83
|
-
subject # initialize forces sync
|
|
84
|
-
expect(local[:search].actors_value).to eq(Set.new)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it 'adds local group when remote group is added' do
|
|
88
|
-
group = Flipper::Types::Group.new(:staff)
|
|
89
|
-
remote.enable_group(:search, group)
|
|
90
|
-
subject # initialize forces sync
|
|
91
|
-
expect(local[:search].groups_value).to eq(Set["staff"])
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it 'removes local group when remote group is removed' do
|
|
95
|
-
group = Flipper::Types::Group.new(:staff)
|
|
96
|
-
remote.enable_group(:search, group)
|
|
97
|
-
local.enable_group(:search, group)
|
|
98
|
-
remote.disable(:search, group)
|
|
99
|
-
subject # initialize forces sync
|
|
100
|
-
expect(local[:search].groups_value).to eq(Set.new)
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it 'updates percentage of actors when remote is updated' do
|
|
104
|
-
remote.enable_percentage_of_actors(:search, 10)
|
|
105
|
-
local.enable_percentage_of_actors(:search, 10)
|
|
106
|
-
remote.enable_percentage_of_actors(:search, 15)
|
|
107
|
-
subject # initialize forces sync
|
|
108
|
-
expect(local[:search].percentage_of_actors_value).to eq(15)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
it 'updates percentage of time when remote is updated' do
|
|
112
|
-
remote.enable_percentage_of_time(:search, 10)
|
|
113
|
-
local.enable_percentage_of_time(:search, 10)
|
|
114
|
-
remote.enable_percentage_of_time(:search, 15)
|
|
115
|
-
subject # initialize forces sync
|
|
116
|
-
expect(local[:search].percentage_of_time_value).to eq(15)
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
context 'when local and remote match' do
|
|
120
|
-
it 'does not update boolean enabled' do
|
|
121
|
-
local.enable(:search)
|
|
122
|
-
remote.enable(:search)
|
|
123
|
-
local_adapter.reset
|
|
124
|
-
subject # initialize forces sync
|
|
125
|
-
expect(local_adapter.count(:enable)).to be(0)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
it 'does not update boolean disabled' do
|
|
129
|
-
local.disable(:search)
|
|
130
|
-
remote.disable(:search)
|
|
131
|
-
local_adapter.reset
|
|
132
|
-
subject # initialize forces sync
|
|
133
|
-
expect(local_adapter.count(:disable)).to be(0)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
it 'does not update actors' do
|
|
137
|
-
actor = Flipper::Actor.new("User;235")
|
|
138
|
-
local.enable_actor(:search, actor)
|
|
139
|
-
remote.enable_actor(:search, actor)
|
|
140
|
-
local_adapter.reset
|
|
141
|
-
subject # initialize forces sync
|
|
142
|
-
expect(local_adapter.count(:enable)).to be(0)
|
|
143
|
-
expect(local_adapter.count(:disable)).to be(0)
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
it 'does not update groups' do
|
|
147
|
-
group = Flipper::Types::Group.new(:staff)
|
|
148
|
-
local.enable_group(:search, group)
|
|
149
|
-
remote.enable_group(:search, group)
|
|
150
|
-
local_adapter.reset
|
|
151
|
-
subject # initialize forces sync
|
|
152
|
-
expect(local_adapter.count(:enable)).to be(0)
|
|
153
|
-
expect(local_adapter.count(:disable)).to be(0)
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
it 'does not update percentage of actors' do
|
|
157
|
-
local.enable_percentage_of_actors(:search, 10)
|
|
158
|
-
remote.enable_percentage_of_actors(:search, 10)
|
|
159
|
-
local_adapter.reset
|
|
160
|
-
subject # initialize forces sync
|
|
161
|
-
expect(local_adapter.count(:enable)).to be(0)
|
|
162
|
-
expect(local_adapter.count(:disable)).to be(0)
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
it 'does not update percentage of time' do
|
|
166
|
-
local.enable_percentage_of_time(:search, 10)
|
|
167
|
-
remote.enable_percentage_of_time(:search, 10)
|
|
168
|
-
local_adapter.reset
|
|
169
|
-
subject # initialize forces sync
|
|
170
|
-
expect(local_adapter.count(:enable)).to be(0)
|
|
171
|
-
expect(local_adapter.count(:disable)).to be(0)
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
it 'synchronizes for #features' do
|
|
176
|
-
expect(subject).to receive(:synchronize)
|
|
177
|
-
subject.features
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
it 'synchronizes for #get' do
|
|
181
|
-
expect(subject).to receive(:synchronize)
|
|
182
|
-
subject.get sync[:search]
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
it 'synchronizes for #get_multi' do
|
|
186
|
-
expect(subject).to receive(:synchronize)
|
|
187
|
-
subject.get_multi [sync[:search]]
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
it 'synchronizes for #get_all' do
|
|
191
|
-
expect(subject).to receive(:synchronize)
|
|
192
|
-
subject.get_all
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
it 'does not raise sync exceptions' do
|
|
196
|
-
exception = StandardError.new
|
|
197
|
-
expect(remote_adapter).to receive(:get_all).and_raise(exception)
|
|
198
|
-
expect { subject.get_all }.not_to raise_error
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
describe '#adapter_stack' do
|
|
202
|
-
it 'returns the tree representation' do
|
|
203
|
-
expect(subject.adapter_stack).to eq("sync(local: operation_logger -> memory, remote: operation_logger -> memory)")
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
it 'shows nested adapters in the tree' do
|
|
207
|
-
memory = Flipper::Adapters::Memory.new
|
|
208
|
-
strict = Flipper::Adapters::Strict.new(Flipper::Adapters::Memory.new)
|
|
209
|
-
adapter = described_class.new(memory, strict, interval: 1)
|
|
210
|
-
expect(adapter.adapter_stack).to eq("sync(local: memory, remote: strict -> memory)")
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
end
|
data/spec/flipper/cli_spec.rb
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
require "flipper/cli"
|
|
2
|
-
|
|
3
|
-
RSpec.describe Flipper::CLI do
|
|
4
|
-
let(:stdout) { StringIO.new }
|
|
5
|
-
let(:stderr) { StringIO.new }
|
|
6
|
-
let(:cli) { Flipper::CLI.new(stdout: stdout, stderr: stderr) }
|
|
7
|
-
|
|
8
|
-
Result = Struct.new(:status, :stdout, :stderr, keyword_init: true)
|
|
9
|
-
|
|
10
|
-
before do
|
|
11
|
-
# Prentend stdout/stderr a TTY to test colorization
|
|
12
|
-
allow(stdout).to receive(:tty?).and_return(true)
|
|
13
|
-
allow(stderr).to receive(:tty?).and_return(true)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# Infer the command from the description
|
|
17
|
-
let(:argv) do
|
|
18
|
-
descriptions = self.class.parent_groups.map {|g| g.metadata[:description_args] }.reverse.flatten.drop(1)
|
|
19
|
-
descriptions.map { |arg| Shellwords.split(arg) }.flatten
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
subject do
|
|
23
|
-
status = 0
|
|
24
|
-
|
|
25
|
-
begin
|
|
26
|
-
cli.run(argv)
|
|
27
|
-
rescue SystemExit => e
|
|
28
|
-
status = e.status
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
Result.new(status: status, stdout: stdout.string, stderr: stderr.string)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
before do
|
|
35
|
-
ENV["FLIPPER_REQUIRE"] = "./spec/fixtures/environment"
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
describe "enable" do
|
|
39
|
-
describe "feature" do
|
|
40
|
-
it do
|
|
41
|
-
expect(subject).to have_attributes(status: 0, stdout: /feature.*\e\[32m.*enabled/)
|
|
42
|
-
expect(Flipper).to be_enabled(:feature)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
describe "-a User;1 feature" do
|
|
47
|
-
it do
|
|
48
|
-
expect(subject).to have_attributes(status: 0, stdout: /feature.*\e\[33m.*enabled.*User;1/m)
|
|
49
|
-
expect(Flipper).to be_enabled(:feature, Flipper::Actor.new("User;1"))
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
describe "feature -g admins" do
|
|
54
|
-
it do
|
|
55
|
-
expect(subject).to have_attributes(status: 0, stdout: /feature.*enabled.*admins/m)
|
|
56
|
-
expect(Flipper.feature('feature').enabled_groups.map(&:name)).to eq([:admins])
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
describe "feature -p 30" do
|
|
61
|
-
it do
|
|
62
|
-
expect(subject).to have_attributes(status: 0, stdout: /feature.*enabled.*30% of actors/m)
|
|
63
|
-
expect(Flipper.feature('feature').percentage_of_actors_value).to eq(30)
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
describe "feature -t 50" do
|
|
68
|
-
it do
|
|
69
|
-
expect(subject).to have_attributes(status: 0, stdout: /feature.*enabled.*50% of time/m)
|
|
70
|
-
expect(Flipper.feature('feature').percentage_of_time_value).to eq(50)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
describe %|feature -x '{"Equal":[{"Property":"flipper_id"},"User;1"]}'| do
|
|
75
|
-
it do
|
|
76
|
-
expect(subject).to have_attributes(status: 0, stdout: /feature.*enabled.*User;1/m)
|
|
77
|
-
expect(Flipper.feature('feature').expression.value).to eq({ "Equal" => [ { "Property" => ["flipper_id"] }, "User;1" ] })
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
describe %|feature -x invalid_json| do
|
|
82
|
-
it do
|
|
83
|
-
expect(subject).to have_attributes(status: 1, stderr: /JSON parse error/m)
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
describe %|feature -x '{}'| do
|
|
88
|
-
it do
|
|
89
|
-
expect(subject).to have_attributes(status: 1, stderr: /Invalid expression/m)
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
describe "disable" do
|
|
95
|
-
describe "feature" do
|
|
96
|
-
before { Flipper.enable :feature }
|
|
97
|
-
|
|
98
|
-
it do
|
|
99
|
-
expect(subject).to have_attributes(status: 0, stdout: /feature.*disabled/)
|
|
100
|
-
expect(Flipper).not_to be_enabled(:feature)
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
describe "feature -g admins" do
|
|
105
|
-
before { Flipper.enable_group(:feature, :admins) }
|
|
106
|
-
|
|
107
|
-
it do
|
|
108
|
-
expect(subject).to have_attributes(status: 0, stdout: /feature.*disabled/)
|
|
109
|
-
expect(Flipper.feature('feature').enabled_groups).to be_empty
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
describe "list" do
|
|
115
|
-
before do
|
|
116
|
-
Flipper.enable :foo
|
|
117
|
-
Flipper.disable :bar
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
it "lists features" do
|
|
121
|
-
expect(subject).to have_attributes(status: 0, stdout: /foo.*enabled/)
|
|
122
|
-
expect(subject).to have_attributes(status: 0, stdout: /bar.*disabled/)
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
["-h", "--help", "help"].each do |arg|
|
|
127
|
-
describe arg do
|
|
128
|
-
it { should have_attributes(status: 0, stdout: /Usage: flipper/) }
|
|
129
|
-
|
|
130
|
-
it "should list subcommands" do
|
|
131
|
-
%w(enable disable list).each do |subcommand|
|
|
132
|
-
expect(subject.stdout).to match(/#{subcommand}/)
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
describe "help enable" do
|
|
139
|
-
it { should have_attributes(status: 0, stdout: /Usage: flipper enable \[options\] <feature>/) }
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
describe "nope" do
|
|
143
|
-
it { should have_attributes(status: 1, stderr: /Unknown command: nope/) }
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
describe "--nope" do
|
|
147
|
-
it { should have_attributes(status: 1, stderr: /invalid option: --nope/) }
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
describe "export" do
|
|
151
|
-
before do
|
|
152
|
-
Flipper.enable :search
|
|
153
|
-
Flipper.disable :analytics
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
it "outputs valid JSON export" do
|
|
157
|
-
expect(subject).to have_attributes(status: 0)
|
|
158
|
-
data = JSON.parse(subject.stdout)
|
|
159
|
-
expect(data["version"]).to eq(1)
|
|
160
|
-
expect(data["features"]).to have_key("search")
|
|
161
|
-
expect(data["features"]).to have_key("analytics")
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
describe "cloud" do
|
|
166
|
-
it "shows help when no subcommand given" do
|
|
167
|
-
expect(subject).to have_attributes(status: 0, stdout: /migrate/)
|
|
168
|
-
expect(subject.stdout).to match(/push/)
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
describe "cloud migrate" do
|
|
173
|
-
before do
|
|
174
|
-
Flipper.enable :search
|
|
175
|
-
require 'flipper/cloud/migrate'
|
|
176
|
-
allow(Flipper::Cloud).to receive(:migrate).and_return(
|
|
177
|
-
Flipper::Cloud::MigrateResult.new(code: 200, url: "https://www.flippercloud.io/cloud/setup/abc123")
|
|
178
|
-
)
|
|
179
|
-
allow(cli).to receive(:system)
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
it "prints the cloud URL" do
|
|
183
|
-
expect(subject).to have_attributes(status: 0, stdout: /flippercloud\.io/)
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
describe "cloud push test-token" do
|
|
188
|
-
before do
|
|
189
|
-
Flipper.enable :search
|
|
190
|
-
require 'flipper/cloud/migrate'
|
|
191
|
-
allow(Flipper::Cloud).to receive(:push).and_return(
|
|
192
|
-
Flipper::Cloud::MigrateResult.new(code: 204, url: nil)
|
|
193
|
-
)
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
it "prints success message" do
|
|
197
|
-
expect(subject).to have_attributes(status: 0, stdout: /Successfully pushed/)
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
describe "show foo" do
|
|
202
|
-
context "boolean" do
|
|
203
|
-
before { Flipper.enable :foo }
|
|
204
|
-
it { should have_attributes(status: 0, stdout: /foo.*enabled/) }
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
context "actors" do
|
|
208
|
-
before { Flipper.enable_actor :foo, Flipper::Actor.new("User;1") }
|
|
209
|
-
it { should have_attributes(status: 0, stdout: /User;1/) }
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
context "groups" do
|
|
213
|
-
before { Flipper.enable_group :foo, :admins }
|
|
214
|
-
it { should have_attributes(status: 0, stdout: /enabled.*admins/m) }
|
|
215
|
-
end
|
|
216
|
-
end
|
|
217
|
-
end
|