test(aa): refractor interface rule unit tests.

This commit is contained in:
Alexandre Pujol 2024-06-27 11:39:36 +01:00
parent 732134bd96
commit 86b2f74a24
Failed to generate hash of commit
2 changed files with 30 additions and 30 deletions

View file

@ -14,7 +14,7 @@ import (
func Test_tokenizeRule(t *testing.T) { func Test_tokenizeRule(t *testing.T) {
inHeader = true inHeader = true
for _, tt := range testRules { for _, tt := range testParseRules {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if got := tokenizeRule(tt.raw); !reflect.DeepEqual(got, tt.tokens) { if got := tokenizeRule(tt.raw); !reflect.DeepEqual(got, tt.tokens) {
t.Errorf("tokenize() = %v, want %v", got, tt.tokens) t.Errorf("tokenize() = %v, want %v", got, tt.tokens)
@ -25,7 +25,7 @@ func Test_tokenizeRule(t *testing.T) {
func Test_parseRule(t *testing.T) { func Test_parseRule(t *testing.T) {
inHeader = true inHeader = true
for _, tt := range testRules { for _, tt := range testParseRules {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if got := parseRule(tt.raw); !reflect.DeepEqual(got, tt.rule) { if got := parseRule(tt.raw); !reflect.DeepEqual(got, tt.rule) {
t.Errorf("parseRule() = %v, want %v", got, tt.rule) t.Errorf("parseRule() = %v, want %v", got, tt.rule)
@ -35,7 +35,7 @@ func Test_parseRule(t *testing.T) {
} }
func Test_rule_Getter(t *testing.T) { func Test_rule_Getter(t *testing.T) {
for _, tt := range testRules { for _, tt := range testParseRules {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if tt.wGetAsMap == nil { if tt.wGetAsMap == nil {
tt.wGetAsMap = map[string][]string{} tt.wGetAsMap = map[string][]string{}
@ -113,7 +113,7 @@ func Test_parseCommaRules(t *testing.T) {
} }
func Test_newRules(t *testing.T) { func Test_newRules(t *testing.T) {
for _, tt := range testRules { for _, tt := range testParseRules {
if tt.wRule == nil { if tt.wRule == nil {
continue continue
} }
@ -159,7 +159,7 @@ func Test_AppArmorProfileFile_Parse(t *testing.T) {
var ( var (
// Test cases for tokenizeRule, parseRule,rule getters, and newRules // Test cases for tokenizeRule, parseRule,rule getters, and newRules
testRules = []struct { testParseRules = []struct {
name string name string
raw string raw string
tokens []string tokens []string
@ -497,7 +497,7 @@ var (
wString: "signal receive set=(cont term winch) peer=at-spi-bus-launcher", wString: "signal receive set=(cont term winch) peer=at-spi-bus-launcher",
wRule: &Signal{ wRule: &Signal{
Access: []string{"receive"}, Access: []string{"receive"},
Set: []string{"term", "cont", "winch"}, Set: []string{"cont", "term", "winch"},
Peer: "at-spi-bus-launcher", Peer: "at-spi-bus-launcher",
}, },
}, },
@ -1123,7 +1123,7 @@ var (
{ {
&Signal{ &Signal{
Access: []string{"receive"}, Access: []string{"receive"},
Set: []string{"term", "cont", "winch"}, Set: []string{"cont", "term", "winch"},
Peer: "at-spi-bus-launcher", Peer: "at-spi-bus-launcher",
}, },
}, },

View file

@ -9,7 +9,7 @@ import (
"testing" "testing"
) )
func TestRules_FromLog(t *testing.T) { func TestRule_FromLog(t *testing.T) {
for _, tt := range testRule { for _, tt := range testRule {
if tt.fromLog == nil { if tt.fromLog == nil {
continue continue
@ -22,27 +22,7 @@ func TestRules_FromLog(t *testing.T) {
} }
} }
func TestRules_Validate(t *testing.T) { func TestRule_String(t *testing.T) {
for _, tt := range testRule {
t.Run(tt.name, func(t *testing.T) {
if err := tt.rule.Validate(); (err != nil) != tt.wValidErr {
t.Errorf("Rules.Validate() error = %v, wantErr %v", err, tt.wValidErr)
}
})
}
}
func TestCapability_Compare(t *testing.T) {
for _, tt := range testRule {
t.Run(tt.name, func(t *testing.T) {
if got := tt.rule.Compare(tt.other); got != tt.wCompare {
t.Errorf("Rule.Compare() = %v, want %v", got, tt.wCompare)
}
})
}
}
func TestRules_String(t *testing.T) {
for _, tt := range testRule { for _, tt := range testRule {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if got := tt.rule.String(); got != tt.wString { if got := tt.rule.String(); got != tt.wString {
@ -52,7 +32,27 @@ func TestRules_String(t *testing.T) {
} }
} }
func TestCapability_Merge(t *testing.T) { func TestRule_Validate(t *testing.T) {
for _, tt := range testRule {
t.Run(tt.name, func(t *testing.T) {
if err := tt.rule.Validate(); (err != nil) != tt.wValidErr {
t.Errorf("Rules.Validate() error = %v, wantErr %v", err, tt.wValidErr)
}
})
}
}
func TestRule_Compare(t *testing.T) {
for _, tt := range testRule {
t.Run(tt.name, func(t *testing.T) {
if got := tt.rule.Compare(tt.other); got != tt.wCompare {
t.Errorf("Rule.Compare() = %v, want %v", got, tt.wCompare)
}
})
}
}
func TestRule_Merge(t *testing.T) {
for _, tt := range testRule { for _, tt := range testRule {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if got := tt.rule.Merge(tt.other); got != tt.wMerge { if got := tt.rule.Merge(tt.other); got != tt.wMerge {