Skip to content

Commit b683924

Browse files
committed
tests: fix e2e hooks tests
1 parent 4cd69ee commit b683924

File tree

16 files changed

+690
-658
lines changed

16 files changed

+690
-658
lines changed

cmd/build.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type BuildCmd struct {
2828
ForceBuild bool
2929
BuildSequential bool
3030
MaxConcurrentBuilds int
31+
32+
Ctx context.Context
3133
}
3234

3335
// NewBuildCmd creates a new devspace build command
@@ -66,8 +68,14 @@ Builds all defined images and pushes them
6668

6769
// Run executes the command logic
6870
func (cmd *BuildCmd) Run(f factory.Factory) error {
71+
if cmd.Ctx == nil {
72+
var cancelFn context.CancelFunc
73+
cmd.Ctx, cancelFn = context.WithCancel(context.Background())
74+
defer cancelFn()
75+
}
76+
6977
configOptions := cmd.ToConfigOptions()
70-
ctx, err := prepare(context.Background(), f, configOptions, cmd.GlobalFlags, true)
78+
ctx, err := prepare(cmd.Ctx, f, configOptions, cmd.GlobalFlags, true)
7179
if err != nil {
7280
return err
7381
}

cmd/deploy.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/loft-sh/devspace/pkg/devspace/deploy"
1616
"github.com/loft-sh/devspace/pkg/devspace/dev"
1717
"github.com/loft-sh/devspace/pkg/devspace/devpod"
18-
"github.com/loft-sh/devspace/pkg/devspace/hook"
1918
fakekube "github.com/loft-sh/devspace/pkg/devspace/kubectl/testing"
2019
"github.com/loft-sh/devspace/pkg/devspace/pipeline"
2120
"github.com/loft-sh/devspace/pkg/devspace/pipeline/types"
@@ -57,6 +56,8 @@ type DeployCmd struct {
5756
Timeout int
5857

5958
log logpkg.Logger
59+
60+
Ctx context.Context
6061
}
6162

6263
// NewDeployCmd creates a new deploy command
@@ -114,8 +115,14 @@ devspace deploy --kube-context=deploy-context
114115

115116
// Run executes the down command logic
116117
func (cmd *DeployCmd) Run(f factory.Factory) error {
118+
if cmd.Ctx == nil {
119+
var cancelFn context.CancelFunc
120+
cmd.Ctx, cancelFn = context.WithCancel(context.Background())
121+
defer cancelFn()
122+
}
123+
117124
configOptions := cmd.ToConfigOptions()
118-
ctx, err := prepare(context.Background(), f, configOptions, cmd.GlobalFlags, false)
125+
ctx, err := prepare(cmd.Ctx, f, configOptions, cmd.GlobalFlags, false)
119126
if err != nil {
120127
return err
121128
}
@@ -254,12 +261,6 @@ func runPipeline(ctx *devspacecontext.Context, f factory.Factory, forceLeader bo
254261
}
255262
ctx = ctx.WithDependencies(dependencies)
256263

257-
// execute plugin hook
258-
err = hook.ExecuteHooks(ctx, nil, "deploy")
259-
if err != nil {
260-
return err
261-
}
262-
263264
// update last used kube context & save generated yaml
264265
err = updateLastKubeContext(ctx)
265266
if err != nil {

cmd/dev.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ Open terminal instead of logs:
136136
// Run executes the command logic
137137
func (cmd *DevCmd) Run(f factory.Factory, args []string) error {
138138
if cmd.Ctx == nil {
139-
cmd.Ctx = context.Background()
139+
var cancelFn context.CancelFunc
140+
cmd.Ctx, cancelFn = context.WithCancel(context.Background())
141+
defer cancelFn()
140142
}
141143

142144
configOptions := cmd.ToConfigOptions()
@@ -152,12 +154,6 @@ func (cmd *DevCmd) Run(f factory.Factory, args []string) error {
152154
}
153155

154156
return runWithHooks(ctx, "devCommand", func() error {
155-
// Execute plugin hook
156-
err = hook.ExecuteHooks(ctx, nil, "dev")
157-
if err != nil {
158-
return err
159-
}
160-
161157
// Build and deploy images
162158
err = cmd.runCommand(ctx, f, configOptions)
163159
if err != nil {

cmd/purge.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type PurgeCmd struct {
2626
Dependency []string
2727

2828
log log.Logger
29+
30+
Ctx context.Context
2931
}
3032

3133
// NewPurgeCmd creates a new purge command
@@ -66,8 +68,14 @@ devspace purge -d my-deployment
6668

6769
// Run executes the purge command logic
6870
func (cmd *PurgeCmd) Run(f factory.Factory) error {
71+
if cmd.Ctx == nil {
72+
var cancelFn context.CancelFunc
73+
cmd.Ctx, cancelFn = context.WithCancel(context.Background())
74+
defer cancelFn()
75+
}
76+
6977
configOptions := cmd.ToConfigOptions()
70-
ctx, err := prepare(context.Background(), f, configOptions, cmd.GlobalFlags, false)
78+
ctx, err := prepare(cmd.Ctx, f, configOptions, cmd.GlobalFlags, false)
7179
if err != nil {
7280
return err
7381
}

cmd/sync.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ type nameConfig struct {
119119

120120
// Run executes the command logic
121121
func (cmd *SyncCmd) Run(f factory.Factory) error {
122+
if cmd.Ctx == nil {
123+
var cancelFn context.CancelFunc
124+
cmd.Ctx, cancelFn = context.WithCancel(context.Background())
125+
defer cancelFn()
126+
}
127+
122128
// Switch working directory
123129
if cmd.GlobalFlags.ConfigPath != "" {
124130
_, err := os.Stat(cmd.GlobalFlags.ConfigPath)
@@ -175,10 +181,6 @@ func (cmd *SyncCmd) Run(f factory.Factory) error {
175181
}
176182
}
177183

178-
if cmd.Ctx == nil {
179-
cmd.Ctx = context.Background()
180-
}
181-
182184
// create the devspace context
183185
ctx := devspacecontext.NewContext(cmd.Ctx, logger).
184186
WithConfig(configInterface).

0 commit comments

Comments
 (0)