9b5e89bd34
* [VAULT-2776] Add prefix_filter support to vault * [VAULT-2776] Add filter_default config, update docs * [VAULT-2776] Add changelog file * [VAULT-2776] Update telemetry tests and error handling * [VAULT-2776] Add test fixtures, update test * [VAULT-2776] Update gitignore hcl filter
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package configutil
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestParsePrefixFilters(t *testing.T) {
|
|
t.Parallel()
|
|
cases := []struct {
|
|
inputFilters []string
|
|
expectedErrStr string
|
|
expectedAllowedPrefixes []string
|
|
expectedBlockedPrefixes []string
|
|
}{
|
|
{
|
|
[]string{""},
|
|
"Cannot have empty filter rule in prefix_filter",
|
|
[]string(nil),
|
|
[]string(nil),
|
|
},
|
|
{
|
|
[]string{"vault.abc"},
|
|
"Filter rule must begin with either '+' or '-': \"vault.abc\"",
|
|
[]string(nil),
|
|
[]string(nil),
|
|
},
|
|
{
|
|
[]string{"+vault.abc", "-vault.bcd"},
|
|
"",
|
|
[]string{"vault.abc"},
|
|
[]string{"vault.bcd"},
|
|
},
|
|
}
|
|
t.Run("validate metric filter configs", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
for _, tc := range cases {
|
|
|
|
allowedPrefixes, blockedPrefixes, err := parsePrefixFilter(tc.inputFilters)
|
|
|
|
if err != nil {
|
|
assert.EqualError(t, err, tc.expectedErrStr)
|
|
} else {
|
|
assert.Equal(t, "", tc.expectedErrStr)
|
|
assert.Equal(t, tc.expectedAllowedPrefixes, allowedPrefixes)
|
|
|
|
assert.Equal(t, tc.expectedBlockedPrefixes, blockedPrefixes)
|
|
}
|
|
}
|
|
})
|
|
}
|