feat: add Subscription types and subject validation with wildcard matching
This commit is contained in:
57
tests/NATS.Server.Tests/SubjectMatchTests.cs
Normal file
57
tests/NATS.Server.Tests/SubjectMatchTests.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using NATS.Server.Subscriptions;
|
||||
|
||||
namespace NATS.Server.Tests;
|
||||
|
||||
public class SubjectMatchTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("foo", true)]
|
||||
[InlineData("foo.bar", true)]
|
||||
[InlineData("foo.bar.baz", true)]
|
||||
[InlineData("foo.*", true)]
|
||||
[InlineData("foo.>", true)]
|
||||
[InlineData(">", true)]
|
||||
[InlineData("*", true)]
|
||||
[InlineData("*.bar", true)]
|
||||
[InlineData("foo.*.baz", true)]
|
||||
[InlineData("", false)]
|
||||
[InlineData("foo.", false)]
|
||||
[InlineData(".foo", false)]
|
||||
[InlineData("foo..bar", false)]
|
||||
[InlineData("foo.>.bar", false)] // > must be last token
|
||||
[InlineData("foo bar", false)] // no spaces
|
||||
[InlineData("foo\tbar", false)] // no tabs
|
||||
public void IsValidSubject(string subject, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, SubjectMatch.IsValidSubject(subject));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("foo", true)]
|
||||
[InlineData("foo.bar.baz", true)]
|
||||
[InlineData("foo.*", false)]
|
||||
[InlineData("foo.>", false)]
|
||||
[InlineData(">", false)]
|
||||
[InlineData("*", false)]
|
||||
public void IsValidPublishSubject(string subject, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, SubjectMatch.IsValidPublishSubject(subject));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("foo", "foo", true)]
|
||||
[InlineData("foo", "bar", false)]
|
||||
[InlineData("foo.bar", "foo.*", true)]
|
||||
[InlineData("foo.bar", "*.bar", true)]
|
||||
[InlineData("foo.bar", "*.*", true)]
|
||||
[InlineData("foo.bar.baz", "foo.>", true)]
|
||||
[InlineData("foo.bar.baz", ">", true)]
|
||||
[InlineData("foo.bar", "foo.>", true)]
|
||||
[InlineData("foo", "foo.>", false)]
|
||||
[InlineData("foo.bar.baz", "foo.*", false)]
|
||||
[InlineData("foo.bar", "foo.bar.>", false)]
|
||||
public void MatchLiteral(string literal, string pattern, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, SubjectMatch.MatchLiteral(literal, pattern));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user