Skip to content

Commit e6e9a7e

Browse files
committed
Simplify tests
1 parent 371f231 commit e6e9a7e

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

system_tests/system_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ var _ = Describe("Operator", func() {
6767

6868
It("works", func() {
6969
By("publishing and consuming a message", func() {
70-
response, err := alivenessTest(hostname, port, username, password)
71-
Expect(err).NotTo(HaveOccurred())
70+
response := alivenessTest(hostname, port, username, password)
7271
Expect(response.Status).To(Equal("ok"))
7372
})
7473

@@ -378,8 +377,7 @@ CONSOLE_LOG=new`
378377
Expect(err).NotTo(HaveOccurred())
379378
assertHttpReady(hostname, port)
380379

381-
response, err := alivenessTest(hostname, port, username, password)
382-
Expect(err).NotTo(HaveOccurred())
380+
response := alivenessTest(hostname, port, username, password)
383381
Expect(response.Status).To(Equal("ok"))
384382

385383
// test https://github.com/rabbitmq/cluster-operator/issues/662 is fixed
@@ -472,8 +470,7 @@ CONSOLE_LOG=new`
472470

473471
By("connecting to management API over TLS", func() {
474472
managementTLSNodePort := rabbitmqNodePort(ctx, clientSet, cluster, "management-tls")
475-
err := connectHTTPS(username, password, hostname, managementTLSNodePort, caFilePath)
476-
Expect(err).NotTo(HaveOccurred())
473+
Expect(connectHTTPS(username, password, hostname, managementTLSNodePort, caFilePath)).To(Succeed())
477474
})
478475

479476
By("talking MQTTS", func() {

system_tests/utils.go

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import (
5757
. "github.com/onsi/gomega"
5858
)
5959

60-
const podCreationTimeout = 600 * time.Second
60+
const podCreationTimeout = 10 * time.Minute
6161

6262
type featureFlag struct {
6363
Name string
@@ -363,40 +363,26 @@ func getMessageFromQueueAMQPS(username, password, hostname, amqpsPort, caFilePat
363363
return "", nil
364364
}
365365

366-
func alivenessTest(rabbitmqHostName, rabbitmqPort, rabbitmqUsername, rabbitmqPassword string) (*HealthcheckResponse, error) {
366+
func alivenessTest(rabbitmqHostName, rabbitmqPort, rabbitmqUsername, rabbitmqPassword string) *HealthcheckResponse {
367367
client := &http.Client{Timeout: 10 * time.Second}
368368
url := fmt.Sprintf("http://%s:%s/api/aliveness-test/%%2F", rabbitmqHostName, rabbitmqPort)
369369

370-
req, _ := http.NewRequest(http.MethodGet, url, nil)
370+
req, err := http.NewRequest(http.MethodGet, url, nil)
371+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
371372
req.SetBasicAuth(rabbitmqUsername, rabbitmqPassword)
372373

373374
resp, err := client.Do(req)
374-
if err != nil {
375-
fmt.Printf("Failed to run cluster aliveness test: %+v \n", err)
376-
return nil, fmt.Errorf("failed aliveness check: %v with api endpoint: %s", err, url)
377-
}
378-
379-
if resp.StatusCode != http.StatusOK {
380-
fmt.Printf("Cluster aliveness test failed. Status: %s \n", resp.Status)
381-
errMessage := fmt.Sprintf("Response code '%d' != '%d'", resp.StatusCode, http.StatusOK)
382-
return nil, fmt.Errorf("failed aliveness check: %v with api endpoint: %s, error msg: %s", err, url, errMessage)
383-
}
375+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
376+
Expect(resp).To(HaveHTTPStatus(http.StatusOK))
384377

385378
defer resp.Body.Close()
386379
b, err := ioutil.ReadAll(resp.Body)
387-
if err != nil {
388-
fmt.Printf("Failed to read cluster aliveness test: %s \n", err)
389-
return nil, fmt.Errorf("failed aliveness check: %v with api endpoint: %s", err, url)
390-
}
380+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
391381

392382
healthcheckResponse := &HealthcheckResponse{}
393-
err = json.Unmarshal(b, healthcheckResponse)
394-
if err != nil {
395-
fmt.Printf("Failed to umarshal cluster aliveness test result: %s \n", err)
396-
return nil, err
397-
}
383+
ExpectWithOffset(1, json.Unmarshal(b, healthcheckResponse)).To(Succeed())
398384

399-
return healthcheckResponse, nil
385+
return healthcheckResponse
400386
}
401387

402388
type HealthcheckResponse struct {

0 commit comments

Comments
 (0)