Skip to content

Commit

Permalink
chore: add support for withenv for traksformer resource
Browse files Browse the repository at this point in the history
  • Loading branch information
achettyiitr committed Oct 17, 2024
1 parent fa27ba6 commit 08a98c5
Showing 1 changed file with 20 additions and 6 deletions.
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

0 comments on commit 08a98c5

Please sign in to comment.