@@ -2,10 +2,12 @@ package engine
2
2
3
3
import (
4
4
"bytes"
5
+ "runtime"
5
6
"strings"
6
7
"testing"
7
8
8
9
"github.com/harness/lite-engine/engine/spec"
10
+ "github.com/stretchr/testify/assert"
9
11
)
10
12
11
13
func TestRun (t * testing.T ) {
@@ -55,3 +57,43 @@ func TestRun(t *testing.T) {
55
57
})
56
58
}
57
59
}
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