refactor: use standard logger instead of logrus

This commit is contained in:
Lukas Zapletal 2025-04-29 15:17:22 +02:00 committed by Achilleas Koutsou
parent 48cd004bed
commit 392a04fd12
9 changed files with 152 additions and 29 deletions

View file

@ -2,6 +2,7 @@ package setup
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
@ -10,8 +11,6 @@ import (
"golang.org/x/sys/unix"
"github.com/sirupsen/logrus"
"github.com/osbuild/image-builder-cli/pkg/podmanutil"
"github.com/osbuild/image-builder-cli/pkg/util"
)
@ -136,7 +135,7 @@ func validateCanRunTargetArch(targetArch string) error {
// we could error here but in principle with a working qemu-user
// any arch should work so let's just warn. the common case
// (arm64/amd64) is covered properly
logrus.Warningf("cannot check architecture support for %v: no canary binary found", targetArch)
log.Printf("WARNING: cannot check architecture support for %v: no canary binary found", targetArch)
return nil
}
output, err := exec.Command(canaryCmd).CombinedOutput()

View file

@ -3,12 +3,12 @@ package setup_test
import (
"bytes"
"fmt"
"log"
"os"
"path/filepath"
"runtime"
"testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/osbuild/image-builder-cli/pkg/setup"
@ -23,11 +23,13 @@ func TestValidateCanRunTargetArchTrivial(t *testing.T) {
func TestValidateCanRunTargetArchUnsupportedCanary(t *testing.T) {
var logbuf bytes.Buffer
logrus.SetOutput(&logbuf)
ow := log.Writer()
log.SetOutput(&logbuf)
defer log.SetOutput(ow)
err := setup.ValidateCanRunTargetArch("unsupported-arch")
assert.NoError(t, err)
assert.Contains(t, logbuf.String(), `level=warning msg="cannot check architecture support for unsupported-arch: no canary binary found"`)
assert.Contains(t, logbuf.String(), `cannot check architecture support for unsupported-arch: no canary binary found`)
}
func makeFakeBinary(t *testing.T, binary, content string) {
@ -43,7 +45,9 @@ func makeFakeCanary(t *testing.T, content string) {
func TestValidateCanRunTargetArchHappy(t *testing.T) {
var logbuf bytes.Buffer
logrus.SetOutput(&logbuf)
ow := log.Writer()
log.SetOutput(&logbuf)
defer log.SetOutput(ow)
makeFakeCanary(t, "#!/bin/sh\necho ok")