mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2025-01-31 07:17:22 +01:00
fix(build): ensure tests work.
This commit is contained in:
parent
b88b8b8c26
commit
cf7ce9603e
7 changed files with 17 additions and 7 deletions
|
@ -6,10 +6,10 @@ package builder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -5,8 +5,9 @@
|
||||||
package builder
|
package builder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"slices"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuilder_Apply(t *testing.T) {
|
func TestBuilder_Apply(t *testing.T) {
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
package builder
|
package builder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"slices"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Enforce struct {
|
type Enforce struct {
|
||||||
|
|
|
@ -26,7 +26,7 @@ var (
|
||||||
SystemdDir *paths.Path = paths.New("systemd")
|
SystemdDir *paths.Path = paths.New("systemd")
|
||||||
|
|
||||||
// DebianDir is the directory where the debian specific files are stored
|
// 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
|
// Either or not overwrite some upstreamed profile
|
||||||
Overwrite = Overwriter{Enabled: false}
|
Overwrite = Overwriter{Enabled: false}
|
||||||
|
|
|
@ -9,11 +9,18 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/arduino/go-paths-helper"
|
||||||
"github.com/roddhjav/apparmor.d/pkg/prebuild/builder"
|
"github.com/roddhjav/apparmor.d/pkg/prebuild/builder"
|
||||||
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
||||||
"github.com/roddhjav/apparmor.d/pkg/prebuild/prepare"
|
"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() {
|
func chdirGitRoot() {
|
||||||
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
|
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
|
||||||
out, err := cmd.Output()
|
out, err := cmd.Output()
|
||||||
|
@ -71,6 +78,7 @@ func Test_PreBuild(t *testing.T) {
|
||||||
chdirGitRoot()
|
chdirGitRoot()
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
setTestBuildDirectories(tt.name)
|
||||||
cfg.Distribution = tt.dist
|
cfg.Distribution = tt.dist
|
||||||
if tt.full {
|
if tt.full {
|
||||||
prepare.Register("fsp")
|
prepare.Register("fsp")
|
||||||
|
|
|
@ -7,11 +7,11 @@ package prepare
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"slices"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/arduino/go-paths-helper"
|
"github.com/arduino/go-paths-helper"
|
||||||
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
func chdirGitRoot() {
|
func chdirGitRoot() {
|
||||||
|
@ -84,6 +84,7 @@ func TestTask_Apply(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
chdirGitRoot()
|
chdirGitRoot()
|
||||||
|
cfg.Root.RemoveAll()
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got, err := tt.task.Apply()
|
got, err := tt.task.Apply()
|
||||||
|
|
|
@ -121,13 +121,13 @@ func TestCopyTo(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "default",
|
name: "default",
|
||||||
src: paths.New("../../apparmor.d/groups/_full/"),
|
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,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "issue-source",
|
name: "issue-source",
|
||||||
src: paths.New("../../apparmor.d/groups/nope/"),
|
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,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue