mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2025-02-21 17:35:50 +01:00
build: refractor internal tools.
This commit is contained in:
parent
df21886965
commit
b0d52d68f4
3 changed files with 29 additions and 5 deletions
|
@ -2,7 +2,7 @@
|
||||||
// Copyright (C) 2023-2024 Alexandre Pujol <alexandre@pujol.io>
|
// Copyright (C) 2023-2024 Alexandre Pujol <alexandre@pujol.io>
|
||||||
// SPDX-License-Identifier: GPL-2.0-only
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
|
||||||
package util
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
|
@ -26,7 +26,7 @@ func toExtrat(name string, subfolders []string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract part of an archive to a destination directory
|
// Extract part of an archive to a destination directory
|
||||||
func ExtratTo(src *paths.Path, dst *paths.Path, subfolders []string) error {
|
func extratTo(src *paths.Path, dst *paths.Path, subfolders []string) error {
|
||||||
gzIn, err := src.Open()
|
gzIn, err := src.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("opening %s: %w", src, err)
|
return fmt.Errorf("opening %s: %w", src, err)
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/arduino/go-paths-helper"
|
"github.com/arduino/go-paths-helper"
|
||||||
"github.com/roddhjav/apparmor.d/pkg/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Tldr struct {
|
type Tldr struct {
|
||||||
|
@ -49,7 +48,7 @@ func (t Tldr) Download() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
pages := []string{"tldr-main/pages/linux", "tldr-main/pages/common"}
|
pages := []string{"tldr-main/pages/linux", "tldr-main/pages/common"}
|
||||||
return util.ExtratTo(gzPath, t.Dir, pages)
|
return extratTo(gzPath, t.Dir, pages)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the tldr pages and return a list of scenarios
|
// Parse the tldr pages and return a list of scenarios
|
||||||
|
|
|
@ -61,7 +61,7 @@ func TestToRegexRepl(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
in []string
|
in []string
|
||||||
want []RegexRepl
|
want RegexReplList
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "",
|
name: "",
|
||||||
|
@ -83,3 +83,28 @@ func TestToRegexRepl(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRegexReplList_Replace(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
rr RegexReplList
|
||||||
|
str string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "default",
|
||||||
|
rr: []RegexRepl{
|
||||||
|
{Regex: regexp.MustCompile(`^/foo`), Repl: "/bar"},
|
||||||
|
},
|
||||||
|
str: "/foo",
|
||||||
|
want: "/bar",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := tt.rr.Replace(tt.str); got != tt.want {
|
||||||
|
t.Errorf("RegexReplList.Replace() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue