Merge ~gabrielcocenza/juju-lint:bug/1979542 into juju-lint:master

Proposed by Gabriel Cocenza
Status: Merged
Approved by: Eric Chen
Approved revision: 7c358ca024c4a892308001a73dc6a1e9a934fe17
Merged at revision: 03479fa387c011076bdfaa39227f837f6e48fd89
Proposed branch: ~gabrielcocenza/juju-lint:bug/1979542
Merge into: juju-lint:master
Diff against target: 83 lines (+37/-0)
4 files modified
contrib/includes/operations/bionic.yaml (+3/-0)
contrib/includes/operations/focal.yaml (+4/-0)
tests/unit/conftest.py (+9/-0)
tests/unit/test_jujulint.py (+21/-0)
Reviewer Review Type Date Requested Status
Eric Chen Needs Information
BootStack Reviewers Pending
Martin Kalcok Pending
Review via email: mp+429452@code.launchpad.net

Commit message

unit tests to check if rules file on contrib folder load correctly.

- fixed broken rules

Closes-Bug: #1979542

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Eric Chen (eric-chen) wrote :

LGTM, but let's merge it after Martin's big unit test MR

Revision history for this message
Eric Chen (eric-chen) :
review: Approve
Revision history for this message
Eric Chen (eric-chen) wrote :

Last thing: Please rebase and provide the log of lint/unit/func test, thanks!

review: Needs Information
Revision history for this message
Gabriel Cocenza (gabrielcocenza) wrote :

Rebased and here is the pastebin for lint, unit and func tests [0]

[0] https://pastebin.canonical.com/p/K8T2VwmDzQ/

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 03479fa387c011076bdfaa39227f837f6e48fd89

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/contrib/includes/operations/bionic.yaml b/contrib/includes/operations/bionic.yaml
2index a6baf9e..1e37975 100644
3--- a/contrib/includes/operations/bionic.yaml
4+++ b/contrib/includes/operations/bionic.yaml
5@@ -1,2 +1,5 @@
6 operations openstack mandatory series: &operations-openstack-mandatory-series
7 - prometheus-ceph-exporter
8+# compatability with new fields of fcb rules
9+operations openstack mandatory release: &operations-openstack-mandatory-release []
10+openstack loadbalancer: &openstack-loadbalancer []
11diff --git a/contrib/includes/operations/focal.yaml b/contrib/includes/operations/focal.yaml
12index d658661..f7b3f73 100644
13--- a/contrib/includes/operations/focal.yaml
14+++ b/contrib/includes/operations/focal.yaml
15@@ -1 +1,5 @@
16 operations openstack mandatory series: &operations-openstack-mandatory-series []
17+# compatability with new fields of fcb rules
18+operations openstack mandatory release: &operations-openstack-mandatory-release []
19+openstack loadbalancer: &openstack-loadbalancer
20+ - openstack-loadbalancer
21diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py
22index d82193d..a70ef63 100644
23--- a/tests/unit/conftest.py
24+++ b/tests/unit/conftest.py
25@@ -10,6 +10,7 @@
26
27 import os
28 import sys
29+from pathlib import Path
30 from unittest.mock import MagicMock
31
32 import mock
33@@ -220,3 +221,11 @@ def patch_cloud_init(mocker):
34 mocker.patch.object(cloud, "Logger")
35 mocker.patch.object(cloud, "Connection")
36 mocker.patch.object(cloud.socket, "getfqdn", return_value="localhost")
37+
38+
39+@pytest.fixture
40+def rules_files():
41+ """Get all standard rules files that comes with the snap."""
42+ return [
43+ str(rule.resolve()) for rule in Path("./contrib").iterdir() if rule.is_file()
44+ ]
45diff --git a/tests/unit/test_jujulint.py b/tests/unit/test_jujulint.py
46index 6c611f6..4394835 100644
47--- a/tests/unit/test_jujulint.py
48+++ b/tests/unit/test_jujulint.py
49@@ -5,6 +5,7 @@ from datetime import datetime, timezone
50 from unittest import mock
51
52 import pytest
53+import yaml
54
55 from jujulint import check_spaces, lint
56
57@@ -874,6 +875,26 @@ applications:
58 assert linter.lint_rules == {"key": "value"}
59 assert result
60
61+ def test_snap_rules_files(self, rules_files, linter):
62+ """Ensure that all standard rules in the snap is loading correctly."""
63+ for rule_file in rules_files:
64+ try:
65+ linter.filename = rule_file
66+ linter.read_rules()
67+ except yaml.YAMLError:
68+ pytest.fail(f"File: {rule_file} not loading")
69+
70+ def test_wrong_rule_file_raise_error(self, rules_files, linter, mocker):
71+ """Test that bad formatted rules raise YAMLError."""
72+ rules_file = rules_files[0]
73+ linter.filename = rules_file
74+ mocker.patch(
75+ "jujulint.lint.Linter._process_includes_in_rules",
76+ side_effect=yaml.YAMLError,
77+ )
78+ with pytest.raises(yaml.YAMLError):
79+ linter.read_rules()
80+
81 def test_read_rules_include(self, linter, tmp_path):
82 """Test that rules YAML with an include is imported as expected."""
83 include_path = tmp_path / "include.yaml"

Subscribers

People subscribed via source and target branches