Commit 3a76b0fd authored by Sanad Liaquat's avatar Sanad Liaquat

Ensure flags are set properly

Also adds unit tests for Runtime::Feature.enabled?
parent a4dbeeb0
...@@ -18,6 +18,11 @@ module QA ...@@ -18,6 +18,11 @@ module QA
set_feature(key, false) set_feature(key, false)
end end
def enabled?(key)
feature = JSON.parse(get_features).find { |flag| flag["name"] == key }
feature && feature["state"] == "on"
end
private private
def api_client def api_client
...@@ -31,6 +36,12 @@ module QA ...@@ -31,6 +36,12 @@ module QA
raise SetFeatureError, "Setting feature flag #{key} to #{value} failed with `#{response}`." raise SetFeatureError, "Setting feature flag #{key} to #{value} failed with `#{response}`."
end end
end end
def get_features
request = Runtime::API::Request.new(api_client, "/features")
response = get(request.url)
response.body
end
end end
end end
end end
...@@ -60,11 +60,14 @@ module QA ...@@ -60,11 +60,14 @@ module QA
expect(page).to have_content("Test SAML SSO") expect(page).to have_content("Test SAML SSO")
end end
# Failure issue: https://gitlab.com/gitlab-org/quality/nightly/issues/129 context 'Enforced SSO' do
context 'Enforced SSO', :quarantine do
before do before do
Runtime::Feature.enable("enforced_sso") %w[enforced_sso enforced_sso_requires_session].each do |flag|
Runtime::Feature.enable("enforced_sso_requires_session") QA::Support::Retrier.retry_until(exit_on_failure: true) do
Runtime::Feature.enable(flag)
Runtime::Feature.enabled?(flag)
end
end
end end
it 'user clones and pushes to project within a group using Git HTTP' do it 'user clones and pushes to project within a group using Git HTTP' do
......
...@@ -24,7 +24,7 @@ module QA ...@@ -24,7 +24,7 @@ module QA
end end
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}") QA::Runtime::Logger.debug("with retry_until: max_attempts #{max_attempts}; sleep_interval #{sleep_interval}; reload_page:#{reload_page}")
attempts = 0 attempts = 0
...@@ -40,6 +40,11 @@ module QA ...@@ -40,6 +40,11 @@ module QA
attempts += 1 attempts += 1
end end
if exit_on_failure
QA::Runtime::Logger.debug("Raising exception after #{max_attempts} attempts")
raise
end
false false
end end
end end
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
describe QA::Runtime::Feature do describe QA::Runtime::Feature do
let(:api_client) { double('QA::Runtime::API::Client') } let(:api_client) { double('QA::Runtime::API::Client') }
let(:request) { Struct.new(:url).new('http://api') } 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 before do
allow(described_class).to receive(:api_client).and_return(api_client) allow(described_class).to receive(:api_client).and_return(api_client)
...@@ -18,7 +19,7 @@ describe QA::Runtime::Feature do ...@@ -18,7 +19,7 @@ describe QA::Runtime::Feature do
expect(described_class) expect(described_class)
.to receive(:post) .to receive(:post)
.with(request.url, { value: true }) .with(request.url, { value: true })
.and_return(response) .and_return(response_post)
subject.enable('a-flag') subject.enable('a-flag')
end end
...@@ -33,9 +34,23 @@ describe QA::Runtime::Feature do ...@@ -33,9 +34,23 @@ describe QA::Runtime::Feature do
expect(described_class) expect(described_class)
.to receive(:post) .to receive(:post)
.with(request.url, { value: false }) .with(request.url, { value: false })
.and_return(response) .and_return(response_post)
subject.disable('a-flag') subject.disable('a-flag')
end end
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 end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment