From 5085f9af73f7e4f528119ac9275ce4d825ab7c96 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 27 Nov 2024 15:52:37 +0100 Subject: [PATCH] reporegistry: add logging regression test This commit adds a tiny test to ensure repo logging does not break again. --- pkg/reporegistry/repository_test.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/reporegistry/repository_test.go b/pkg/reporegistry/repository_test.go index ad24e9c9d6..0bcf75f63f 100644 --- a/pkg/reporegistry/repository_test.go +++ b/pkg/reporegistry/repository_test.go @@ -1,14 +1,20 @@ package reporegistry import ( + "fmt" "path/filepath" "reflect" + "slices" "testing" + "github.com/sirupsen/logrus" + logrusTest "github.com/sirupsen/logrus/hooks/test" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/osbuild/images/internal/common" "github.com/osbuild/images/pkg/distro/test_distro" "github.com/osbuild/images/pkg/rpmmd" - "github.com/stretchr/testify/assert" ) func getConfPaths(t *testing.T) []string { @@ -295,3 +301,16 @@ func Test_LoadAllRepositories(t *testing.T) { }) } } + +func TestLoadRepositoriesLogging(t *testing.T) { + _, logHook := logrusTest.NewNullLogger() + logrus.AddHook(logHook) + + confPaths := getConfPaths(t) + _, err := LoadAllRepositories(confPaths) + require.NoError(t, err) + needle := "Loaded repository configuration file: rhel-8.10.json" + assert.True(t, slices.ContainsFunc(logHook.AllEntries(), func(entry *logrus.Entry) bool { + return needle == entry.Message + }), fmt.Sprintf("%q not found in look entries %+v (last: %q)", needle, logHook.AllEntries(), logHook.LastEntry().Message)) +}