mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
improve mapping template regex to allow for some extra spaces and associated test upgrade
This commit is contained in:
@@ -164,8 +164,8 @@ const (
|
||||
)
|
||||
|
||||
var commaSeparatorRegEx = regexp.MustCompile(`,\s*`)
|
||||
var partitionMappingFunctionRegEx = regexp.MustCompile(`{{partition *\((.*)\)}}`)
|
||||
var wildcardMappingFunctionRegEx = regexp.MustCompile(`{{wildcard *\((.*)\)}}`)
|
||||
var partitionMappingFunctionRegEx = regexp.MustCompile(`{{\s*partition\s*\((.*)\)\s*}}`)
|
||||
var wildcardMappingFunctionRegEx = regexp.MustCompile(`{{\s*wildcard\s*\((.*)\)\s*}}`)
|
||||
|
||||
// String helper.
|
||||
func (rt ServiceRespType) String() string {
|
||||
|
||||
@@ -63,12 +63,35 @@ func TestPlaceHolderIndex(t *testing.T) {
|
||||
t.Fatalf("Error parsing %s", testString)
|
||||
}
|
||||
|
||||
testString = "{{ partition(10,1,2,3) }}"
|
||||
|
||||
indexes, nbPartitions, err = placeHolderIndex(testString)
|
||||
|
||||
if err != nil || !reflect.DeepEqual(indexes, []int{1, 2, 3}) || nbPartitions != 10 {
|
||||
t.Fatalf("Error parsing %s", testString)
|
||||
}
|
||||
|
||||
testString = "{{partition (10,1,2,3)}}"
|
||||
|
||||
indexes, nbPartitions, err = placeHolderIndex(testString)
|
||||
|
||||
if err != nil || !reflect.DeepEqual(indexes, []int{1, 2, 3}) || nbPartitions != 10 {
|
||||
t.Fatalf("Error parsing %s", testString)
|
||||
}
|
||||
|
||||
testString = "{{wildcard(2)}}"
|
||||
indexes, nbPartitions, err = placeHolderIndex(testString)
|
||||
|
||||
if err != nil || len(indexes) != 1 || indexes[0] != 2 || nbPartitions != -1 {
|
||||
t.Fatalf("Error parsing %s", testString)
|
||||
}
|
||||
|
||||
testString = "{{ wildcard (2) }}"
|
||||
indexes, nbPartitions, err = placeHolderIndex(testString)
|
||||
|
||||
if err != nil || len(indexes) != 1 || indexes[0] != 2 || nbPartitions != -1 {
|
||||
t.Fatalf("Error parsing %s", testString)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterDuplicateAccounts(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user