mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-15 18:57:01 +00:00
envs in if: - take 2 (#412)
* Test more if env variants * The correct negation syntax is != * Make the Interpolate function support negated booleans from envs * Move assert := a.New(t) into t.Run This uncovered that some of the test premisses was wrong and the Eval Bool function also had flaws * Remove a stray logrus import
This commit is contained in:
parent
88978fc12b
commit
d752f1e2b9
4 changed files with 106 additions and 32 deletions
|
@ -1,6 +1,7 @@
|
|||
package runner
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/nektos/act/pkg/model"
|
||||
a "github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
@ -10,7 +11,6 @@ import (
|
|||
|
||||
func TestRunContext_EvalBool(t *testing.T) {
|
||||
hook := test.NewGlobal()
|
||||
assert := a.New(t)
|
||||
rc := &RunContext{
|
||||
Config: &Config{
|
||||
Workdir: ".",
|
||||
|
@ -58,29 +58,45 @@ func TestRunContext_EvalBool(t *testing.T) {
|
|||
// The basic ones
|
||||
{"true", true},
|
||||
{"false", false},
|
||||
{"1 !== 0", true},
|
||||
{"1 !== 1", false},
|
||||
{"1 != 0", true},
|
||||
{"1 != 1", false},
|
||||
{"1 == 0", false},
|
||||
{"1 == 1", true},
|
||||
{"1 > 2", false},
|
||||
{"1 < 2", true},
|
||||
{"success()", true},
|
||||
{"failure()", false},
|
||||
{"always()", true},
|
||||
{"failure()", false},
|
||||
// And or
|
||||
{"true && false", false},
|
||||
{"true && 1 < 2", true},
|
||||
{"false || 1 < 2", true},
|
||||
{"false || false", false},
|
||||
// None boolable
|
||||
{"env.SOME_TEXT", true},
|
||||
{"env.UNKNOWN == 'true'", false},
|
||||
{"env.UNKNOWN", false},
|
||||
// Inline expressions
|
||||
{"env.SOME_TEXT", true}, // this is because Boolean('text') is true in Javascript
|
||||
{"env.SOME_TEXT == 'text'", true},
|
||||
{"env.TRUE == 'true'", true},
|
||||
{"env.FALSE == 'true'", false},
|
||||
{"env.TRUE", true},
|
||||
{"env.FALSE", false},
|
||||
{"!env.TRUE", false},
|
||||
{"!env.FALSE", true},
|
||||
{"${{ env.TRUE }}", true},
|
||||
{"${{ env.FALSE }}", false},
|
||||
{"${{ !env.TRUE }}", false},
|
||||
{"${{ !env.FALSE }}", true},
|
||||
{"!env.TRUE && true", false},
|
||||
{"!env.FALSE && true", true},
|
||||
{"!env.TRUE || true", true},
|
||||
{"!env.FALSE || false", true},
|
||||
{"${{env.TRUE == 'true'}}", true},
|
||||
{"${{env.FALSE == 'true'}}", false},
|
||||
{"${{env.FALSE == 'false'}}", true},
|
||||
|
||||
// All together now
|
||||
{"false || env.TRUE == 'true'", true},
|
||||
{"true || env.FALSE == 'true'", true},
|
||||
|
@ -97,10 +113,11 @@ func TestRunContext_EvalBool(t *testing.T) {
|
|||
for _, table := range tables {
|
||||
table := table
|
||||
t.Run(table.in, func(t *testing.T) {
|
||||
assert := a.New(t)
|
||||
defer hook.Reset()
|
||||
b := rc.EvalBool(table.in)
|
||||
|
||||
assert.Equal(table.out, b, table.in)
|
||||
assert.Equal(table.out, b, fmt.Sprintf("Expected %s to be %v, was %v", table.in, table.out, b))
|
||||
assert.Empty(hook.LastEntry(), table.in)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue