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

chore: add support for WithEnv and WithRepository for transformer resource #673

Merged
merged 1 commit into from
Oct 17, 2024
Merged
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
26 changes: 20 additions & 6 deletions testhelper/docker/resource/transformer/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type Resource struct {
TransformerURL string
}

type Option func(*config)

type config struct {
repository string
tag string
Expand Down Expand Up @@ -55,7 +57,7 @@ func (c *config) setBackendConfigURL(url string) {
// return event;
// }`,
// })
func WithUserTransformations(transformations map[string]string, cleaner resource.Cleaner) func(*config) {
func WithUserTransformations(transformations map[string]string, cleaner resource.Cleaner) Option {
return func(conf *config) {
backendConfigSvc := newTestBackendConfigServer(transformations)

Expand All @@ -69,33 +71,45 @@ func WithUserTransformations(transformations map[string]string, cleaner resource

// WithConnectionToHostEnabled lets transformer container connect with the host machine
// i.e. transformer container will be able to access localhost of the host machine
func WithConnectionToHostEnabled() func(*config) {
func WithConnectionToHostEnabled() Option {
return func(conf *config) {
conf.extraHosts = append(conf.extraHosts, "host.docker.internal:host-gateway")
}
}

// WithConfigBackendURL lets transformer use custom backend config server for transformations
// WithConfigBackendURL should not be used with WithUserTransformations option
func WithConfigBackendURL(url string) func(*config) {
func WithConfigBackendURL(url string) Option {
return func(conf *config) {
conf.setBackendConfigURL(dockertesthelper.ToInternalDockerHost(url))
}
}

func WithDockerImageTag(tag string) func(*config) {
func WithDockerImageTag(tag string) Option {
return func(conf *config) {
conf.tag = tag
}
}

func WithDockerNetwork(network *docker.Network) func(*config) {
func WithDockerNetwork(network *docker.Network) Option {
return func(conf *config) {
conf.network = network
}
}

func Setup(pool *dockertest.Pool, d resource.Cleaner, opts ...func(conf *config)) (*Resource, error) {
func WithEnv(env string) Option {
return func(conf *config) {
conf.envs = append(conf.envs, env)
}
}

func WithRepository(repository string) Option {
return func(conf *config) {
conf.repository = repository
}
}

func Setup(pool *dockertest.Pool, d resource.Cleaner, opts ...Option) (*Resource, error) {
// Set Rudder Transformer
// pulls an image first to make sure we don't have an old cached version locally,
// then it creates a container based on it and runs it
Expand Down
Loading