Skip to content

Commit

Permalink
feat: create scylla resource (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
cisse21 committed Jul 30, 2024
1 parent b7e92b3 commit 461d676
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
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)
}

0 comments on commit 461d676

Please sign in to comment.