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

Allow custom hooks for ClNode in e2e tests #11745

Merged
merged 3 commits into from
Jan 12, 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
44 changes: 28 additions & 16 deletions integration-tests/docker/test_env/cl_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ type ClNode struct {
PostgresDb *test_env.PostgresDb `json:"postgresDb"`
UserEmail string `json:"userEmail"`
UserPassword string `json:"userPassword"`
AlwaysPullImage bool
AlwaysPullImage bool `json:"-"`
PostStartsHooks []tc.ContainerHook `json:"-"`
PostStopsHooks []tc.ContainerHook `json:"-"`
PreTerminatesHooks []tc.ContainerHook `json:"-"`
t *testing.T
l zerolog.Logger
ls *logstream.LogStream
Expand Down Expand Up @@ -140,12 +143,32 @@ func NewClNode(networks []string, imageName, imageVersion string, nodeConfig *ch
PostgresDb: pgDb,
l: log.Logger,
}
n.SetDefaultHooks()
for _, opt := range opts {
opt(n)
}
return n, nil
}

func (n *ClNode) SetDefaultHooks() {
n.PostStartsHooks = []tc.ContainerHook{
func(ctx context.Context, c tc.Container) error {
if n.ls != nil {
return n.ls.ConnectContainer(ctx, c, "cl-node")
}
return nil
},
}
n.PostStopsHooks = []tc.ContainerHook{
func(ctx context.Context, c tc.Container) error {
if n.ls != nil {
return n.ls.DisconnectContainer(c)
}
return nil
},
}
}

func (n *ClNode) SetTestLogger(t *testing.T) {
n.l = logging.GetTestLogger(t)
n.t = t
Expand Down Expand Up @@ -475,22 +498,11 @@ func (n *ClNode) getContainerRequest(secrets string) (
},
},
LifecycleHooks: []tc.ContainerLifecycleHooks{
{PostStarts: []tc.ContainerHook{
func(ctx context.Context, c tc.Container) error {
if n.ls != nil {
return n.ls.ConnectContainer(ctx, c, "cl-node")
}
return nil
},
{
PostStarts: n.PostStartsHooks,
PostStops: n.PostStopsHooks,
PreTerminates: n.PreTerminatesHooks,
},
PostStops: []tc.ContainerHook{
func(ctx context.Context, c tc.Container) error {
if n.ls != nil {
return n.ls.DisconnectContainer(c)
}
return nil
},
}},
},
}, nil
}
Loading