diff --git a/controllers/activemqartemis_controller2_test.go b/controllers/activemqartemis_controller2_test.go index aa630564f..0c036163a 100644 --- a/controllers/activemqartemis_controller2_test.go +++ b/controllers/activemqartemis_controller2_test.go @@ -488,7 +488,7 @@ var _ = Describe("artemis controller 2", func() { }, timeout, interval).Should(Succeed()) By("finding no Updating v1.Route ") - matches, err := FindAllFromCapturedLog(`Updating \*v1.Route`) + matches, err := FindAllInCapturingLog(`Updating \*v1.Route`) Expect(err).To(BeNil()) Expect(len(matches)).To(Equal(0)) diff --git a/controllers/activemqartemis_controller_test.go b/controllers/activemqartemis_controller_test.go index e88dc82a1..2fb445958 100644 --- a/controllers/activemqartemis_controller_test.go +++ b/controllers/activemqartemis_controller_test.go @@ -1350,11 +1350,11 @@ var _ = Describe("artemis controller", func() { g.Expect(newVarFound).To(BeTrue()) }, timeout, interval).Should(Succeed()) - hasMatch, matchErr := MatchCapturedLog("Failed to create new \\*v1\\.Secret") + hasMatch, matchErr := MatchInCapturingLog("Failed to create new \\*v1\\.Secret") Expect(matchErr).To(BeNil()) Expect(hasMatch).To(BeFalse()) - hasMatch, matchErr = MatchCapturedLog("The secret " + secret.Name + " is ignored because its onwer references doesn't include ActiveMQArtemis/" + brokerCr.Name) + hasMatch, matchErr = MatchInCapturingLog("The secret " + secret.Name + " is ignored because its onwer references doesn't include ActiveMQArtemis/" + brokerCr.Name) Expect(matchErr).To(BeNil()) Expect(hasMatch).To(BeTrue()) @@ -3241,7 +3241,7 @@ var _ = Describe("artemis controller", func() { g.Expect(meta.IsStatusConditionTrue(deployedCrd.Status.Conditions, brokerv1beta1.ReadyConditionType)).Should(BeTrue()) }, existingClusterTimeout, existingClusterInterval).Should(Succeed()) - unequalEntries, _ := FindAllFromCapturedLog("Unequal") + unequalEntries, _ := FindAllInCapturingLog("Unequal") Expect(len(unequalEntries)).Should(BeNumerically("==", 0)) Expect(k8sClient.Delete(ctx, deployedCrd)).Should(Succeed()) @@ -8062,7 +8062,7 @@ var _ = Describe("artemis controller", func() { g.Expect(len(createdCrd.Status.PodStatus.Stopped)).Should(BeEquivalentTo(1)) }, timeout, interval).Should(Succeed()) - Expect(MatchCapturedLog("Failed to create new \\*v1.Secret")).Should(BeFalse()) + Expect(MatchInCapturingLog("Failed to create new \\*v1.Secret")).Should(BeFalse()) // cleanup k8sClient.Delete(ctx, &crd) diff --git a/controllers/activemqartemissecurity_controller_test.go b/controllers/activemqartemissecurity_controller_test.go index b5db9ac74..4b7295ae4 100644 --- a/controllers/activemqartemissecurity_controller_test.go +++ b/controllers/activemqartemissecurity_controller_test.go @@ -171,13 +171,13 @@ var _ = Describe("security controller", func() { By("checking the log") Eventually(func(g Gomega) { - isMatch, err := MatchPattern(TestLogWrapper.unbufferedWriter.String(), "resource successfully reconciled") + isMatch, err := MatchInCapturingLog("resource successfully reconciled") g.Expect(err).To(BeNil()) g.Expect(isMatch).To(BeTrue()) }, timeout, interval).Should(Succeed()) - hasMatch, matchErr := MatchPattern(TestLogWrapper.unbufferedWriter.String(), okDefaultPwd) + hasMatch, matchErr := MatchInCapturingLog(okDefaultPwd) Expect(matchErr).To(BeNil()) - Expect(hasMatch).To(BeFalse(), TestLogWrapper.unbufferedWriter.String()) + Expect(hasMatch).To(BeFalse()) CleanResource(createdBrokerCr, createdBrokerCr.Name, defaultNamespace) CleanResource(createdSecurityCr, createdSecurityCr.Name, defaultNamespace) diff --git a/controllers/common_util_test.go b/controllers/common_util_test.go index b0a62ed9e..b95dc4b6f 100644 --- a/controllers/common_util_test.go +++ b/controllers/common_util_test.go @@ -32,7 +32,6 @@ import ( "os" "os/exec" "path" - "regexp" "strconv" "strings" "time" @@ -81,32 +80,6 @@ func GetHelmCmd() string { return "helm" } -type TestLogWriter struct { - unbufferedWriter bytes.Buffer -} - -func (w *TestLogWriter) Write(p []byte) (n int, err error) { - num, err := w.unbufferedWriter.Write(p) - if err != nil { - return num, err - } - return GinkgoWriter.Write(p) -} - -func (w *TestLogWriter) StartLogging() { - w.unbufferedWriter = *bytes.NewBuffer(nil) -} - -func (w *TestLogWriter) StopLogging() { - w.unbufferedWriter.Reset() -} - -var TestLogWrapper = TestLogWriter{} - -func MatchPattern(content string, pattern string) (matched bool, err error) { - return regexp.Match(pattern, []byte(content)) -} - func randStringWithPrefix(prefix string) string { rand.Seed(time.Now().UnixNano()) length := 6 diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 2449b83de..7fcc191df 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -138,7 +138,7 @@ var ( } managerChannel chan struct{} - testWriter = common.BufferWriter{} + capturingLogWriter = common.BufferWriter{} artemisGvk = schema.GroupVersionKind{Group: "broker", Version: "v1beta1", Kind: "ActiveMQArtemis"} @@ -769,7 +769,7 @@ func setUpK8sClient() { var _ = BeforeSuite(func() { opts := zap.Options{ Development: true, - DestWriter: &TestLogWrapper, + DestWriter: GinkgoWriter, TimeEncoder: zapcore.ISO8601TimeEncoder, } @@ -779,7 +779,7 @@ var _ = BeforeSuite(func() { GinkgoWriter.TeeTo(os.Stderr) } - GinkgoWriter.TeeTo(testWriter) + GinkgoWriter.TeeTo(&capturingLogWriter) ctx, cancel = context.WithCancel(context.TODO()) @@ -870,25 +870,23 @@ func uninstallCRDs() { } func StartCapturingLog() { - testWriter.Buffer = bytes.NewBuffer(nil) - TestLogWrapper.StartLogging() + capturingLogWriter.Buffer = bytes.NewBuffer(nil) } -func MatchCapturedLog(pattern string) (matched bool, err error) { - return regexp.Match(pattern, TestLogWrapper.unbufferedWriter.Bytes()) +func MatchInCapturingLog(pattern string) (matched bool, err error) { + return regexp.Match(pattern, capturingLogWriter.Buffer.Bytes()) } -func FindAllFromCapturedLog(pattern string) ([]string, error) { +func FindAllInCapturingLog(pattern string) ([]string, error) { re, err := regexp.Compile(pattern) if err == nil { - return re.FindAllString(TestLogWrapper.unbufferedWriter.String(), -1), nil + return re.FindAllString(capturingLogWriter.Buffer.String(), -1), nil } return nil, err } func StopCapturingLog() { - testWriter.Buffer = nil - TestLogWrapper.StopLogging() + capturingLogWriter.Buffer = nil } func BeforeEachSpec() {