Fix parsing regex, #1318

This commit is contained in:
Alexander Zobnin
2022-02-16 17:59:56 +03:00
parent f4fad8d58d
commit 0a4714f9e9
2 changed files with 38 additions and 2 deletions

View File

@@ -1,8 +1,9 @@
package zabbix
import (
"github.com/stretchr/testify/assert"
"testing"
"github.com/stretchr/testify/assert"
)
func TestExpandItemName(t *testing.T) {
@@ -55,3 +56,38 @@ func TestExpandItemName(t *testing.T) {
})
}
}
func TestParseFilter(t *testing.T) {
tests := []struct {
name string
filter string
expectNoError bool
expectedError string
}{
{
name: "Simple regexp",
filter: "/.*/",
expectNoError: true,
expectedError: "",
},
{
name: "Not a regex",
filter: "/var/lib/mysql: Total space",
expectNoError: true,
expectedError: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := parseFilter(tt.filter)
if tt.expectNoError {
assert.NoError(t, err)
}
if tt.expectedError != "" {
assert.Error(t, err)
assert.EqualError(t, err, tt.expectedError)
}
})
}
}