diff options
author | Sanad Liaquat <sliaquat@gitlab.com> | 2019-09-11 19:31:35 +0500 |
---|---|---|
committer | Sanad Liaquat <sliaquat@gitlab.com> | 2019-09-11 22:09:24 +0500 |
commit | 9e64d00b655f72561d6408c2f9123897e342a7d2 (patch) | |
tree | 5989643eed577b33c0dbf1f6f81e9734ec2d2a8d | |
parent | 0813d1543114883e8ec84cecb5495a3cd9c1f332 (diff) | |
download | gitlab-ce-qa-nightly-129-fix-group-saml-sso-spec-ce.tar.gz |
CE port of "Ensure flags are set properly"qa-nightly-129-fix-group-saml-sso-spec-ce
Also adds unit tests for Runtime::Feature.enabled?
-rw-r--r-- | qa/qa/runtime/feature.rb | 11 | ||||
-rw-r--r-- | qa/qa/support/retrier.rb | 7 | ||||
-rw-r--r-- | qa/spec/runtime/feature_spec.rb | 21 |
3 files changed, 35 insertions, 4 deletions
diff --git a/qa/qa/runtime/feature.rb b/qa/qa/runtime/feature.rb index 1b4ae7adbbe..b74f343ba7b 100644 --- a/qa/qa/runtime/feature.rb +++ b/qa/qa/runtime/feature.rb @@ -18,6 +18,11 @@ module QA set_feature(key, false) end + def enabled?(key) + feature = JSON.parse(get_features).find { |flag| flag["name"] == key } + feature && feature["state"] == "on" + end + private def api_client @@ -31,6 +36,12 @@ module QA raise SetFeatureError, "Setting feature flag #{key} to #{value} failed with `#{response}`." end end + + def get_features + request = Runtime::API::Request.new(api_client, "/features") + response = get(request.url) + response.body + end end end end diff --git a/qa/qa/support/retrier.rb b/qa/qa/support/retrier.rb index 720f1d17037..3b02cb4855b 100644 --- a/qa/qa/support/retrier.rb +++ b/qa/qa/support/retrier.rb @@ -24,7 +24,7 @@ module QA end end - def retry_until(max_attempts: 3, reload_page: nil, sleep_interval: 0) + def retry_until(max_attempts: 3, reload_page: nil, sleep_interval: 0, exit_on_failure: false) QA::Runtime::Logger.debug("with retry_until: max_attempts #{max_attempts}; sleep_interval #{sleep_interval}; reload_page:#{reload_page}") attempts = 0 @@ -40,6 +40,11 @@ module QA attempts += 1 end + if exit_on_failure + QA::Runtime::Logger.debug("Raising exception after #{max_attempts} attempts") + raise + end + false end end diff --git a/qa/spec/runtime/feature_spec.rb b/qa/spec/runtime/feature_spec.rb index 192299b7857..94638d99b01 100644 --- a/qa/spec/runtime/feature_spec.rb +++ b/qa/spec/runtime/feature_spec.rb @@ -3,7 +3,8 @@ describe QA::Runtime::Feature do let(:api_client) { double('QA::Runtime::API::Client') } let(:request) { Struct.new(:url).new('http://api') } - let(:response) { Struct.new(:code).new(201) } + let(:response_post) { Struct.new(:code).new(201) } + let(:response_get) { Struct.new(:code, :body).new(200, '[{ "name": "a-flag", "state": "on" }]') } before do allow(described_class).to receive(:api_client).and_return(api_client) @@ -18,7 +19,7 @@ describe QA::Runtime::Feature do expect(described_class) .to receive(:post) .with(request.url, { value: true }) - .and_return(response) + .and_return(response_post) subject.enable('a-flag') end @@ -33,9 +34,23 @@ describe QA::Runtime::Feature do expect(described_class) .to receive(:post) .with(request.url, { value: false }) - .and_return(response) + .and_return(response_post) subject.disable('a-flag') end end + + describe '.enabled?' do + it 'returns a feature flag state' do + expect(QA::Runtime::API::Request) + .to receive(:new) + .with(api_client, "/features") + .and_return(request) + expect(described_class) + .to receive(:get) + .and_return(response_get) + + expect(subject.enabled?('a-flag')).to be_truthy + end + end end |