Skip to content

Commit f481878

Browse files
committed
Use Expect/EventuallyWithOffset in system_tests/utils
- we should use Expect and Eventually with offset to make sure that the stack trace points to the failing line in system tests instead of the helper function
1 parent 8427c41 commit f481878

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

system_tests/utils.go

+26-26
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ func getConfigFileFromPod(namespace string, cluster *rabbitmqv1beta1.RabbitmqClu
513513
"cat",
514514
path,
515515
)
516-
Expect(err).NotTo(HaveOccurred())
516+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
517517
cfg, err := ini.Load(output)
518518
ExpectWithOffset(1, err).NotTo(HaveOccurred())
519519
return cfg.Section("").KeysHash()
@@ -566,7 +566,7 @@ func waitForRabbitmqNotRunningWithOffset(cluster *rabbitmqv1beta1.RabbitmqCluste
566566
)
567567

568568
if err != nil {
569-
Expect(string(output)).To(ContainSubstring("not found"))
569+
ExpectWithOffset(1, string(output)).To(ContainSubstring("not found"))
570570
}
571571

572572
return string(output)
@@ -591,7 +591,7 @@ func waitForRabbitmqRunningWithOffset(cluster *rabbitmqv1beta1.RabbitmqCluster,
591591
)
592592

593593
if err != nil {
594-
Expect(string(output)).To(ContainSubstring("not found"))
594+
ExpectWithOffset(1, string(output)).To(ContainSubstring("not found"))
595595
}
596596

597597
return string(output)
@@ -626,7 +626,7 @@ func assertHttpReady(hostname, port string) {
626626
rabbitURL := fmt.Sprintf("http://%s:%s", hostname, port)
627627

628628
req, err := http.NewRequest(http.MethodGet, rabbitURL, nil)
629-
Expect(err).ToNot(HaveOccurred())
629+
ExpectWithOffset(1, err).ToNot(HaveOccurred())
630630

631631
return client.Do(req)
632632
}, podCreationTimeout, 5).Should(HaveHTTPStatus(http.StatusOK))
@@ -680,7 +680,7 @@ func k8sSecretExists(secretName, secretNamespace string) (bool, error) {
680680
)
681681

682682
if err != nil {
683-
Expect(string(output)).To(ContainSubstring("not found"))
683+
ExpectWithOffset(1, string(output)).To(ContainSubstring("not found"))
684684
return false, nil
685685
}
686686

@@ -690,9 +690,9 @@ func k8sSecretExists(secretName, secretNamespace string) (bool, error) {
690690
func k8sCreateTLSSecret(secretName, secretNamespace, certPath, keyPath string) error {
691691
// delete secret if it exists
692692
secretExists, err := k8sSecretExists(secretName, secretNamespace)
693-
Expect(err).NotTo(HaveOccurred())
693+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
694694
if secretExists {
695-
Expect(k8sDeleteSecret(secretName, secretNamespace)).To(Succeed())
695+
ExpectWithOffset(1, k8sDeleteSecret(secretName, secretNamespace)).To(Succeed())
696696
}
697697

698698
// create secret
@@ -861,26 +861,26 @@ func publishAndConsumeMQTTMsg(hostname, nodePort, username, password string, ove
861861

862862
handler := func(client mqtt.Client, msg mqtt.Message) {
863863
defer GinkgoRecover()
864-
Expect(msg.Topic()).To(Equal(topic))
865-
Expect(string(msg.Payload())).To(Equal("test message MQTT"))
864+
ExpectWithOffset(1, msg.Topic()).To(Equal(topic))
865+
ExpectWithOffset(1, string(msg.Payload())).To(Equal("test message MQTT"))
866866
msgReceived = true
867867
}
868868

869869
token = c.Subscribe(topic, 0, handler)
870-
Expect(token.Wait()).To(BeTrue())
871-
Expect(token.Error()).ToNot(HaveOccurred())
870+
ExpectWithOffset(1, token.Wait()).To(BeTrue())
871+
ExpectWithOffset(1, token.Error()).ToNot(HaveOccurred())
872872

873873
token = c.Publish(topic, 0, false, "test message MQTT")
874-
Expect(token.Wait()).To(BeTrue())
875-
Expect(token.Error()).ToNot(HaveOccurred())
874+
ExpectWithOffset(1, token.Wait()).To(BeTrue())
875+
ExpectWithOffset(1, token.Error()).ToNot(HaveOccurred())
876876

877-
Eventually(func() bool {
877+
EventuallyWithOffset(1, func() bool {
878878
return msgReceived
879879
}, 5*time.Second).Should(BeTrue())
880880

881881
token = c.Unsubscribe(topic)
882-
Expect(token.Wait()).To(BeTrue())
883-
Expect(token.Error()).ToNot(HaveOccurred())
882+
ExpectWithOffset(1, token.Wait()).To(BeTrue())
883+
ExpectWithOffset(1, token.Error()).ToNot(HaveOccurred())
884884

885885
c.Disconnect(250)
886886
}
@@ -892,7 +892,7 @@ func publishAndConsumeSTOMPMsg(hostname, stompNodePort, username, password strin
892892
// Create a secure tls.Conn and pass to stomp.Connect, otherwise use Stomp.Dial
893893
if tlsConfig != nil {
894894
secureConn, err := tls.Dial("tcp", fmt.Sprintf("%s:%s", hostname, stompNodePort), tlsConfig)
895-
Expect(err).NotTo(HaveOccurred())
895+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
896896
defer secureConn.Close()
897897

898898
for retry := 0; retry < 5; retry++ {
@@ -927,26 +927,26 @@ func publishAndConsumeSTOMPMsg(hostname, stompNodePort, username, password strin
927927
}
928928
}
929929

930-
Expect(err).ToNot(HaveOccurred())
930+
ExpectWithOffset(1, err).ToNot(HaveOccurred())
931931

932932
queue := "/queue/system-tests-stomp"
933933
sub, err := conn.Subscribe(queue, stomp.AckAuto)
934-
Expect(err).ToNot(HaveOccurred())
934+
ExpectWithOffset(1, err).ToNot(HaveOccurred())
935935

936936
msgReceived := false
937937
go func() {
938938
defer GinkgoRecover()
939939
var msg *stomp.Message
940-
Eventually(sub.C, 5*time.Second).Should(Receive(&msg))
941-
Expect(msg.Err).ToNot(HaveOccurred())
942-
Expect(string(msg.Body)).To(Equal("test message STOMP"))
940+
EventuallyWithOffset(1, sub.C, 5*time.Second).Should(Receive(&msg))
941+
ExpectWithOffset(1, msg.Err).ToNot(HaveOccurred())
942+
ExpectWithOffset(1, string(msg.Body)).To(Equal("test message STOMP"))
943943
msgReceived = true
944944
}()
945945

946-
Expect(conn.Send(queue, "text/plain", []byte("test message STOMP"), nil)).To(Succeed())
947-
Eventually(func() bool {
946+
ExpectWithOffset(1, conn.Send(queue, "text/plain", []byte("test message STOMP"), nil)).To(Succeed())
947+
EventuallyWithOffset(1, func() bool {
948948
return msgReceived
949949
}, 5*time.Second).Should(BeTrue())
950-
Expect(sub.Unsubscribe()).To(Succeed())
951-
Expect(conn.Disconnect()).To(Succeed())
950+
ExpectWithOffset(1, sub.Unsubscribe()).To(Succeed())
951+
ExpectWithOffset(1, conn.Disconnect()).To(Succeed())
952952
}

0 commit comments

Comments
 (0)