Skip to content
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

feat: create scylla resource #576

Merged
merged 1 commit into from
Jul 30, 2024
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
13 changes: 13 additions & 0 deletions testhelper/docker/resource/scylla/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package scylla

type Option func(*config)

func WithTag(tag string) Option {
return func(c *config) {
c.tag = tag
}
}

type config struct {
tag string
}
66 changes: 66 additions & 0 deletions testhelper/docker/resource/scylla/scylla.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package scylla

import (
"bytes"
"fmt"

"github.com/ory/dockertest/v3"

"github.com/rudderlabs/rudder-go-kit/testhelper/docker/resource"
)

type Resource struct {
URL string
Port string
}

func Setup(pool *dockertest.Pool, d resource.Cleaner, opts ...Option) (*Resource, error) {
c := &config{
tag: "5.4.9",
}
for _, opt := range opts {
opt(c)
}

container, err := pool.RunWithOptions(&dockertest.RunOptions{
Repository: "scylladb/scylla",
Tag: c.tag,
Env: []string{},
ExposedPorts: []string{"9042"},
})
if err != nil {
return nil, err
}

d.Cleanup(func() {
if err := pool.Purge(container); err != nil {
d.Log("Could not purge resource:", err)
}
})

url := fmt.Sprintf("http://localhost:%s", container.GetPort("9042/tcp"))

if err := pool.Retry(func() (err error) {
var w bytes.Buffer
code, err := container.Exec(
[]string{
"sh", "-c", "nodetool statusgossip | grep 'running' || exit 1",
},
dockertest.ExecOptions{StdOut: &w, StdErr: &w},
)
if err != nil {
return err
}
if code != 0 {
return fmt.Errorf("pulsar healthcheck failed")
}
return nil
}); err != nil {
return nil, err
}

return &Resource{
URL: url,
Port: container.GetPort("9042/tcp"),
}, nil
}
17 changes: 17 additions & 0 deletions testhelper/docker/resource/scylla/scylla_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package scylla

import (
"testing"

"github.com/ory/dockertest/v3"
"github.com/stretchr/testify/require"
)

func TestScylla(t *testing.T) {
pool, err := dockertest.NewPool("")
require.NoError(t, err)

scyllaContainer, err := Setup(pool, t)
require.NoError(t, err)
require.NotNil(t, scyllaContainer)
}
Loading