mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2025-01-18 08:58:15 +01:00
tests(aa): improve rules unit tests.
This commit is contained in:
parent
23eaa20fb7
commit
5f64bb4e0c
3 changed files with 441 additions and 661 deletions
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
func Test_tokenizeRule(t *testing.T) {
|
||||
for _, tt := range testRules {
|
||||
for _, tt := range testTokenRules {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tokenize(tt.raw); !reflect.DeepEqual(got, tt.tokens) {
|
||||
t.Errorf("tokenize() = %v, want %v", got, tt.tokens)
|
||||
|
@ -37,7 +37,7 @@ func Test_AppArmorProfileFile_Parse(t *testing.T) {
|
|||
|
||||
var (
|
||||
// Test cases for tokenize
|
||||
testRules = []struct {
|
||||
testTokenRules = []struct {
|
||||
name string
|
||||
raw string
|
||||
tokens []string
|
||||
|
|
|
@ -54,6 +54,9 @@ type Rules []Rule
|
|||
|
||||
func (r Rules) Validate() error {
|
||||
for _, rule := range r {
|
||||
if rule == nil {
|
||||
continue
|
||||
}
|
||||
if err := rule.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -66,9 +69,12 @@ func (r Rules) String() string {
|
|||
}
|
||||
|
||||
// Index returns the index of the first occurrence of rule rin r, or -1 if not present.
|
||||
func (r Rules) Index(rule Rule) int {
|
||||
for idx, rr := range r {
|
||||
if rr.Kind() == rule.Kind() && rr.Equals(rule) {
|
||||
func (r Rules) Index(item Rule) int {
|
||||
for idx, rule := range r {
|
||||
if rule == nil {
|
||||
continue
|
||||
}
|
||||
if rule.Kind() == item.Kind() && rule.Equals(item) {
|
||||
return idx
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +100,9 @@ func (r Rules) Delete(i int) Rules {
|
|||
func (r Rules) DeleteKind(kind Kind) Rules {
|
||||
res := make(Rules, 0)
|
||||
for _, rule := range r {
|
||||
if rule == nil {
|
||||
continue
|
||||
}
|
||||
if rule.Kind() != kind {
|
||||
res = append(res, rule)
|
||||
}
|
||||
|
@ -104,6 +113,9 @@ func (r Rules) DeleteKind(kind Kind) Rules {
|
|||
func (r Rules) Filter(filter Kind) Rules {
|
||||
res := make(Rules, 0)
|
||||
for _, rule := range r {
|
||||
if rule == nil {
|
||||
continue
|
||||
}
|
||||
if rule.Kind() != filter {
|
||||
res = append(res, rule)
|
||||
}
|
||||
|
|
1080
pkg/aa/rules_test.go
1080
pkg/aa/rules_test.go
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue