Skip to content

Commit

Permalink
Allow custom hooks for ClNode in e2e tests (#11745)
Browse files Browse the repository at this point in the history
* Allow custom hooks for ClNode in e2e tests

* Fix for json.Marshall
  • Loading branch information
lukaszcl committed Jan 12, 2024
1 parent a69a78d commit 45bf1fd
Showing 1 changed file with 28 additions and 16 deletions.
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
}

0 comments on commit 45bf1fd

Please sign in to comment.