build: refractor internal tools.

This commit is contained in:
Alexandre Pujol 2024-03-10 19:07:55 +00:00
parent df21886965
commit b0d52d68f4
Failed to generate hash of commit
3 changed files with 29 additions and 5 deletions

View file

@ -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)

View file

@ -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

View file

@ -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)
}
})
}
}