From cf7ce9603e3f88d4ce3e03d6b594fd365d9ab778 Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Wed, 27 Mar 2024 16:26:01 +0000 Subject: [PATCH] fix(build): ensure tests work. --- pkg/prebuild/builder/complain.go | 2 +- pkg/prebuild/builder/core_test.go | 3 ++- pkg/prebuild/builder/enforce.go | 2 +- pkg/prebuild/cfg/directories.go | 2 +- pkg/prebuild/prebuild_test.go | 8 ++++++++ pkg/prebuild/prepare/core_test.go | 3 ++- pkg/util/tools_test.go | 4 ++-- 7 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pkg/prebuild/builder/complain.go b/pkg/prebuild/builder/complain.go index 3970e6df..3dc04166 100644 --- a/pkg/prebuild/builder/complain.go +++ b/pkg/prebuild/builder/complain.go @@ -6,10 +6,10 @@ package builder import ( "regexp" - "slices" "strings" "github.com/roddhjav/apparmor.d/pkg/prebuild/cfg" + "golang.org/x/exp/slices" ) var ( diff --git a/pkg/prebuild/builder/core_test.go b/pkg/prebuild/builder/core_test.go index b0c59e77..3b620e6b 100644 --- a/pkg/prebuild/builder/core_test.go +++ b/pkg/prebuild/builder/core_test.go @@ -5,8 +5,9 @@ package builder import ( - "slices" "testing" + + "golang.org/x/exp/slices" ) func TestBuilder_Apply(t *testing.T) { diff --git a/pkg/prebuild/builder/enforce.go b/pkg/prebuild/builder/enforce.go index a3bd2c1d..8c4aaccf 100644 --- a/pkg/prebuild/builder/enforce.go +++ b/pkg/prebuild/builder/enforce.go @@ -5,10 +5,10 @@ package builder import ( - "slices" "strings" "github.com/roddhjav/apparmor.d/pkg/prebuild/cfg" + "golang.org/x/exp/slices" ) type Enforce struct { diff --git a/pkg/prebuild/cfg/directories.go b/pkg/prebuild/cfg/directories.go index d8bdf23a..7d482c4b 100644 --- a/pkg/prebuild/cfg/directories.go +++ b/pkg/prebuild/cfg/directories.go @@ -26,7 +26,7 @@ var ( SystemdDir *paths.Path = paths.New("systemd") // DebianDir is the directory where the debian specific files are stored - DebianDir *paths.Path = DistDir.Join("debian") + DebianDir *paths.Path = paths.New("debian") // Either or not overwrite some upstreamed profile Overwrite = Overwriter{Enabled: false} diff --git a/pkg/prebuild/prebuild_test.go b/pkg/prebuild/prebuild_test.go index 083dca35..48f7cda7 100644 --- a/pkg/prebuild/prebuild_test.go +++ b/pkg/prebuild/prebuild_test.go @@ -9,11 +9,18 @@ import ( "os/exec" "testing" + "github.com/arduino/go-paths-helper" "github.com/roddhjav/apparmor.d/pkg/prebuild/builder" "github.com/roddhjav/apparmor.d/pkg/prebuild/cfg" "github.com/roddhjav/apparmor.d/pkg/prebuild/prepare" ) +func setTestBuildDirectories(name string) { + testRoot := paths.New("/tmp/tests") + cfg.Root = testRoot.Join(name) + cfg.RootApparmord = cfg.Root.Join("apparmor.d") +} + func chdirGitRoot() { cmd := exec.Command("git", "rev-parse", "--show-toplevel") out, err := cmd.Output() @@ -71,6 +78,7 @@ func Test_PreBuild(t *testing.T) { chdirGitRoot() for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + setTestBuildDirectories(tt.name) cfg.Distribution = tt.dist if tt.full { prepare.Register("fsp") diff --git a/pkg/prebuild/prepare/core_test.go b/pkg/prebuild/prepare/core_test.go index 75e5c348..77ca0f28 100644 --- a/pkg/prebuild/prepare/core_test.go +++ b/pkg/prebuild/prepare/core_test.go @@ -7,11 +7,11 @@ package prepare import ( "os" "os/exec" - "slices" "testing" "github.com/arduino/go-paths-helper" "github.com/roddhjav/apparmor.d/pkg/prebuild/cfg" + "golang.org/x/exp/slices" ) func chdirGitRoot() { @@ -84,6 +84,7 @@ func TestTask_Apply(t *testing.T) { }, } chdirGitRoot() + cfg.Root.RemoveAll() for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := tt.task.Apply() diff --git a/pkg/util/tools_test.go b/pkg/util/tools_test.go index dce3c461..a977f91a 100644 --- a/pkg/util/tools_test.go +++ b/pkg/util/tools_test.go @@ -121,13 +121,13 @@ func TestCopyTo(t *testing.T) { { name: "default", src: paths.New("../../apparmor.d/groups/_full/"), - dst: paths.New("../../.build/apparmor.d/groups/_full/"), + dst: paths.New("/tmp/test/apparmor.d/groups/_full/"), wantErr: false, }, { name: "issue-source", src: paths.New("../../apparmor.d/groups/nope/"), - dst: paths.New("../../.build/apparmor.d/groups/_full/"), + dst: paths.New("/tmp/test/apparmor.d/groups/_full/"), wantErr: true, }, {