Make envs available in if conditionals (#225)

* Ignore .idea

* Add Env to the RunContext vm so we can Evaluate and Interpolate `env.xx`

* Make EvalBool support expressions more in line with the github runner

* Turns out Boolean(value) is what github is doing after all

* Add test for github context as well
This commit is contained in:
Torbjørn Vatn
2020-05-04 21:18:13 +02:00
committed by GitHub
parent 6d6ea7ac04
commit a149cf8ca2
5 changed files with 155 additions and 18 deletions

View File

@@ -4,15 +4,18 @@ import (
"testing"
"github.com/nektos/act/pkg/model"
"github.com/stretchr/testify/assert"
a "github.com/stretchr/testify/assert"
)
func TestEvaluate(t *testing.T) {
assert := assert.New(t)
assert := a.New(t)
rc := &RunContext{
Config: &Config{
Workdir: ".",
},
Env: map[string]string{
"key": "value",
},
Run: &model.Run{
JobID: "job1",
Workflow: &model.Workflow{
@@ -79,6 +82,8 @@ func TestEvaluate(t *testing.T) {
{"runner.os", "Linux", ""},
{"matrix.os", "Linux", ""},
{"matrix.foo", "bar", ""},
{"env.key", "value", ""},
}
for _, table := range tables {
@@ -97,11 +102,14 @@ func TestEvaluate(t *testing.T) {
}
func TestInterpolate(t *testing.T) {
assert := assert.New(t)
assert := a.New(t)
rc := &RunContext{
Config: &Config{
Workdir: ".",
},
Env: map[string]string{
"key": "value",
},
Run: &model.Run{
JobID: "job1",
Workflow: &model.Workflow{
@@ -113,8 +121,20 @@ func TestInterpolate(t *testing.T) {
},
}
ee := rc.NewExpressionEvaluator()
tables := []struct{
in string
out string
}{
{" ${{1}} to ${{2}} ", " 1 to 2 "},
{" ${{ env.key }} ", " value "},
{"${{ env.unknown }}", ""},
}
out := ee.Interpolate(" ${{1}} to ${{2}} ")
assert.Equal(" 1 to 2 ", out)
for _, table := range tables {
table := table
t.Run(table.in, func(t *testing.T) {
out := ee.Interpolate(table.in)
assert.Equal(table.out, out, table.in)
})
}
}