Class: Bucky::Core::Database::TestDataOperator
- Inherits:
-
Object
- Object
- Bucky::Core::Database::TestDataOperator
- Defined in:
- lib/bucky/core/database/test_data_operator.rb
Instance Method Summary collapse
-
#add_suite_id_to_loaded_suite_data(test_suite_data) ⇒ Array
Add test_suites.id to loaded suite data.
-
#get_last_round_from_job_id(job_id) ⇒ Int
Return last round.
-
#get_ng_test_cases_at_last_execution(cond) ⇒ Hash
Return file path and CaseName that failed at last time.
- #get_test_case_id(test_suite_id, case_name) ⇒ Object
-
#initialize ⇒ TestDataOperator
constructor
A new instance of TestDataOperator.
-
#save_job_record_and_get_job_id(start_time, command_and_option, fqdn) ⇒ Fixnum
Save job data and return job id.
-
#save_test_result(test_suite_result) ⇒ Object
Save test result.
-
#update_test_suites_data(test_suite_data) ⇒ Object
Save test suite data.
Constructor Details
#initialize ⇒ TestDataOperator
Returns a new instance of TestDataOperator.
10 11 12 13 14 |
# File 'lib/bucky/core/database/test_data_operator.rb', line 10 def initialize @connector = DbConnector.new @connector.connect @config = Bucky::Utils::Config.instance end |
Instance Method Details
#add_suite_id_to_loaded_suite_data(test_suite_data) ⇒ Array
Add test_suites.id to loaded suite data
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bucky/core/database/test_data_operator.rb', line 38 def add_suite_id_to_loaded_suite_data(test_suite_data) return test_suite_data if $debug test_suite_data.each_with_index do |test_data, i| suite = get_test_suite_from_test_data(test_data) test_suite_data[i][:test_suite_id] = suite[:id] end @connector.disconnect test_suite_data end |
#get_last_round_from_job_id(job_id) ⇒ Int
Return last round
108 109 110 111 112 |
# File 'lib/bucky/core/database/test_data_operator.rb', line 108 def get_last_round_from_job_id(job_id) round = @connector.con[:test_case_results].where(job_id: job_id).max(:round) @connector.disconnect round end |
#get_ng_test_cases_at_last_execution(cond) ⇒ Hash
Return file path and CaseName that failed at last time.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/bucky/core/database/test_data_operator.rb', line 67 def get_ng_test_cases_at_last_execution(cond) re_test_cond = {} return {} if $debug cases = @connector.con[:test_case_results].filter(cond).select(:test_case_id).all.map { |row| row[:test_case_id] } Sequel.split_symbols = true # To use test_cases__id suites_and_cases = @connector.con[:test_cases] .left_join(:test_suites, id: Sequel.qualify('test_cases', 'test_suite_id')) .where(test_cases__id: cases).all # Created data # { # 1 => {file_path: "/hoge/fuga.yml", cases_names: ["hogehoge_hoge_1", "hogehoge_hoge_2"]}, # 2 => {file_path: "/gefu/hugo.yml", cases_names: ["hogehoge_hoge_1", "hogehoge_hoge_2"]}, # } suites_and_cases.each do |suite_case| suite_id = suite_case[:test_suite_id] if re_test_cond.key? suite_id re_test_cond[suite_id][:case_names].push suite_case[:case_name] else re_test_cond[suite_id] = { file_path: suite_case[:file_path], case_names: [suite_case[:case_name]] } end end re_test_cond end |
#get_test_case_id(test_suite_id, case_name) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/bucky/core/database/test_data_operator.rb', line 95 def get_test_case_id(test_suite_id, case_name) return nil if $debug test_case = @connector.con[:test_cases].filter(test_suite_id: test_suite_id, case_name: case_name).first @connector.disconnect raise "Cannot get test_case id. test_suite_id: #{test_suite_id}, case_name: #{case_name}" if test_case.nil? test_case[:id] end |
#save_job_record_and_get_job_id(start_time, command_and_option, fqdn) ⇒ Fixnum
Save job data and return job id
21 22 23 24 25 26 27 |
# File 'lib/bucky/core/database/test_data_operator.rb', line 21 def save_job_record_and_get_job_id(start_time, command_and_option, fqdn) return 0 if $debug job_id = @connector.con[:jobs].insert(start_time: start_time, command_and_option: command_and_option, base_fqdn: fqdn) @connector.disconnect job_id end |
#save_test_result(test_suite_result) ⇒ Object
Save test result
31 32 33 34 |
# File 'lib/bucky/core/database/test_data_operator.rb', line 31 def save_test_result(test_suite_result) @connector.con[:test_case_results].import(test_suite_result[:column], test_suite_result[:data_set]) @connector.disconnect end |
#update_test_suites_data(test_suite_data) ⇒ Object
Save test suite data
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bucky/core/database/test_data_operator.rb', line 50 def update_test_suites_data(test_suite_data) return if $debug test_suite_data.each do |test_data| saved_test_suite = get_test_suite_from_test_data(test_data) suite_id = get_suite_id_from_saved_test_suite(saved_test_suite, test_data) test_data[:suite][:cases].each do |test_case| labels = get_labels_from_suite_and_case(test_data[:suite][:labels], test_case[:labels]) label_ids = insert_and_return_label_ids(labels) update_test_case_and_test_case_label(suite_id, test_case, label_ids) end end @connector.disconnect end |