1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2026-06-03 16:35:37 +02:00

Add more test cases for rpc label filter (#6483)

This commit is contained in:
6543
2026-04-22 16:55:50 +02:00
committed by GitHub
parent 91c1b1cf72
commit fa0bfe9038
+89 -1
View File
@@ -76,7 +76,7 @@ func TestCreateFilterFunc(t *testing.T) {
wantScore: 0,
},
{
name: "Missing label",
name: "Missing required label on agent",
agentFilter: rpc.Filter{
Labels: map[string]string{"platform": "linux"},
},
@@ -130,6 +130,94 @@ func TestCreateFilterFunc(t *testing.T) {
wantMatched: true,
wantScore: 20,
},
{
name: "Two different labels",
agentFilter: rpc.Filter{
Labels: map[string]string{"docker": "true"},
},
task: &model.Task{
Labels: map[string]string{"hello": "true"},
},
wantMatched: false,
wantScore: 0,
},
{
name: "Exact match",
agentFilter: rpc.Filter{
Labels: map[string]string{"docker": "true"},
},
task: &model.Task{
Labels: map[string]string{"docker": "true"},
},
wantMatched: true,
wantScore: 10,
},
{
name: "Agent without labels",
agentFilter: rpc.Filter{
Labels: map[string]string{},
},
task: &model.Task{
Labels: map[string]string{"docker": "true"},
},
wantMatched: false,
wantScore: 0,
},
{
name: "Task without labels",
agentFilter: rpc.Filter{
Labels: map[string]string{"docker": "true"},
},
task: &model.Task{
Labels: map[string]string{},
},
wantMatched: true,
wantScore: 0,
},
{
name: "Agent and task without labels",
agentFilter: rpc.Filter{
Labels: map[string]string{},
},
task: &model.Task{
Labels: map[string]string{},
},
wantMatched: true,
wantScore: 0,
},
{
name: "Multiple matching labels",
agentFilter: rpc.Filter{
Labels: map[string]string{"docker": "true", "shell": "true", "gpu": "true"},
},
task: &model.Task{
Labels: map[string]string{"docker": "true", "shell": "true", "gpu": "true"},
},
wantMatched: true,
wantScore: 30,
},
{
name: "Additional label in agent",
agentFilter: rpc.Filter{
Labels: map[string]string{"docker": "true", "shell": "true", "gpu": "true"},
},
task: &model.Task{
Labels: map[string]string{"docker": "true", "shell": "true"},
},
wantMatched: true,
wantScore: 20,
},
{
name: "Additional label in task",
agentFilter: rpc.Filter{
Labels: map[string]string{"docker": "true", "shell": "true"},
},
task: &model.Task{
Labels: map[string]string{"docker": "true", "shell": "true", "gpu": "true"},
},
wantMatched: false,
wantScore: 0,
},
}
for _, tt := range tests {