mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-11 17:50:58 +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
|
@ -8,7 +8,6 @@ import (
|
|||
)
|
||||
|
||||
func TestEvaluate(t *testing.T) {
|
||||
assert := a.New(t)
|
||||
rc := &RunContext{
|
||||
Config: &Config{
|
||||
Workdir: ".",
|
||||
|
@ -105,6 +104,7 @@ func TestEvaluate(t *testing.T) {
|
|||
for _, table := range tables {
|
||||
table := table
|
||||
t.Run(table.in, func(t *testing.T) {
|
||||
assert := a.New(t)
|
||||
out, err := ee.Evaluate(table.in)
|
||||
if table.errMesg == "" {
|
||||
assert.NoError(err, table.in)
|
||||
|
@ -118,15 +118,16 @@ func TestEvaluate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInterpolate(t *testing.T) {
|
||||
assert := a.New(t)
|
||||
rc := &RunContext{
|
||||
Config: &Config{
|
||||
Workdir: ".",
|
||||
},
|
||||
Env: map[string]string{
|
||||
"keywithnothing": "valuewithnothing",
|
||||
"key-with-hyphens": "value-with-hyphens",
|
||||
"key_with_underscores": "value_with_underscores",
|
||||
"KEYWITHNOTHING": "valuewithnothing",
|
||||
"KEY-WITH-HYPHENS": "value-with-hyphens",
|
||||
"KEY_WITH_UNDERSCORES": "value_with_underscores",
|
||||
"TRUE": "true",
|
||||
"FALSE": "false",
|
||||
},
|
||||
Run: &model.Run{
|
||||
JobID: "job1",
|
||||
|
@ -144,15 +145,20 @@ func TestInterpolate(t *testing.T) {
|
|||
out string
|
||||
}{
|
||||
{" ${{1}} to ${{2}} ", " 1 to 2 "},
|
||||
{" ${{ env.keywithnothing }} ", " valuewithnothing "},
|
||||
{" ${{ env.key-with-hyphens }} ", " value-with-hyphens "},
|
||||
{" ${{ env.key_with_underscores }} ", " value_with_underscores "},
|
||||
{"${{ env.unknown }}", ""},
|
||||
{" ${{ env.KEYWITHNOTHING }} ", " valuewithnothing "},
|
||||
{" ${{ env.KEY-WITH-HYPHENS }} ", " value-with-hyphens "},
|
||||
{" ${{ env.KEY_WITH_UNDERSCORES }} ", " value_with_underscores "},
|
||||
{"${{ env.UNKNOWN }}", ""},
|
||||
{"${{ env.TRUE }}", "true"},
|
||||
{"${{ env.FALSE }}", "false"},
|
||||
{"${{ !env.TRUE }}", "!true"},
|
||||
{"${{ !env.FALSE }}", "!false"},
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
table := table
|
||||
t.Run(table.in, func(t *testing.T) {
|
||||
assert := a.New(t)
|
||||
out := ee.Interpolate(table.in)
|
||||
assert.Equal(table.out, out, table.in)
|
||||
})
|
||||
|
@ -160,8 +166,6 @@ func TestInterpolate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRewrite(t *testing.T) {
|
||||
assert := a.New(t)
|
||||
|
||||
rc := &RunContext{
|
||||
Config: &Config{},
|
||||
Run: &model.Run{
|
||||
|
@ -195,6 +199,7 @@ func TestRewrite(t *testing.T) {
|
|||
for _, table := range tables {
|
||||
table := table
|
||||
t.Run(table.in, func(t *testing.T) {
|
||||
assert := a.New(t)
|
||||
re := ee.Rewrite(table.in)
|
||||
assert.Equal(table.re, re, table.in)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue