diff --git a/query_exporter/db.py b/query_exporter/db.py index f73bf87..4b0ffd5 100644 --- a/query_exporter/db.py +++ b/query_exporter/db.py @@ -218,7 +218,7 @@ def results(self, query_results: QueryResults) -> MetricResults: if len(expected_keys) != len(result_keys): raise InvalidResultCount(len(expected_keys), len(result_keys)) if result_keys != expected_keys: - raise InvalidResultColumnNames(result_keys, expected_keys) + raise InvalidResultColumnNames(expected_keys, result_keys) results = [] for row in query_results.rows: values = dict(zip(query_results.keys, row)) diff --git a/tests/db_test.py b/tests/db_test.py index 28f7e32..ad9aab0 100644 --- a/tests/db_test.py +++ b/tests/db_test.py @@ -292,8 +292,12 @@ def test_results_wrong_names_with_labels(self): "query", ["db"], [QueryMetric("metric1", ["label1"])], "" ) query_results = QueryResults(["one", "two"], [(1, 2)]) - with pytest.raises(InvalidResultColumnNames): + with pytest.raises(InvalidResultColumnNames) as error: query.results(query_results) + assert str(error.value) == ( + "Wrong column names from query: " + "expected (label1, metric1), got (one, two)" + ) class TestQueryResults: @@ -609,7 +613,7 @@ async def test_execute_query_invalid_names_with_labels(self, db): await db.execute(query) assert ( str(error.value) - == "Wrong column names from query: expected (foo, label), got (label, metric)" + == "Wrong column names from query: expected (label, metric), got (foo, label)" ) assert error.value.fatal @@ -618,7 +622,7 @@ async def test_execute_query_traceback_debug(self, caplog, mocker, db): """Traceback are logged as debug messages.""" query = Query( "query", - 20, + ["db"], [QueryMetric("metric", [])], "SELECT 1 AS metric", )