From 896235cf3993b9fb446541dd673c00191e713a2f Mon Sep 17 00:00:00 2001 From: ytti Date: Wed, 13 Jun 2018 16:42:53 +0300 Subject: Feature string navigation for HTTP source API JSON Allow HTTP API to place host array in arbitrary place defined as: hosts_location: a.b[0].c Also support arrays in mapping keys: key: location[0].is.here[2] --- spec/source/http_spec.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 spec/source/http_spec.rb (limited to 'spec') diff --git a/spec/source/http_spec.rb b/spec/source/http_spec.rb new file mode 100644 index 0000000..d3df551 --- /dev/null +++ b/spec/source/http_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' +require 'oxidized/source/http' + +describe Oxidized::HTTP do + before(:each) do + Oxidized.asetus = Asetus.new + Oxidized.setup_logger + end + + describe "#string_navigate" do + h1 = {} + h1["inventory"] = [{ "ip" => "10.10.10.10" }] + h1["jotain"] = { "2" => "jotain" } + it "should be able to navigate multilevel-hash" do + http = Oxidized::HTTP.new + http.class.must_equal Oxidized::HTTP + http.send(:string_navigate, h1, "jotain.2").must_equal "jotain" + end + it "should be able to navigate multilevel-hash" do + Oxidized::HTTP.new.send(:string_navigate, h1, "jotain.2").must_equal "jotain" + end + it "should be able to navigate hash/array combination" do + Oxidized::HTTP.new.send(:string_navigate, h1, "inventory[0].ip").must_equal "10.10.10.10" + end + it "should return nil on non-existing string key" do + Oxidized::HTTP.new.send(:string_navigate, h1, "jotain.3").must_equal nil + end + it "should return nil on non-existing array index" do + Oxidized::HTTP.new.send(:string_navigate, h1, "inventory[3]").must_equal nil + end + end +end -- cgit v1.2.1