diff --git a/cmd/aa-log/main_test.go b/cmd/aa-log/main_test.go index 92693c79..fb933867 100644 --- a/cmd/aa-log/main_test.go +++ b/cmd/aa-log/main_test.go @@ -5,9 +5,14 @@ package main import ( + "path/filepath" "testing" ) +var ( + testdata = "../../tests/testdata/logs" +) + func Test_app(t *testing.T) { tests := []struct { name string @@ -20,7 +25,7 @@ func Test_app(t *testing.T) { { name: "Test audit.log", logger: "auditd", - path: "../../tests/audit.log", + path: filepath.Join(testdata, "audit.log"), profile: "", rules: false, wantErr: false, @@ -28,7 +33,7 @@ func Test_app(t *testing.T) { { name: "Test audit.log to rules", logger: "auditd", - path: "../../tests/audit.log", + path: filepath.Join(testdata, "audit.log"), profile: "", rules: true, wantErr: false, @@ -36,7 +41,7 @@ func Test_app(t *testing.T) { { name: "Test Dbus Session", logger: "systemd", - path: "../../tests/systemd.log", + path: filepath.Join(testdata, "systemd.log"), profile: "", rules: false, wantErr: false, @@ -44,7 +49,7 @@ func Test_app(t *testing.T) { { name: "No logfile", logger: "auditd", - path: "../../tests/log", + path: filepath.Join(testdata, "log"), profile: "", rules: false, wantErr: true, @@ -52,7 +57,7 @@ func Test_app(t *testing.T) { { name: "Logger not supported", logger: "raw", - path: "../../tests/audit.log", + path: filepath.Join(testdata, "audit.log"), profile: "", rules: false, wantErr: true, diff --git a/cmd/prebuild/main_test.go b/cmd/prebuild/main_test.go index 92af60c2..8e80c3ab 100644 --- a/cmd/prebuild/main_test.go +++ b/cmd/prebuild/main_test.go @@ -20,7 +20,7 @@ func chdirGitRoot() { if err != nil { panic(err) } - root := string(out)[0 : len(out)-1] + root := string(out[0 : len(out)-1]) if err := os.Chdir(root); err != nil { panic(err) } diff --git a/pkg/aa/apparmor_test.go b/pkg/aa/apparmor_test.go index b1a2c961..a580e7e5 100644 --- a/pkg/aa/apparmor_test.go +++ b/pkg/aa/apparmor_test.go @@ -13,8 +13,8 @@ import ( ) var ( - testData = paths.New("../../").Join("tests") - intData = paths.New("../../").Join("apparmor.d") + testData = paths.New("../../tests/testdata/") + intData = paths.New("../../apparmor.d") ) func TestAppArmorProfileFile_String(t *testing.T) { diff --git a/pkg/logs/loggers_test.go b/pkg/logs/loggers_test.go index 5a58c7c7..15fa1fbc 100644 --- a/pkg/logs/loggers_test.go +++ b/pkg/logs/loggers_test.go @@ -5,10 +5,15 @@ package logs import ( + "path/filepath" "reflect" "testing" ) +var ( + testdata = "../../tests/testdata/logs" +) + func TestGetJournalctlLogs(t *testing.T) { tests := []struct { name string @@ -19,7 +24,7 @@ func TestGetJournalctlLogs(t *testing.T) { { name: "gsd-xsettings", useFile: true, - path: "../../tests/systemd.log", + path: filepath.Join(testdata, "systemd.log"), want: AppArmorLogs{ { "apparmor": "ALLOWED", @@ -60,8 +65,8 @@ func TestSelectLogFile(t *testing.T) { }{ { name: "Get audit.log", - path: "../../tests/audit.log", - want: "../../tests/audit.log", + path: filepath.Join(testdata, "audit.log"), + want: filepath.Join(testdata, "audit.log"), }, { name: "Get /var/log/audit/audit.log.1", diff --git a/pkg/logs/logs_test.go b/pkg/logs/logs_test.go index 44dc565f..6332aa11 100644 --- a/pkg/logs/logs_test.go +++ b/pkg/logs/logs_test.go @@ -188,7 +188,7 @@ func TestNewApparmorLogs(t *testing.T) { }{ { name: "dnsmasq", - path: "../../tests/audit.log", + path: filepath.Join(testdata, "audit.log"), want: AppArmorLogs{ { "apparmor": "DENIED", @@ -233,17 +233,17 @@ func TestNewApparmorLogs(t *testing.T) { }, { name: "kmod", - path: "../../tests/audit.log", + path: filepath.Join(testdata, "audit.log"), want: refKmod, }, { name: "man", - path: "../../tests/audit.log", + path: filepath.Join(testdata, "audit.log"), want: refMan, }, { name: "power-profiles-daemon", - path: "../../tests/audit.log", + path: filepath.Join(testdata, "audit.log"), want: refPowerProfiles, }, } diff --git a/tests/audit.log b/tests/testdata/logs/audit.log similarity index 100% rename from tests/audit.log rename to tests/testdata/logs/audit.log diff --git a/tests/systemd.log b/tests/testdata/logs/systemd.log similarity index 100% rename from tests/systemd.log rename to tests/testdata/logs/systemd.log diff --git a/tests/string.aa b/tests/testdata/string.aa similarity index 100% rename from tests/string.aa rename to tests/testdata/string.aa