Skip to content

Skeleton for system tests #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build_test_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:

- name: Test
run: make tests-ci
env:
RABBITMQ_STREAM_SKIP_RABBIT_START: "for system tests"

e2e_test:
name: E2E Test
Expand Down
71 changes: 71 additions & 0 deletions pkg/stream/stream_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package stream_test

import (
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
"log"
"os"
"os/exec"
"strings"
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -11,3 +18,67 @@ func TestStream(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Stream Suite")
}

const (
SystemTestSkipRabbitStart = "RABBITMQ_STREAM_SKIP_RABBIT_START"
SystemTestEnvVarName = "RABBITMQ_STREAM_RUN_SYSTEM_TEST"
containerName string = "rabbitmq-stream-go-client"
)

var _ = SynchronizedBeforeSuite(func() {
// Just once
logger := log.New(GinkgoWriter, "[SBS] ", log.Ldate|log.Lmsgprefix)
if _, isSet := os.LookupEnv(SystemTestSkipRabbitStart); isSet {
logger.Println("System test variable to skip RabbitMQ start is set. Skipping...")
return
}

dockerRunArgs := strings.Split(
"run --rm --detach --name "+containerName+" "+
"-p 5672:5672 -p 15672:15672 -p 5552:5552 "+
"rabbitmq:3-management",
" ")
cmd := exec.Command("docker", dockerRunArgs...)
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())
session.Wait()

Eventually(func() *gbytes.Buffer {
cmd := exec.Command("docker", "exec", containerName, "epmd", "-names")
bufErr := gbytes.NewBuffer()
session, _ := gexec.Start(cmd, bufErr, bufErr)
session.Wait()
return bufErr
}).WithPolling(time.Second).WithTimeout(time.Second*10).
Should(gbytes.Say("rabbit"), "expected epmd to report rabbit app as running")

awaitStartArgs := strings.Split("exec --user rabbitmq -i "+containerName+" rabbitmqctl await_startup", " ")
awaitCmd := exec.Command("docker", awaitStartArgs...)
awaitSession, err := gexec.Start(awaitCmd, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())
awaitSession.Wait(time.Second * 10)

enablePluginArgs := strings.Split("exec --user rabbitmq -i "+containerName+" rabbitmq-plugins enable rabbitmq_stream", " ")
enablePluginCmd := exec.Command("docker", enablePluginArgs...)
enablePluginSession, err := gexec.Start(enablePluginCmd, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())
enablePluginSession.Wait(time.Second * 10)
}, func() {
// All processes
})

var _ = SynchronizedAfterSuite(func() {
// all processes
}, func() {
// Just once
logger := log.New(GinkgoWriter, "[SAS] ", log.Lmsgprefix|log.Ldate)
if _, isSet := os.LookupEnv("RABBITMQ_STREAM_KEEP_CONTAINER"); isSet {
logger.Println("Keep container env variable set. RabbitMQ container won't be stopped")
return
}
stopArgs := strings.Split("stop "+containerName, " ")
stopCmd := exec.Command("docker", stopArgs...)
session, err := gexec.Start(stopCmd, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())
session.Wait(time.Second * 15)
})
3 changes: 3 additions & 0 deletions pkg/stream/system_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//go:build rabbitmq.stream.system_test

package stream_test