-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from lyubick/issue_#4
ISSUE #4: JSON validation enabled.
- Loading branch information
Showing
13 changed files
with
162 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
--- | ||
name: Self Test | ||
|
||
on: | ||
'on': | ||
pull_request: | ||
branches: [ main ] | ||
branches: ['main'] | ||
|
||
jobs: | ||
runValidation: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Check if directory is not scanned, due to recursive is False (should PASS) | ||
id: validation | ||
uses: lyubick/action-YAML-schema-validator@test | ||
- name: Run PyTest(s) | ||
run: | | ||
pip install -r requirements.txt | ||
pip install -r requirements-test.txt | ||
pytest test/ -rxXs | ||
- name: Check YAML files inside directory | ||
uses: ./ | ||
continue-on-error: true | ||
with: | ||
json-schema-file: test/json_schema.json | ||
yaml-file-dir: test/ | ||
- name: Check if directory is scanned, due to recursive is True (should FAIL) | ||
id: invalidation | ||
json-schema-file: test/schema/json_schema.json | ||
yaml-file-dir: test/YAMLs/ | ||
- name: Check JSON files inside directory | ||
uses: ./ | ||
continue-on-error: true | ||
uses: lyubick/action-YAML-schema-validator@test | ||
with: | ||
json-schema-file: test/json_schema.json | ||
yaml-file-dir: test/ | ||
recursive: true | ||
json-schema-file: test/schema/json_schema.json | ||
yaml-file-dir: test/JSONs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
jsonschema==4.17.3 | ||
pyyaml==6.0 | ||
pytest==7.3.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"field2": "Value2" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"field1": "Value1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
--- | ||
field2: Value2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
--- | ||
field1: Value1 |
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from pathlib import Path | ||
|
||
import validator | ||
import jsonschema | ||
|
||
|
||
class Test: | ||
abs_path = Path(__file__).parent | ||
|
||
def test1_load_schema(self): | ||
schema = validator.load_schema(f'{self.abs_path}/schema/json_schema.json') | ||
assert schema['title'] == 'TestConfig' | ||
assert schema['description'] == 'Test Basic YAML File' | ||
|
||
def test2_get_files(self): | ||
files = validator.get_yaml_json_files_list(f'{self.abs_path}/YAMLs', is_recursive=True) | ||
assert len(files) == 2 | ||
|
||
def test3_validate_valid_file(self): | ||
schema = validator.load_schema(f'{self.abs_path}/schema/json_schema.json') | ||
files = validator.get_yaml_json_files_list(f'{self.abs_path}/YAMLs/yaml_valid.yaml', False) | ||
assert validator.validate_files(files, schema) | ||
|
||
def test4_validate_invalid_file(self): | ||
schema = validator.load_schema(f'{self.abs_path}/schema/json_schema.json') | ||
files = validator.get_yaml_json_files_list(f'{self.abs_path}/YAMLs/yaml_invalid.yaml', False) | ||
try: | ||
validator.validate_files(files, schema) | ||
assert False | ||
except jsonschema.exceptions.ValidationError as exc: | ||
assert exc.instance == {'field2': 'Value2'} | ||
|
||
def test5_validate_valid_file_json(self): | ||
schema = validator.load_schema(f'{self.abs_path}/schema/json_schema.json') | ||
files = validator.get_yaml_json_files_list(f'{self.abs_path}/JSONs/yaml_valid.json', False) | ||
assert validator.validate_files(files, schema) | ||
|
||
def test6_validate_invalid_file_json(self): | ||
schema = validator.load_schema(f'{self.abs_path}/schema/json_schema.json') | ||
files = validator.get_yaml_json_files_list(f'{self.abs_path}/JSONs/yaml_invalid.json', False) | ||
try: | ||
validator.validate_files(files, schema) | ||
assert False | ||
except jsonschema.exceptions.ValidationError as exc: | ||
assert exc.instance == {'field2': 'Value2'} | ||
|
||
def test7_validate_folder_yaml(self): | ||
schema = validator.load_schema(f'{self.abs_path}/schema/json_schema.json') | ||
files = validator.get_yaml_json_files_list(f'{self.abs_path}/YAMLs/', False) | ||
try: | ||
validator.validate_files(files, schema) | ||
assert False | ||
except jsonschema.exceptions.ValidationError as exc: | ||
assert exc.instance == {'field2': 'Value2'} | ||
|
||
def test8_validate_folder_json(self): | ||
schema = validator.load_schema(f'{self.abs_path}/schema/json_schema.json') | ||
files = validator.get_yaml_json_files_list(f'{self.abs_path}/JSONs/', False) | ||
try: | ||
validator.validate_files(files, schema) | ||
assert False | ||
except jsonschema.exceptions.ValidationError as exc: | ||
assert exc.instance == {'field2': 'Value2'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters