Skip to content

Commit

Permalink
reporegistry: add logging regression test
Browse files Browse the repository at this point in the history
This commit adds a tiny test to ensure repo logging does not break
again.
  • Loading branch information
mvo5 authored and thozza committed Nov 28, 2024
1 parent efd26c8 commit 5085f9a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pkg/reporegistry/repository_test.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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))
}

0 comments on commit 5085f9a

Please sign in to comment.