-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |