1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-08-11 17:50:58 +00:00

feat: add notifications control to the workflow (#151)

Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/151
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
Earl Warren 2025-06-14 15:42:32 +00:00 committed by earl-warren
parent 5cf8d53087
commit 01032808ea
2 changed files with 77 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package model
import (
"fmt"
"strings"
"testing"
@ -108,6 +109,64 @@ jobs:
assert.Contains(t, workflow.On(), "push")
}
func TestReadWorkflow_Notifications(t *testing.T) {
for _, testCase := range []struct {
expected bool
hasErr bool
snippet string
}{
{
expected: false,
hasErr: false,
snippet: "# nothing",
},
{
expected: true,
hasErr: false,
snippet: "notifications: true",
},
{
expected: false,
hasErr: false,
snippet: "notifications: false",
},
{
hasErr: true,
snippet: "notifications: invalid",
},
{
hasErr: true,
snippet: "notifications: [1,2]",
},
} {
t.Run(testCase.snippet, func(t *testing.T) {
yaml := fmt.Sprintf(`
name: name-455
on: push
%s
jobs:
valid-JOB-Name-455:
runs-on: docker
steps:
- run: echo hi
`, testCase.snippet)
workflow, err := ReadWorkflow(strings.NewReader(yaml))
assert.NoError(t, err, "read workflow should succeed")
notification, err := workflow.Notifications()
if testCase.hasErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, testCase.expected, notification)
}
})
}
}
func TestReadWorkflow_ListEvent(t *testing.T) {
yaml := `
name: local-action-docker-url