Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make sure JSONParser is compatible with RawFileProvider #3390

Merged
merged 5 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion insights/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,12 @@ class JSONParser(Parser, LegacyItemAccess):
"""
def parse_content(self, content):
try:
self.data = json.loads(''.join(content))
if isinstance(content, list):
self.data = json.loads('\n'.join(content))
else:
self.data = json.loads(content)
if self.data is None:
raise SkipException("There is no data")
except:
# If content is empty then raise a skip exception instead of a parse exception.
if not content:
Expand Down
11 changes: 11 additions & 0 deletions insights/parsers/tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,16 @@ def test_tags_json():
assert result.data['group'] == "app-db-01"


def test_tags_json_bytes():
bytes_content = bytes(str(tags_json_content).encode("utf-8"))
ctx = context_wrap(bytes_content)
ctx.content = bytes_content
result = Tags(ctx)
assert result.data['zone'] == "east"
assert result.data['owner'] == "test"
assert result.data['exclude'] == "true"
assert result.data['group'] == "app-db-01"


def test_tags_empty():
assert 'Empty output.' in skip_exception_check(Tags)