Merge pull request 'chore: add test for unexpected YAML type in top level env' (#269) from earl-warren/runner:wip-env-type into main
Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/269 Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
This commit is contained in:
commit
db9f23de54
1 changed files with 27 additions and 5 deletions
|
@ -19,7 +19,7 @@ func Test_generateWorkflow(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
assert func(t *testing.T, wf *model.Workflow)
|
assert func(t *testing.T, wf *model.Workflow, err error)
|
||||||
want1 string
|
want1 string
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
|
@ -56,19 +56,41 @@ jobs:
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
assert: func(t *testing.T, wf *model.Workflow) {
|
assert: func(t *testing.T, wf *model.Workflow, err error) {
|
||||||
assert.DeepEqual(t, wf.GetJob("job9").Needs(), []string{"job1", "job2"})
|
assert.DeepEqual(t, wf.GetJob("job9").Needs(), []string{"job1", "job2"})
|
||||||
},
|
},
|
||||||
want1: "job9",
|
want1: "job9",
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "valid YAML syntax in top level env but wrong value type",
|
||||||
|
args: args{
|
||||||
|
task: &runnerv1.Task{
|
||||||
|
WorkflowPayload: []byte(`
|
||||||
|
on: push
|
||||||
|
|
||||||
|
env:
|
||||||
|
value: {{ }}
|
||||||
|
`),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
assert: func(t *testing.T, wf *model.Workflow, err error) {
|
||||||
|
require.Nil(t, wf)
|
||||||
|
assert.ErrorContains(t, err, "cannot unmarshal")
|
||||||
|
},
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got, got1, err := generateWorkflow(tt.args.task)
|
got, got1, err := generateWorkflow(tt.args.task)
|
||||||
|
if tt.wantErr {
|
||||||
|
require.Error(t, err)
|
||||||
|
} else {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tt.assert(t, got)
|
|
||||||
assert.Equal(t, got1, tt.want1)
|
assert.Equal(t, got1, tt.want1)
|
||||||
|
}
|
||||||
|
tt.assert(t, got, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue