From 3938ddb31914afa693b0fc591a2a421234170d1b Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Tue, 1 Oct 2024 19:31:22 +0545 Subject: [PATCH] test: change mapping --- scrapers/changes/rules_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/scrapers/changes/rules_test.go b/scrapers/changes/rules_test.go index 5ca43629..273d2835 100644 --- a/scrapers/changes/rules_test.go +++ b/scrapers/changes/rules_test.go @@ -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{