|
| 1 | +# Licensed to Elasticsearch B.V. under one or more contributor |
| 2 | +# license agreements. See the NOTICE file distributed with |
| 3 | +# this work for additional information regarding copyright |
| 4 | +# ownership. Elasticsearch B.V. licenses this file to you under |
| 5 | +# the Apache License, Version 2.0 (the "License"); you may |
| 6 | +# not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +# 'catch' is in the task group definition |
| 19 | +def run_rspec_matchers_on_task_group(task_group, test) |
| 20 | + if task_group.catch_exception? |
| 21 | + it 'sends the request and throws the expected error' do |
| 22 | + expect(task_group.exception).to match_error(task_group.expected_exception_message) |
| 23 | + end |
| 24 | + |
| 25 | + # 'match' on error description is in the task group definition |
| 26 | + if task_group.has_match_clauses? |
| 27 | + task_group.match_clauses.each do |match| |
| 28 | + it 'contains the expected error in the request response' do |
| 29 | + regexp = if (val = match['match'].values.first.to_s).include?('\\s') |
| 30 | + Regexp.new(val.gsub('\\\\', '\\').gsub('/', '')) |
| 31 | + else |
| 32 | + Regexp.new(Regexp.escape(val)) |
| 33 | + end |
| 34 | + expect(task_group.exception.message).to match(regexp) |
| 35 | + end |
| 36 | + end |
| 37 | + end |
| 38 | + else |
| 39 | + # 'match' is in the task group definition |
| 40 | + if task_group.has_match_clauses? |
| 41 | + task_group.match_clauses.each do |match| |
| 42 | + it "has the expected value (#{match['match'].values.join(',')}) in the response field (#{match['match'].keys.join(',')})" do |
| 43 | + expect(task_group.response).to match_response(match['match'], test) |
| 44 | + end |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + # 'length' is in the task group definition |
| 49 | + if task_group.has_length_match_clauses? |
| 50 | + task_group.length_match_clauses.each do |match| |
| 51 | + it "the '#{match['length'].keys.join(',')}' field have the expected length" do |
| 52 | + expect(task_group.response).to match_response_field_length(match['length'], test) |
| 53 | + end |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + # 'is_true' is in the task group definition |
| 58 | + if task_group.has_true_clauses? |
| 59 | + task_group.true_clauses.each do |match| |
| 60 | + it "sends the request and the '#{match['is_true']}' field is set to true" do |
| 61 | + expect(task_group.response).to match_true_field(match['is_true'], test) |
| 62 | + end |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + # 'is_false' is in the task group definition |
| 67 | + if task_group.has_false_clauses? |
| 68 | + task_group.false_clauses.each do |match| |
| 69 | + it "sends the request and the '#{match['is_false']}' field is set to true" do |
| 70 | + expect(task_group.response).to match_false_field(match['is_false'], test) |
| 71 | + end |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + # 'gte' is in the task group definition |
| 76 | + if task_group.has_gte_clauses? |
| 77 | + task_group.gte_clauses.each do |match| |
| 78 | + it "sends the request and the '#{match['gte']}' field is greater than or equal to the expected value" do |
| 79 | + expect(task_group.response).to match_gte_field(match['gte'], test) |
| 80 | + end |
| 81 | + end |
| 82 | + end |
| 83 | + |
| 84 | + # 'gt' is in the task group definition |
| 85 | + if task_group.has_gt_clauses? |
| 86 | + task_group.gt_clauses.each do |match| |
| 87 | + it "sends the request and the '#{match['gt']}' field is greater than the expected value" do |
| 88 | + expect(task_group.response).to match_gt_field(match['gt'], test) |
| 89 | + end |
| 90 | + end |
| 91 | + end |
| 92 | + |
| 93 | + # 'lte' is in the task group definition |
| 94 | + if task_group.has_lte_clauses? |
| 95 | + task_group.lte_clauses.each do |match| |
| 96 | + it "sends the request and the '#{match['lte']}' field is less than or equal to the expected value" do |
| 97 | + expect(task_group.response).to match_lte_field(match['lte'], test) |
| 98 | + end |
| 99 | + end |
| 100 | + end |
| 101 | + |
| 102 | + # 'lt' is in the task group definition |
| 103 | + if task_group.has_lt_clauses? |
| 104 | + task_group.lt_clauses.each do |match| |
| 105 | + it "sends the request and the '#{match['lt']}' field is less than the expected value" do |
| 106 | + expect(task_group.response).to match_lt_field(match['lt'], test) |
| 107 | + end |
| 108 | + end |
| 109 | + end |
| 110 | + end |
| 111 | +end |
0 commit comments