diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2017-11-09 11:53:57 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-11-09 11:53:57 +0000 |
commit | 77103646678deed776784be9c3eba2ced4c6daea (patch) | |
tree | d6ed056976dcc2ea64df72224e9013db98f5dae1 /qa/qa/scenario/bootable.rb | |
parent | 760b2c75ef9d2c6acb655860dceae4c04cd8e5a7 (diff) | |
download | gitlab-ce-77103646678deed776784be9c3eba2ced4c6daea.tar.gz |
Make it possible to define global scenario attributes
Diffstat (limited to 'qa/qa/scenario/bootable.rb')
-rw-r--r-- | qa/qa/scenario/bootable.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/qa/qa/scenario/bootable.rb b/qa/qa/scenario/bootable.rb new file mode 100644 index 00000000000..22496bcc2fc --- /dev/null +++ b/qa/qa/scenario/bootable.rb @@ -0,0 +1,47 @@ +require 'optparse' + +module QA + module Scenario + module Bootable + Option = Struct.new(:name, :arg, :desc) + + def self.included(base) + base.extend(ClassMethods) + end + + module ClassMethods + def launch!(argv) + arguments = OptionParser.new do |parser| + options.to_a.each do |opt| + parser.on(opt.arg, opt.desc) do |value| + Runtime::Scenario.define(opt.name, value) + end + end + end + + arguments.parse!(argv) + + if has_attributes? + self.perform(**Runtime::Scenario.attributes) + else + self.perform(*argv) + end + end + + private + + def attribute(name, arg, desc) + options.push(Option.new(name, arg, desc)) + end + + def options + @options ||= [] + end + + def has_attributes? + options.any? + end + end + end + end +end |