Skip to content

Commit

Permalink
feat: Add Wildcard pattern tests
Browse files Browse the repository at this point in the history
  • Loading branch information
estolfo committed Mar 2, 2023
1 parent c75d9eb commit 7f68284
Show file tree
Hide file tree
Showing 2 changed files with 222 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
{
"testMatchesStartsWith": {
"foo*": {
"foo": true,
"foobar": true,
"bar": false,
"barfoo": false,
"rfoo": false
}
},
"testWildcardInTheMiddle": {
"/foo/*/baz": {
"/foo/bar/baz": true,
"/foo/bar": false
}
},
"testCompoundWildcardMatcher": {
"*foo*foo*": {
"foofoo": true,
"foo/bar/foo": true,
"/foo/bar/foo/bar": true,
"foo": false
}
},
"testCompoundWildcardMatcher3": {
"*foo*oo*": {
"foooo": true,
"foofoo": true,
"foo/bar/foo": true,
"/foo/bar/foo/bar": true,
"foo": false,
"fooo": false
}
},
"testCompoundWildcardMatcher2": {
"*foo*bar*": {
"foobar": true,
"foo/bar/foo/baz": true,
"/foo/bar/baz": true,
"bar/foo": false,
"barfoo": false
}
},
"testCompoundWildcardMatcher4": {
"*foo*far*": {
"foofar": true,
"foo/far/foo/baz": true,
"/foo/far/baz": true,
"/far/foo": false,
"farfoo": false
}
},
"testMatchBetween": {
"*foo*foo*": {
"foofoo": true,
"foo/foo/foo/baz": true,
"/foo/foo/baz": true,
"/foo/foo": true,
"foobar": false
}
},
"testComplexExpressions": {
"/foo/*/baz*": {
"/foo/a/bar/b/baz": true
},
"/foo/*/bar/*/baz": {
"/foo/a/bar/b/baz": true
}
},
"testInfixEmptyMatcher": {
"**": {
"": true,
"foo": true
}
},
"testMatchesEndsWith": {
"*foo": {
"foo": true,
"foobar": false,
"bar": false,
"barfoo": true,
"foor": false
}
},
"testMatchesEquals": {
"foo": {
"foo": true,
"foobar": false,
"bar": false,
"barfoo": false
}
},
"testMatchesInfix": {
"*foo*": {
"foo": true,
"foobar": true,
"bar": false,
"barfoo": true,
"barfoobaz": true
}
},
"testMatchesNoWildcard": {
"foo": {
"foo": true,
"foobar": false
}
},
"testMatchesStartsWith_ignoreCase": {
"foo*": {
"foo": true,
"foobar": true,
"bar": false,
"barfoo": false
}
},
"testInfixEmptyMatcher_ignoreCase": {
"**": {
"": true,
"foo": true
}
},
"testMatchesEndsWith_ignoreCase": {
"*foo": {
"fOo": true,
"foobar": false,
"bar": false,
"baRFoo": true
}
},
"testMatchesEquals_ignoreCase": {
"foo": {
"fOo": true,
"foOBar": false,
"BAR": false,
"barfoo": false
}
},
"testMatchesInfix_ignoreCase": {
"*foo*": {
"FOO": true,
"foOBar": true,
"BAR": false,
"baRFOo": true,
"BARFOOBAZ": true
}
},
"testMatchesInfix_caseSensitive": {
"(?-i)*foo*": {
"foo": true,
"FOO": false
}
},
"testMatchesNoWildcard_ignoreCase": {
"foo": {
"FOO": true,
"foobar": false
}
},
"testNeedleLongerThanHaystack": {
"*foo": {
"baz": false
},
"*foob": {
"baz": false
},
"*fooba": {
"baz": false
},
"*foobar": {
"baz": false
},
"foo*": {
"baz": false
},
"foob*": {
"baz": false
},
"fooba*": {
"baz": false
},
"foobar*": {
"baz": false
},
"*foobar*": {
"baz": false
}
},
"testSingleCharacterWildcardNotSupported": {
"fo?": {
"foo": false,
"fo?": true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

require 'test_helper'

require_relative '../../../lib/opentelemetry/instrumentation/elasticsearch'

describe OpenTelemetry::Instrumentation::Elasticsearch::WildcardPattern do
let(:wildcard_obj) { OpenTelemetry::Instrumentation::Elasticsearch::WildcardPattern.new(pattern) }
JSON.parse(
File.read("test/fixtures/wildcard_matcher_tests.json", :encoding => 'utf-8')
).each do |category, group|
describe(category) do
group.each do |pattern_from_json, examples|
let(:pattern) { pattern_from_json }

examples.each do |string, expectation|
it("#{pattern_from_json} #{expectation ? '=~' : '!~'} #{string}") do
_(wildcard_obj.match?(string)).must_equal(expectation)
end
end
end
end
end
end

0 comments on commit 7f68284

Please sign in to comment.