apparmor.d/cmd/aa-log/main_test.go

69 lines
1.3 KiB
Go
Raw Normal View History

2021-12-05 00:53:32 +01:00
// aa-log - Review AppArmor generated messages
// Copyright (C) 2021 Alexandre Pujol <alexandre@pujol.io>
// SPDX-License-Identifier: GPL-2.0-only
package main
import (
"testing"
)
2021-12-12 13:35:08 +01:00
func Test_app(t *testing.T) {
tests := []struct {
name string
logger string
2021-12-12 13:35:08 +01:00
path string
profile string
2023-08-17 20:15:21 +02:00
rules bool
2021-12-12 13:35:08 +01:00
wantErr bool
}{
{
name: "Test audit.log",
logger: "auditd",
2021-12-12 13:35:08 +01:00
path: "../../tests/audit.log",
profile: "",
2023-08-17 20:15:21 +02:00
rules: false,
wantErr: false,
},
{
name: "Test audit.log to rules",
logger: "auditd",
path: "../../tests/audit.log",
profile: "",
rules: rules,
wantErr: false,
},
{
name: "Test Dbus Session",
logger: "systemd",
path: "../../tests/systemd.log",
profile: "",
2023-08-17 20:15:21 +02:00
rules: false,
2021-12-12 13:35:08 +01:00
wantErr: false,
},
{
name: "No logfile",
logger: "auditd",
2021-12-12 13:35:08 +01:00
path: "../../tests/log",
profile: "",
2023-08-17 20:15:21 +02:00
rules: false,
wantErr: true,
},
{
name: "Logger not supported",
logger: "raw",
path: "../../tests/audit.log",
profile: "",
2023-08-17 20:15:21 +02:00
rules: false,
2021-12-12 13:35:08 +01:00
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := aaLog(tt.logger, tt.path, tt.profile, tt.rules); (err != nil) != tt.wantErr {
2021-12-12 13:35:08 +01:00
t.Errorf("aaLog() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}