diff options
author | Mark Lapierre <mlapierre@gitlab.com> | 2019-03-27 19:03:03 +0000 |
---|---|---|
committer | Dan Davison <ddavison@gitlab.com> | 2019-03-27 19:03:03 +0000 |
commit | 67c38a6573f35333cf9b1a399431b86e8b376443 (patch) | |
tree | 3b621737b0b231e4d247fd6f11ee1610eb0029fc /qa/qa/runtime | |
parent | 743c43e40109d0fc28a167c4b4194d69bd0f030c (diff) | |
download | gitlab-ce-67c38a6573f35333cf9b1a399431b86e8b376443.tar.gz |
Set feature flag via command line
First attempt at allowing a feature flag to be set via the command line
when running tests. This will enable the flag, run the tests, and then
disable the flag.
Using OptionParser meant changing how scenarios get the instance
address, so this also allows the address to be set as a command line
option. It's backwards compatible (you can still provide the address
as the command line option after the scenario)
Diffstat (limited to 'qa/qa/runtime')
-rw-r--r-- | qa/qa/runtime/address.rb | 7 | ||||
-rw-r--r-- | qa/qa/runtime/feature.rb | 36 |
2 files changed, 43 insertions, 0 deletions
diff --git a/qa/qa/runtime/address.rb b/qa/qa/runtime/address.rb index ffad3974b02..af0537dc17c 100644 --- a/qa/qa/runtime/address.rb +++ b/qa/qa/runtime/address.rb @@ -15,6 +15,13 @@ module QA @instance.to_s end end + + def self.valid?(value) + uri = URI.parse(value) + uri.is_a?(URI::HTTP) && !uri.host.nil? + rescue URI::InvalidURIError + false + end end end end diff --git a/qa/qa/runtime/feature.rb b/qa/qa/runtime/feature.rb new file mode 100644 index 00000000000..1b4ae7adbbe --- /dev/null +++ b/qa/qa/runtime/feature.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module QA + module Runtime + module Feature + extend self + extend Support::Api + + SetFeatureError = Class.new(RuntimeError) + + def enable(key) + QA::Runtime::Logger.info("Enabling feature: #{key}") + set_feature(key, true) + end + + def disable(key) + QA::Runtime::Logger.info("Disabling feature: #{key}") + set_feature(key, false) + end + + private + + def api_client + @api_client ||= Runtime::API::Client.new(:gitlab) + end + + def set_feature(key, value) + request = Runtime::API::Request.new(api_client, "/features/#{key}") + response = post(request.url, { value: value }) + unless response.code == QA::Support::Api::HTTP_STATUS_CREATED + raise SetFeatureError, "Setting feature flag #{key} to #{value} failed with `#{response}`." + end + end + end + end +end |