@@ -14,40 +14,40 @@ import (
1414 "github.com/stretchr/testify/require"
1515)
1616
17- func TestScopedWorkflowSource_IsFileRequired (t * testing.T ) {
18- src := & ActionScopedWorkflowSource {RequiredFiles : []string {"a.yml" , "b.yml" }}
19- assert .True (t , src .IsFileRequired ("a.yml" ))
20- assert .True (t , src .IsFileRequired ("b.yml" ))
21- assert .False (t , src .IsFileRequired ("c.yml" ))
17+ func TestScopedWorkflowSource_IsWorkflowRequired (t * testing.T ) {
18+ src := & ActionScopedWorkflowSource {RequiredWorkflowIDs : []string {"a.yml" , "b.yml" }}
19+ assert .True (t , src .IsWorkflowRequired ("a.yml" ))
20+ assert .True (t , src .IsWorkflowRequired ("b.yml" ))
21+ assert .False (t , src .IsWorkflowRequired ("c.yml" ))
2222
2323 empty := & ActionScopedWorkflowSource {}
24- assert .False (t , empty .IsFileRequired ("a.yml" ))
24+ assert .False (t , empty .IsWorkflowRequired ("a.yml" ))
2525}
2626
27- func TestIsFileRequiredInSources (t * testing.T ) {
27+ func TestIsWorkflowRequiredInSources (t * testing.T ) {
2828 // repo 100 registered twice (org optional + instance required).
2929 sources := []* ActionScopedWorkflowSource {
30- {OwnerID : 2 , SourceRepoID : 100 , RequiredFiles : nil },
31- {OwnerID : 0 , SourceRepoID : 100 , RequiredFiles : []string {"a.yml" }},
32- {OwnerID : 0 , SourceRepoID : 200 , RequiredFiles : []string {"b.yml" }},
30+ {OwnerID : 2 , SourceRepoID : 100 , RequiredWorkflowIDs : nil },
31+ {OwnerID : 0 , SourceRepoID : 100 , RequiredWorkflowIDs : []string {"a.yml" }},
32+ {OwnerID : 0 , SourceRepoID : 200 , RequiredWorkflowIDs : []string {"b.yml" }},
3333 }
3434
35- assert .True (t , IsFileRequiredInSources (sources , 100 , "a.yml" ), "required at instance level wins over org optional" )
36- assert .False (t , IsFileRequiredInSources (sources , 100 , "z.yml" ))
37- assert .False (t , IsFileRequiredInSources (sources , 200 , "a.yml" ), "a.yml is required for repo 100, not repo 200" )
38- assert .True (t , IsFileRequiredInSources (sources , 200 , "b.yml" ))
39- assert .False (t , IsFileRequiredInSources (sources , 999 , "a.yml" ), "unknown source repo" )
35+ assert .True (t , IsWorkflowRequiredInSources (sources , 100 , "a.yml" ), "required at instance level wins over org optional" )
36+ assert .False (t , IsWorkflowRequiredInSources (sources , 100 , "z.yml" ))
37+ assert .False (t , IsWorkflowRequiredInSources (sources , 200 , "a.yml" ), "a.yml is required for repo 100, not repo 200" )
38+ assert .True (t , IsWorkflowRequiredInSources (sources , 200 , "b.yml" ))
39+ assert .False (t , IsWorkflowRequiredInSources (sources , 999 , "a.yml" ), "unknown source repo" )
4040}
4141
4242func TestGetEffectiveScopedWorkflowSources (t * testing.T ) {
4343 require .NoError (t , unittest .PrepareTestDatabase ())
4444 ctx := t .Context ()
4545
4646 rows := []* ActionScopedWorkflowSource {
47- {OwnerID : 2 , SourceRepoID : 100 , RequiredFiles : nil }, // org 2 registers repo 100 (optional)
48- {OwnerID : 0 , SourceRepoID : 100 , RequiredFiles : []string {"a.yml" }}, // instance also registers repo 100 (required)
49- {OwnerID : 0 , SourceRepoID : 200 , RequiredFiles : []string {"b.yml" }}, // instance source 200
50- {OwnerID : 3 , SourceRepoID : 300 , RequiredFiles : []string {"c.yml" }}, // a different owner's source
47+ {OwnerID : 2 , SourceRepoID : 100 , RequiredWorkflowIDs : nil }, // org 2 registers repo 100 (optional)
48+ {OwnerID : 0 , SourceRepoID : 100 , RequiredWorkflowIDs : []string {"a.yml" }}, // instance also registers repo 100 (required)
49+ {OwnerID : 0 , SourceRepoID : 200 , RequiredWorkflowIDs : []string {"b.yml" }}, // instance source 200
50+ {OwnerID : 3 , SourceRepoID : 300 , RequiredWorkflowIDs : []string {"c.yml" }}, // a different owner's source
5151 }
5252 for _ , r := range rows {
5353 require .NoError (t , db .Insert (ctx , r ))
@@ -58,20 +58,20 @@ func TestGetEffectiveScopedWorkflowSources(t *testing.T) {
5858 require .NoError (t , err )
5959 assert .Len (t , owner2 , 3 )
6060
61- required , err := IsScopedFileRequired (ctx , 2 , 100 , "a.yml" )
61+ required , err := IsScopedWorkflowRequired (ctx , 2 , 100 , "a.yml" )
6262 require .NoError (t , err )
6363 assert .True (t , required , "instance marks a.yml required → required for owner 2 even though org left it optional" )
6464
65- required , err = IsScopedFileRequired (ctx , 2 , 100 , "x.yml" )
65+ required , err = IsScopedWorkflowRequired (ctx , 2 , 100 , "x.yml" )
6666 require .NoError (t , err )
6767 assert .False (t , required )
6868
69- required , err = IsScopedFileRequired (ctx , 2 , 200 , "b.yml" )
69+ required , err = IsScopedWorkflowRequired (ctx , 2 , 200 , "b.yml" )
7070 require .NoError (t , err )
7171 assert .True (t , required )
7272
7373 // owner 3's source must not be effective for owner 2.
74- required , err = IsScopedFileRequired (ctx , 2 , 300 , "c.yml" )
74+ required , err = IsScopedWorkflowRequired (ctx , 2 , 300 , "c.yml" )
7575 require .NoError (t , err )
7676 assert .False (t , required )
7777
@@ -108,19 +108,17 @@ func TestScopedWorkflowSourceCRUD(t *testing.T) {
108108 require .NoError (t , err )
109109 assert .Len (t , sources , 1 )
110110
111- // set required files (with their workflow names used for the merge-gate globs )
112- require .NoError (t , SetScopedWorkflowSourceRequired (ctx , 5 , 10 , []string {"a.yml" , "b.yml" }, [] string { "A" , "B" } ))
111+ // set the required workflows (by entry name / run WorkflowID )
112+ require .NoError (t , SetScopedWorkflowSourceRequired (ctx , 5 , 10 , []string {"a.yml" , "b.yml" }))
113113 src , err := GetScopedWorkflowSource (ctx , 5 , 10 )
114114 require .NoError (t , err )
115- assert .ElementsMatch (t , []string {"a.yml" , "b.yml" }, src .RequiredFiles )
116- assert .ElementsMatch (t , []string {"A" , "B" }, src .RequiredWorkflowNames )
115+ assert .ElementsMatch (t , []string {"a.yml" , "b.yml" }, src .RequiredWorkflowIDs )
117116
118- // clearing required files works
119- require .NoError (t , SetScopedWorkflowSourceRequired (ctx , 5 , 10 , nil , nil ))
117+ // clearing the required set works
118+ require .NoError (t , SetScopedWorkflowSourceRequired (ctx , 5 , 10 , nil ))
120119 src , err = GetScopedWorkflowSource (ctx , 5 , 10 )
121120 require .NoError (t , err )
122- assert .Empty (t , src .RequiredFiles )
123- assert .Empty (t , src .RequiredWorkflowNames )
121+ assert .Empty (t , src .RequiredWorkflowIDs )
124122
125123 // remove
126124 require .NoError (t , RemoveScopedWorkflowSource (ctx , 5 , 10 ))
0 commit comments