Skip to content

Commit

Permalink
fix: rules filters now considers jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
crgisch committed Sep 26, 2024
1 parent b495172 commit f6eb431
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
8 changes: 8 additions & 0 deletions rule/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ func ruleTypeMatch(ruleType types.RuleType, filter types.RuleType) bool {
return false
}
}
if filter.TsuruJob != nil {
if ruleType.TsuruJob == nil {
return false
}
if filter.TsuruJob.JobName != "" && filter.TsuruJob.JobName != ruleType.TsuruJob.JobName {
return false
}
}
if filter.KubernetesService != nil {
if ruleType.KubernetesService == nil {
return false
Expand Down
57 changes: 55 additions & 2 deletions rule/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,39 @@ func Test_RuleService_FindByRule(t *testing.T) {
"x": "y",
},
},
{
RuleID: "3",
Source: types.RuleType{
TsuruJob: &types.TsuruJobRule{
JobName: "my-job",
},
},
Destination: types.RuleType{
ExternalDNS: &types.ExternalDNSRule{
Name: "job-api.com",
Ports: []types.ProtoPort{},
},
},
Metadata: map[string]string{
"y": "z",
},
},
{
RuleID: "4",
Source: types.RuleType{
TsuruApp: &types.TsuruAppRule{
AppName: "myapp",
},
},
Destination: types.RuleType{
TsuruJob: &types.TsuruJobRule{
JobName: "my-job",
},
},
Metadata: map[string]string{
"key": "value",
},
},
}
svc := GetService()
for _, r := range rules {
Expand All @@ -671,7 +704,7 @@ func Test_RuleService_FindByRule(t *testing.T) {
}{
{
filter: types.Rule{},
expectedRuleIDs: []string{"1", "2"},
expectedRuleIDs: []string{"1", "2", "3", "4"},
},
{
filter: types.Rule{
Expand Down Expand Up @@ -708,7 +741,7 @@ func Test_RuleService_FindByRule(t *testing.T) {
TsuruApp: &types.TsuruAppRule{},
},
},
expectedRuleIDs: []string{"1"},
expectedRuleIDs: []string{"1", "4"},
},
{
filter: types.Rule{
Expand Down Expand Up @@ -740,6 +773,26 @@ func Test_RuleService_FindByRule(t *testing.T) {
},
expectedRuleIDs: []string{},
},
{
filter: types.Rule{
Source: types.RuleType{
TsuruJob: &types.TsuruJobRule{
JobName: "my-job",
},
},
},
expectedRuleIDs: []string{"3"},
},
{
filter: types.Rule{
Destination: types.RuleType{
TsuruJob: &types.TsuruJobRule{
JobName: "my-job",
},
},
},
expectedRuleIDs: []string{"4"},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit f6eb431

Please sign in to comment.