fix node unit test (#3190)

This commit is contained in:
Felix Kunde
2026-09-22 15:30:32 +02:00
committed by GitHub
parent 470f4157a4
commit 3a838ceb99
+8 -6
View File
@@ -1,12 +1,13 @@
package controller package controller
import ( import (
"bytes"
"fmt" "fmt"
"strings" "strings"
"testing" "testing"
"time" "time"
logrustest "github.com/sirupsen/logrus/hooks/test" "github.com/sirupsen/logrus"
"github.com/zalando/postgres-operator/v2/pkg/spec" "github.com/zalando/postgres-operator/v2/pkg/spec"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -116,16 +117,17 @@ func TestMoveMasterPodsOffNodeRetriesOnError(t *testing.T) {
// the single retry attempt resolves synchronously without a real sleep. // the single retry attempt resolves synchronously without a real sleep.
controller.opConfig.MasterPodMoveTimeout = &metav1.Duration{Duration: 1 * time.Minute} controller.opConfig.MasterPodMoveTimeout = &metav1.Duration{Duration: 1 * time.Minute}
logger, hook := logrustest.NewNullLogger() var logOutput bytes.Buffer
logger := logrus.New()
logger.SetOutput(&logOutput)
controller.logger = logger.WithField("pkg", "controller") controller.logger = logger.WithField("pkg", "controller")
controller.moveMasterPodsOffNode(makeNode(map[string]string{}, false)) controller.moveMasterPodsOffNode(makeNode(map[string]string{}, false))
lastEntry := hook.LastEntry() if logOutput.Len() == 0 {
if lastEntry == nil {
t.Fatal("expected moveMasterPodsOffNode to log a warning") t.Fatal("expected moveMasterPodsOffNode to log a warning")
} }
if !strings.Contains(lastEntry.Message, "still failing after") { if !strings.Contains(logOutput.String(), "still failing after") {
t.Errorf("expected the retry loop to run out of attempts instead of aborting on the first error, got log message: %q", lastEntry.Message) t.Errorf("expected the retry loop to run out of attempts instead of aborting on the first error, got log output: %q", logOutput.String())
} }
} }