From b4a6b82b5a81f4bdbb1eb12aae01883a5ab24d18 Mon Sep 17 00:00:00 2001 From: grantbirki Date: Mon, 31 Jul 2023 12:29:02 +0100 Subject: [PATCH] update json tests for dot mode --- .../data/config/.github_mock_dir/json2.json | 4 ++++ __tests__/functions/json-validator.test.js | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 __tests__/fixtures/json/project_dir/data/config/.github_mock_dir/json2.json diff --git a/__tests__/fixtures/json/project_dir/data/config/.github_mock_dir/json2.json b/__tests__/fixtures/json/project_dir/data/config/.github_mock_dir/json2.json new file mode 100644 index 0000000..5a258dd --- /dev/null +++ b/__tests__/fixtures/json/project_dir/data/config/.github_mock_dir/json2.json @@ -0,0 +1,4 @@ +{ + "foo": 5, + "bar": "zxy" +} diff --git a/__tests__/functions/json-validator.test.js b/__tests__/functions/json-validator.test.js index c226e37..8bef53e 100644 --- a/__tests__/functions/json-validator.test.js +++ b/__tests__/functions/json-validator.test.js @@ -20,6 +20,7 @@ beforeEach(() => { process.env.INPUT_JSON_EXTENSION = '.json' process.env.INPUT_JSON_EXCLUDE_REGEX = '.*bad.*\\.json' process.env.INPUT_YAML_AS_JSON = false + process.env.INPUT_USE_DOT_MATCH = 'true' }) test('successfully validates a json file with a schema', async () => { @@ -60,7 +61,8 @@ test('successfully skips a file found in the exclude txt file', async () => { }) }) -test('successfully validates a json file with a schema and skips the schema as well', async () => { +test('successfully validates a json file with a schema and skips the schema as well while using the dot match in a disabled mode', async () => { + process.env.INPUT_USE_DOT_MATCH = 'false' process.env.INPUT_JSON_SCHEMA = './__tests__/fixtures/json/project_dir/schemas/schema.json' process.env.INPUT_BASE_DIR = './__tests__/fixtures/json/project_dir' @@ -76,6 +78,22 @@ test('successfully validates a json file with a schema and skips the schema as w ) }) +test('successfully validates a json file with a schema and skips the schema as well', async () => { + process.env.INPUT_JSON_SCHEMA = + './__tests__/fixtures/json/project_dir/schemas/schema.json' + process.env.INPUT_BASE_DIR = './__tests__/fixtures/json/project_dir' + expect(await jsonValidator(excludeMock)).toStrictEqual({ + failed: 0, + passed: 2, + skipped: 0, + success: true, + violations: [] + }) + expect(debugMock).toHaveBeenCalledWith( + `skipping json schema file: ${process.env.INPUT_JSON_SCHEMA}` + ) +}) + test('fails to validate a json file without using a schema', async () => { process.env.INPUT_JSON_SCHEMA = '' process.env.INPUT_BASE_DIR = './__tests__/fixtures/json/invalid'