Skip to content

Commit 1dd25fb

Browse files
vcalasanshbot-harness
authored andcommitted
fix: [PIPE-28910]: Fix for local runner on Windows - Convert pipelineConfig volume host paths to Windows format (#389)
* 60739a Add UT * 188094 Make local runner work on Windows
1 parent abe5b74 commit 1dd25fb

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

engine/engine.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,20 @@ func runHelper(cfg *spec.PipelineConfig, step *spec.Step) error {
235235
return err
236236
}
237237

238+
// If we are running on Windows, convert
239+
// the volume paths to windows paths
238240
for _, vol := range step.Volumes {
239241
vol.Path = pathConverter(vol.Path)
240242
}
243+
244+
for _, vol := range cfg.Volumes {
245+
if vol == nil || vol.HostPath == nil {
246+
continue
247+
}
248+
path := vol.HostPath.Path
249+
vol.HostPath.Path = pathConverter(path)
250+
}
251+
241252
return nil
242253
}
243254

engine/engine_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package engine
22

33
import (
44
"bytes"
5+
"runtime"
56
"strings"
67
"testing"
78

89
"github.com/harness/lite-engine/engine/spec"
10+
"github.com/stretchr/testify/assert"
911
)
1012

1113
func TestRun(t *testing.T) {
@@ -55,3 +57,43 @@ func TestRun(t *testing.T) {
5557
})
5658
}
5759
}
60+
61+
func TestRunHelper(t *testing.T) {
62+
cfg := &spec.PipelineConfig{
63+
Envs: map[string]string{
64+
"GLOBAL_KEY": "global_value",
65+
},
66+
Volumes: []*spec.Volume{
67+
{
68+
HostPath: &spec.VolumeHostPath{Path: "/some/path"},
69+
},
70+
},
71+
}
72+
73+
step := &spec.Step{
74+
Envs: map[string]string{
75+
"STEP_KEY": "step_value",
76+
},
77+
WorkingDir: "/work/dir",
78+
Volumes: []*spec.VolumeMount{
79+
{Name: "myMount", Path: "/mount/path"},
80+
},
81+
Files: []*spec.File{},
82+
}
83+
84+
// Act
85+
err := runHelper(cfg, step)
86+
87+
// Assert
88+
assert.NoError(t, err)
89+
// Env vars should be merged
90+
assert.Equal(t, "global_value", step.Envs["GLOBAL_KEY"])
91+
assert.Equal(t, "step_value", step.Envs["STEP_KEY"])
92+
if runtime.GOOS == "windows" {
93+
assert.Equal(t, "c:\\some\\path", cfg.Volumes[0].HostPath.Path)
94+
assert.Equal(t, "c:\\mount\\path", step.Volumes[0].Path)
95+
} else {
96+
assert.Equal(t, "/some/path", cfg.Volumes[0].HostPath.Path)
97+
assert.Equal(t, "/mount/path", step.Volumes[0].Path)
98+
}
99+
}

0 commit comments

Comments
 (0)