diff --git a/lib/kadalu/binnacle.rb b/lib/kadalu/binnacle.rb index 9c1fee0..724d0be 100644 --- a/lib/kadalu/binnacle.rb +++ b/lib/kadalu/binnacle.rb @@ -49,6 +49,10 @@ def start(task_file, opts) if stdout_line.start_with?('{') begin data = JSON.parse(stdout_line, { symbolize_names: true }) + + # Without ok field this may not be a summary line + next unless data.key?(:ok) + metrics[:tasks] << data Messages.task_summary(data) if data[:ok] diff --git a/lib/kadalu/binnacle/plugins/http.rb b/lib/kadalu/binnacle/plugins/http.rb index 5582123..50f1b49 100644 --- a/lib/kadalu/binnacle/plugins/http.rb +++ b/lib/kadalu/binnacle/plugins/http.rb @@ -82,17 +82,61 @@ module Binnacle # Add a header to the request # + # Using as Block + # + # ``` + # http_base_url "http://localhost:5001" + # http_add_header "Authorization", "Bearer 12345" do + # http_get "/api/folders" + # end + # ``` + # + # or without block + # # ``` # http_base_url "http://localhost:5001" # http_add_header "Authorization", "Bearer 12345" # http_get "/api/folders" # ``` register_plugin 'http_add_header' do |name, value, &block| - Store.hash_add(:request_headers, name, value, &block) + Store.hash_set(:request_headers, name, value, &block) + end + + # Set the header to the request + # + # Using as Block + # + # ``` + # http_base_url "http://localhost:5001" + # http_set_header "Authorization", "Bearer 12345" do + # http_get "/api/folders" + # end + # ``` + # + # or without block + # + # ``` + # http_base_url "http://localhost:5001" + # http_set_header "Authorization", "Bearer 12345" + # http_get "/api/folders" + # ``` + register_plugin 'http_set_header' do |name, value, &block| + Store.hash_set(:request_headers, name, value, &block) end # Remove header from the request # + # Using as a Block + # + # ``` + # http_base_url "http://localhost:5001" + # http_remove_header "Authorization" do + # http_get "/api/folders", status: 403 + # end + # ``` + # + # or without block + # # ``` # http_base_url "http://localhost:5001" # http_remove_header "Authorization" diff --git a/lib/kadalu/binnacle/store.rb b/lib/kadalu/binnacle/store.rb index 3fa0eb5..ef622e0 100644 --- a/lib/kadalu/binnacle/store.rb +++ b/lib/kadalu/binnacle/store.rb @@ -37,14 +37,18 @@ def self.set(name, value, &block) nil end - def self.hash_add(hash_name, name, value, &block) + def self.hash_set(hash_name, name, value, &block) @data[hash_name] = {} unless @data.key?(hash_name) if block - prev_value = get(hash_name) + prev_value = @data[hash_name][name] @data[hash_name][name] = value block.call - @data[hash_name] = prev_value + if prev_value + @data[hash_name][name] = prev_value + else + @data[hash_name].delete(name) + end else @data[hash_name][name] = value end @@ -56,10 +60,10 @@ def self.hash_remove(hash_name, name, &block) @data[hash_name] = {} unless @data.key?(hash_name) if block - prev_value = get(hash_name) - @data[hash_name].delete(name) if @data[hash_name].key?(name) + prev_value = @data[hash_name][name] + @data[hash_name].delete(name) if prev_value block.call - @data[hash_name] = prev_value + @data[hash_name][name] = prev_value if prev_value elsif @data[hash_name].key?(name) @data[hash_name].delete(name) end