diff --git a/pkg/runner/operations/command/command.go b/pkg/runner/operations/command/command.go index 1dacdba6d..40807975b 100644 --- a/pkg/runner/operations/command/command.go +++ b/pkg/runner/operations/command/command.go @@ -16,12 +16,14 @@ import ( type operation struct { command v1alpha1.Command + basePath string namespace string } -func New(command v1alpha1.Command, namespace string) operations.Operation { +func New(command v1alpha1.Command, basePath string, namespace string) operations.Operation { return &operation{ command: command, + basePath: basePath, namespace: namespace, } } @@ -53,6 +55,7 @@ func (o *operation) Exec(ctx context.Context) (_err error) { // TODO // env = append(env, fmt.Sprintf("KUBECONFIG=%s/bin/:%s", cwd, os.Getenv("PATH"))) cmd.Env = env + cmd.Dir = o.basePath logger.Log(logging.Command, logging.RunStatus, color.BoldFgCyan) cmd.Stdout = &output.Stdout cmd.Stderr = &output.Stderr diff --git a/pkg/runner/operations/command/command_test.go b/pkg/runner/operations/command/command_test.go index 9c763fb45..a4e9eb338 100644 --- a/pkg/runner/operations/command/command_test.go +++ b/pkg/runner/operations/command/command_test.go @@ -14,6 +14,7 @@ func Test_operationCommand(t *testing.T) { tests := []struct { name string command v1alpha1.Command + basePath string namespace string wantErr bool }{{ @@ -42,12 +43,23 @@ func Test_operationCommand(t *testing.T) { }, namespace: "test-namespace", wantErr: false, + }, { + name: "Test base path", + command: v1alpha1.Command{ + Entrypoint: "cat", + Args: []string{"operation.go"}, + SkipLogOutput: true, + }, + basePath: "..", + namespace: "test-namespace", + wantErr: false, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ctx := logging.IntoContext(context.TODO(), &tlogging.FakeLogger{}) operation := operation{ command: tt.command, + basePath: tt.basePath, namespace: tt.namespace, } err := operation.Exec(ctx) diff --git a/pkg/runner/operations/script/script.go b/pkg/runner/operations/script/script.go index 540ee5598..977381e59 100644 --- a/pkg/runner/operations/script/script.go +++ b/pkg/runner/operations/script/script.go @@ -16,12 +16,14 @@ import ( type operation struct { script v1alpha1.Script + basePath string namespace string } -func New(script v1alpha1.Script, namespace string) operations.Operation { +func New(script v1alpha1.Script, basePath string, namespace string) operations.Operation { return &operation{ script: script, + basePath: basePath, namespace: namespace, } } @@ -52,6 +54,7 @@ func (o *operation) Exec(ctx context.Context) (_err error) { // TODO // env = append(env, fmt.Sprintf("KUBECONFIG=%s/bin/:%s", cwd, os.Getenv("PATH"))) cmd.Env = env + cmd.Dir = o.basePath logger.Log(logging.Script, logging.RunStatus, color.BoldFgCyan) cmd.Stdout = &output.Stdout cmd.Stderr = &output.Stderr diff --git a/pkg/runner/operations/script/script_test.go b/pkg/runner/operations/script/script_test.go index 0f55ef983..1392b2b50 100644 --- a/pkg/runner/operations/script/script_test.go +++ b/pkg/runner/operations/script/script_test.go @@ -14,6 +14,7 @@ func Test_operationScript(t *testing.T) { tests := []struct { name string script v1alpha1.Script + basePath string namespace string wantErr bool }{{ @@ -40,12 +41,22 @@ func Test_operationScript(t *testing.T) { }, namespace: "test-namespace", wantErr: false, + }, { + name: "Test base path", + script: v1alpha1.Script{ + Content: "cat operation.go", + SkipLogOutput: true, + }, + basePath: "..", + namespace: "test-namespace", + wantErr: false, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ctx := logging.IntoContext(context.TODO(), &tlogging.FakeLogger{}) operation := operation{ script: tt.script, + basePath: tt.basePath, namespace: tt.namespace, } err := operation.Exec(ctx) diff --git a/pkg/runner/processors/step.go b/pkg/runner/processors/step.go index 3736d4c55..453abc9e4 100644 --- a/pkg/runner/processors/step.go +++ b/pkg/runner/processors/step.go @@ -269,7 +269,7 @@ func (p *stepProcessor) assertOperation(ctx context.Context, op v1alpha1.Assert, func (p *stepProcessor) commandOperation(ctx context.Context, exec v1alpha1.Command, to *metav1.Duration) operation { return operation{ timeout: timeout.Get(timeout.DefaultExecTimeout, p.config.Timeouts.Exec, p.test.Spec.Timeouts.Exec, p.step.Spec.Timeouts.Exec, to), - operation: opcommand.New(exec, p.namespacer.GetNamespace()), + operation: opcommand.New(exec, p.test.BasePath, p.namespacer.GetNamespace()), } } @@ -322,7 +322,7 @@ func (p *stepProcessor) errorOperation(ctx context.Context, op v1alpha1.Error, t func (p *stepProcessor) scriptOperation(ctx context.Context, exec v1alpha1.Script, to *metav1.Duration) operation { return operation{ timeout: timeout.Get(timeout.DefaultExecTimeout, p.config.Timeouts.Exec, p.test.Spec.Timeouts.Exec, p.step.Spec.Timeouts.Exec, to), - operation: opscript.New(exec, p.namespacer.GetNamespace()), + operation: opscript.New(exec, p.test.BasePath, p.namespacer.GetNamespace()), } }