Skip to content

Commit

Permalink
test: change mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Oct 1, 2024
1 parent 77ce53d commit 3938ddb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions scrapers/changes/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,39 @@ func TestProcessRules(t *testing.T) {
rules []v1.ChangeMapping
err bool
}{
{
name: "health mapping - fail",
input: v1.ScrapeResult{
Changes: []v1.ChangeResult{{ChangeType: "diff", Patches: ""}},
},
expect: []v1.ChangeResult{{ChangeType: "diff", Patches: ""}},
rules: []v1.ChangeMapping{{
Type: "HealthCheckPassed",
Filter: `change.change_type == 'diff' && jq('try .status.conditions[] | select(.type == "Healthy").message', patch).contains('Health check passed')`,
}},
},
{
name: "health mapping - fail II",
input: v1.ScrapeResult{
Changes: []v1.ChangeResult{{ChangeType: "diff", Patches: `{"status": {}}`}},
},
expect: []v1.ChangeResult{{ChangeType: "diff", Patches: `{"status": {}}`}},
rules: []v1.ChangeMapping{{
Type: "HealthCheckPassed",
Filter: `change.change_type == 'diff' && jq('try .status.conditions[] | select(.type == "Healthy").message', patch).contains('Health check passed')`,
}},
},
{
name: "health mapping - pass",
input: v1.ScrapeResult{
Changes: []v1.ChangeResult{{ChangeType: "diff", Patches: `{"status": {"conditions": [{"type": "Healthy", "message": "Health check passed"}]}}`}},
},
expect: []v1.ChangeResult{{ChangeType: "HealthCheckPassed", Patches: `{"status": {"conditions": [{"type": "Healthy", "message": "Health check passed"}]}}`}},
rules: []v1.ChangeMapping{{
Type: "HealthCheckPassed",
Filter: `change.change_type == 'diff' && jq('try .status.conditions[] | select(.type == "Healthy").message', patch).contains('Health check passed')`,
}},
},
{
name: "Should error out on bad filter",
input: v1.ScrapeResult{
Expand Down

0 comments on commit 3938ddb

Please sign in to comment.