Skip to content

Commit

Permalink
Validate yaml files using superstruct lib
Browse files Browse the repository at this point in the history
  • Loading branch information
willemarcel committed May 7, 2024
1 parent eb97cdb commit 9a8514f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions task/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"meow": "^12.1.1",
"simplify-geojson": "^1.0.5",
"slugify": "^1.6.6",
"superstruct": "^1.0.4",
"xlsx": "^0.18.5",
"xml2js": "^0.6.2",
"yaml": "2.3.4"
Expand Down
38 changes: 38 additions & 0 deletions task/tests/validate-yaml.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const fs = require('fs');
const path = require('path');
const {
array,
assert,
boolean,
number,
object,
optional,
string,
} = require('superstruct');
const { readCampaignYaml } = require('../src/utils');

const structure = array(
object({
name: string(),
platforms: array(
object({
name: string(),
tsv_format: optional(boolean()),
rename_as_ict: optional(boolean()),
process_as_ict: optional(boolean()),
coords_divisor: optional(number()),
files: array(string()),
})
),
})
);

test('YAML files should be valid', () => {
const campaigns = fs.readdirSync('../campaigns/');
campaigns
.filter((c) => fs.existsSync(path.join('../campaigns/', c, 'deployments.yaml')))
.forEach((c) => {
console.log(`Checking: ${c}:`);
assert(readCampaignYaml(path.join('../campaigns/', c)), structure);
});
});
5 changes: 5 additions & 0 deletions task/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4165,6 +4165,11 @@ strnum@^1.0.5:
resolved "https://registry.yarnpkg.com/strnum/-/strnum-1.0.5.tgz#5c4e829fe15ad4ff0d20c3db5ac97b73c9b072db"
integrity sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA==

superstruct@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/superstruct/-/superstruct-1.0.4.tgz#0adb99a7578bd2f1c526220da6571b2d485d91ca"
integrity sha512-7JpaAoX2NGyoFlI9NBh66BQXGONc+uE+MRS5i2iOBKuS4e+ccgMDjATgZldkah+33DakBxDHiss9kvUcGAO8UQ==

supports-color@^5.3.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
Expand Down

0 comments on commit 9a8514f

Please sign in to comment.