mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Many unittests for internal folder
This commit is contained in:
parent
24151345f5
commit
a217f88ea1
10 changed files with 506 additions and 0 deletions
39
internal/filter/filter_test.go
Normal file
39
internal/filter/filter_test.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// This file is Free Software under the MIT License
|
||||
// without warranty, see README.md and LICENSES/MIT.txt for details.
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2023 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de>
|
||||
// Software-Engineering: 2023 Intevation GmbH <https://intevation.de>
|
||||
|
||||
// Package filter implements helps to filter advisories.
|
||||
package filter
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// NewPatternMatcher compiles a new list of regular expression from
|
||||
// a given list of strings.
|
||||
func TestNewPatternMatcher(t *testing.T) {
|
||||
var regex []string
|
||||
if pm, err := NewPatternMatcher(regex); pm == nil || err != nil {
|
||||
t.Errorf("Failure: Did not compile valid regex pattern")
|
||||
}
|
||||
regex = append(regex, "++")
|
||||
if pm, err := NewPatternMatcher(regex); pm != nil || err == nil {
|
||||
t.Errorf("Failure: No error thrown at invalid compile pattern")
|
||||
}
|
||||
}
|
||||
|
||||
// Matches returns true if the given string matches any of the expressions.
|
||||
func TestMatches(t *testing.T) {
|
||||
regex := []string{"a"}
|
||||
pm, _ := NewPatternMatcher(regex)
|
||||
if !pm.Matches("a") {
|
||||
t.Errorf("Failure: Did not match two identical strings")
|
||||
}
|
||||
if pm.Matches("b") {
|
||||
t.Errorf("Failure: Matched two non-matching strings")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue