Sha256: a61983c82a4e321d824a4a21687c849b7135196535c566d64d1b64f947a3cdd0
Contents?: true
Size: 1.62 KB
Versions: 2
Compression:
Stored size: 1.62 KB
Contents
module ResourceDSLMethods # Convert a nested hash to a mapping of key paths to expected classes def hash_to_mapping(h, path=[], mapping={}) h.each do |k,v| if v.is_a?(Hash) hash_to_mapping(v, path + [k], mapping) else full_path = path + [k] mapping[full_path] = v end end mapping end def test_api(expected, path) context "GET #{path}" do let(:payload) { LogStash::Json.load(last_response.body) } before(:all) do do_request { get path } end it "should respond OK" do expect(last_response).to be_ok end hash_to_mapping(expected).each do |resource_path,klass| dotted = resource_path.join(".") it "should set '#{dotted}' at '#{path}' to be a '#{klass}'" do expect(last_response).to be_ok # fail early if need be resource_path_value = resource_path.reduce(payload) do |acc,v| expect(acc.has_key?(v)).to eql(true), "Expected to find value '#{v}' in structure '#{acc}', but could not. Payload was '#{payload}'" acc[v] end expect(resource_path_value).to be_a(klass), "could not find '#{dotted}' in #{payload}" end end end yield if block_given? # Add custom expectations end def test_api_and_resources(expected, xopts={}) xopts[:exclude_from_root] ||= [] root_expectation = expected.clone xopts[:exclude_from_root].each {|k| root_expectation.delete(k)} test_api(root_expectation, "/") expected.keys.each do |key| test_api({key => expected[key]}, "/#{key}") end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
logstash-core-5.0.0.alpha4.snapshot3-java | spec/api/lib/api/support/resource_dsl_methods.rb |
logstash-core-5.0.0.alpha4.snapshot2-java | spec/api/lib/api/support/resource_dsl_methods.rb |