Business intelligence made simple
Moved anomaly_checks tests
Andrew Kane367d53b8bf61
diff --git a/test/anomaly_checks_test.rb b/test/anomaly_checks_test.rbnew file mode 100644index 00000000..46707661--- /dev/null+++ b/test/anomaly_checks_test.rb@@ -0,0 +1,38 @@+require_relative "test_helper"++class AnomalyChecksTest < ActionDispatch::IntegrationTest+ def test_prophet+ skip unless ENV["TEST_PROPHET"]++ assert_anomaly("prophet")+ end++ def test_trend+ skip unless ENV["TEST_TREND"]++ assert_anomaly("trend")+ end++ def test_anomaly_detection+ skip unless ENV["TEST_ANOMALY_DETECTION"]++ assert_anomaly("anomaly_detection")+ end++ def assert_anomaly(anomaly_checks)+ Blazer.stub(:anomaly_checks, anomaly_checks) do+ query = create_query(statement: "SELECT current_date + n AS day, 0.1 * random() FROM generate_series(1, 30) n")+ check = create_check(query: query, check_type: "anomaly")++ Blazer.run_checks(schedule: "5 minutes")+ check.reload+ assert_equal "passing", check.state++ query.update!(statement: "SELECT current_date + n AS day, 0.1 * random() FROM generate_series(1, 30) n UNION ALL SELECT current_date + 31, 2")++ Blazer.run_checks(schedule: "5 minutes")+ check.reload+ assert_equal "failing", check.state+ end+ end+enddiff --git a/test/checks_test.rb b/test/checks_test.rbindex 6832a924..c87934ea 100644--- a/test/checks_test.rb+++ b/test/checks_test.rb@@ -49,24 +49,6 @@ class ChecksTest < ActionDispatch::IntegrationTestassert_equal "error", check.stateend- def test_anomaly_prophet- skip unless ENV["TEST_PROPHET"]-- assert_anomaly("prophet")- end-- def test_anomaly_trend- skip unless ENV["TEST_TREND"]-- assert_anomaly("trend")- end-- def test_anomaly_anomaly_detection- skip unless ENV["TEST_ANOMALY_DETECTION"]-- assert_anomaly("anomaly_detection")- end-def test_emailsquery = create_querycheck = create_check(query: query, check_type: "bad_data", emails: "[email protected],[email protected]")@@ -101,27 +83,6 @@ class ChecksTest < ActionDispatch::IntegrationTestendend- def create_check(**attributes)- Blazer::Check.create!(schedule: "5 minutes", **attributes)- end-- def assert_anomaly(anomaly_checks)- Blazer.stub(:anomaly_checks, anomaly_checks) do- query = create_query(statement: "SELECT current_date + n AS day, 0.1 * random() FROM generate_series(1, 30) n")- check = create_check(query: query, check_type: "anomaly")-- Blazer.run_checks(schedule: "5 minutes")- check.reload- assert_equal "passing", check.state-- query.update!(statement: "SELECT current_date + n AS day, 0.1 * random() FROM generate_series(1, 30) n UNION ALL SELECT current_date + 31, 2")-- Blazer.run_checks(schedule: "5 minutes")- check.reload- assert_equal "failing", check.state- end- end-def assert_slack_messages(expected)count = 0Blazer::SlackNotifier.stub :post_api, ->(*) { count += 1 } dodiff --git a/test/test_helper.rb b/test/test_helper.rbindex 6ecaa330..aa461f74 100644--- a/test/test_helper.rb+++ b/test/test_helper.rb@@ -24,4 +24,8 @@ class ActionDispatch::IntegrationTestdef create_query(statement: "SELECT 1")Blazer::Query.create!(statement: statement, data_source: "main", status: "active")end++ def create_check(**attributes)+ Blazer::Check.create!(schedule: "5 minutes", **attributes)+ endend