WIP: unit test done, need further test
This commit is contained in:
+50
-1
@@ -1,9 +1,12 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"gitea.suyono.dev/suyono/wingmate"
|
||||
wminit "gitea.suyono.dev/suyono/wingmate/init"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestServicesV0(t *testing.T) {
|
||||
@@ -77,3 +80,49 @@ func TestTasks_List(t *testing.T) {
|
||||
|
||||
assert.ElementsMatch(t, testNames, tnames)
|
||||
}
|
||||
|
||||
func TestServiceTaskPatchEnv(t *testing.T) {
|
||||
type testEntry struct {
|
||||
name string
|
||||
systemEnv []string
|
||||
serviceEnv []string
|
||||
expected []string
|
||||
}
|
||||
_ = wingmate.NewLog(os.Stderr, wingmate.Caller|wingmate.Time)
|
||||
|
||||
tests := []testEntry{
|
||||
{
|
||||
name: "normal",
|
||||
systemEnv: []string{"PATH=/bin:/usr/bin:/usr/local/bin"},
|
||||
serviceEnv: []string{
|
||||
"SPARK_HOME=/opt/spark",
|
||||
"PATH=$SPARK_HOME/bin:$PATH",
|
||||
},
|
||||
expected: []string{
|
||||
"SPARK_HOME=/opt/spark",
|
||||
"PATH=/opt/spark/bin:/bin:/usr/bin:/usr/local/bin",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "explicit",
|
||||
systemEnv: []string{"PART=hello "},
|
||||
serviceEnv: []string{"GREET=${PART}world"},
|
||||
expected: []string{"PART=hello ", "GREET=hello world"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name+" - service", func(t *testing.T) {
|
||||
st := NewServiceTask(tt.name)
|
||||
st.SetEnv(tt.serviceEnv...)
|
||||
result := st.PatchEnv(tt.systemEnv)
|
||||
assert.ElementsMatch(t, result, tt.expected)
|
||||
})
|
||||
t.Run(tt.name+" - cron", func(t *testing.T) {
|
||||
st := NewCronTask(tt.name)
|
||||
st.SetEnv(tt.serviceEnv...)
|
||||
result := st.PatchEnv(tt.systemEnv)
|
||||
assert.ElementsMatch(t, result, tt.expected)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user