From b0d52d68f49199996a2a62837a5bcbce93d41e5e Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Sun, 10 Mar 2024 19:07:55 +0000 Subject: [PATCH] build: refractor internal tools. --- pkg/{util => integration}/paths.go | 4 ++-- pkg/integration/tldr.go | 3 +-- pkg/util/tools_test.go | 27 ++++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 5 deletions(-) rename pkg/{util => integration}/paths.go (94%) diff --git a/pkg/util/paths.go b/pkg/integration/paths.go similarity index 94% rename from pkg/util/paths.go rename to pkg/integration/paths.go index f22d3713..2d61150a 100644 --- a/pkg/util/paths.go +++ b/pkg/integration/paths.go @@ -2,7 +2,7 @@ // Copyright (C) 2023-2024 Alexandre Pujol // SPDX-License-Identifier: GPL-2.0-only -package util +package integration import ( "archive/tar" @@ -26,7 +26,7 @@ func toExtrat(name string, subfolders []string) bool { } // 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() if err != nil { return fmt.Errorf("opening %s: %w", src, err) diff --git a/pkg/integration/tldr.go b/pkg/integration/tldr.go index 57e538fb..b2f7477d 100644 --- a/pkg/integration/tldr.go +++ b/pkg/integration/tldr.go @@ -11,7 +11,6 @@ import ( "strings" "github.com/arduino/go-paths-helper" - "github.com/roddhjav/apparmor.d/pkg/util" ) type Tldr struct { @@ -49,7 +48,7 @@ func (t Tldr) Download() error { } 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 diff --git a/pkg/util/tools_test.go b/pkg/util/tools_test.go index 8f715c76..9b161cd3 100644 --- a/pkg/util/tools_test.go +++ b/pkg/util/tools_test.go @@ -61,7 +61,7 @@ func TestToRegexRepl(t *testing.T) { tests := []struct { name string in []string - want []RegexRepl + want RegexReplList }{ { 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) + } + }) + } +}