Skip to content

Commit

Permalink
fix: report right dependency type
Browse files Browse the repository at this point in the history
close #31
  • Loading branch information
vhf committed Feb 8, 2021
1 parent 3892160 commit 9002361
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
20 changes: 10 additions & 10 deletions packages/validation/lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,28 +185,28 @@ function getPipelineProperties (graph, pipelines) {

async function getAllOperationProperties (dependencies, checks) {
const results = {}
for (const env in dependencies) {
for (const module in dependencies[env]) {
for (const protocol in dependencies) {
for (const module in dependencies[protocol]) {
let issue
const currOperations = Array.from(dependencies[env][module]).join('"\n * "')
issue = validators.dependency.validate(module, currOperations)
const operations = Array.from(dependencies[protocol][module]).join('"\n * "')
issue = validators.dependency.validate(module, { operations, protocol })
checks.addGenericCheck(issue)

if (!utils.isModuleInstalled(module)) {
continue
}
const operationsPath = utils.getManifestPath(module)
const manifestPath = utils.getManifestPath(module)

issue = validators.operation.validate(operationsPath, module, currOperations)
issue = validators.operation.validate(manifestPath, module, operations)
checks.addGenericCheck(issue)

if (operationsPath) {
const graph = await readGraph(operationsPath, checks)
const tempResults = getModuleOperationProperties(graph, dependencies[env][module].values())
if (manifestPath) {
const manifestGraph = await readGraph(manifestPath, checks)
const tempResults = getModuleOperationProperties(manifestGraph, dependencies[protocol][module].values())
Object.assign(results, tempResults)
}
else {
for (const codelink of dependencies[env][module]) {
for (const codelink of dependencies[protocol][module]) {
results[codelink] = null
}
}
Expand Down
18 changes: 13 additions & 5 deletions packages/validation/lib/validators/dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@ const Issue = require('../issue')
const utils = require('../utils')
const { template } = require('../utils')

// corresponds to rdf-code-loader resolvers:
// https://github.com/zazuko/rdf-loader-code/blob/c5137d45f13c6788f9f6f161653b7cd800401a0f/lib/iriResolve.js#L4-L17
const dependencyTypes = {
'node:': 'package',
'file:': 'file'
}

const dependency = {
ruleDescription: 'Each dependency must be installed',
ruleId: 2668,
messageSuccessTemplate: template`Package ${'library'} found successfully`,
messageFailureTemplate: template`Missing package ${'library'}\n The following operations cannot be validated:\n * "${'operations'}"`,
validate (library, codelinksWithMissingMetadata) {
messageSuccessTemplate: template`Found ${'dependencyType'} ${'library'} successfully`,
messageFailureTemplate: template`Missing ${'dependencyType'} ${'library'}\n The following operations cannot be validated:\n * "${'operations'}"`,
validate (library, { operations, protocol }) {
const dependencyType = dependencyTypes[protocol]
let issue
if (utils.isModuleInstalled(library)) {
issue = Issue.info({ id: this.ruleId, templateData: { library } })
issue = Issue.info({ id: this.ruleId, templateData: { library, dependencyType } })
}
else {
issue = Issue.error({
id: this.ruleId,
templateData: { library, operations: codelinksWithMissingMetadata }
templateData: { library, dependencyType, operations }
})
}
return issue
Expand Down
2 changes: 1 addition & 1 deletion packages/validation/lib/validators/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const operation = {
ruleId: 3,
ruleDescription: 'manifest.ttl file exists and can be parsed',
messageSuccessTemplate: template`Metadata file for ${'library'} loaded successfully`,
messageFailureTemplate: template`Missing metadata file for ${'library'}.\n The following operations cannot be validated:\n * "${'operations'}"`,
messageFailureTemplate: template`Missing metadata file for ${'library'}\n The following operations cannot be validated:\n * "${'operations'}"`,
validate (operationPathExists, library, codelinksWithMissingMetadata) {
let issue
if (operationPathExists) {
Expand Down
2 changes: 1 addition & 1 deletion packages/validation/test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ describe('parser.getAllOperationProperties', () => {
const actual = await mockedParser.getAllOperationProperties(input, checks)
assert.deepStrictEqual(actual, expected)

const expectedMssg = validators.dependency.messageFailureTemplate({ library: 'foo-bar', operations: 'node:foo-bar#fn' })
const expectedMssg = validators.dependency.messageFailureTemplate({ library: 'foo-bar', operations: 'node:foo-bar#fn', dependencyType: 'package' })
assert(genericContainsMessage(checks, expectedMssg))
})
})
Expand Down

0 comments on commit 9002361

Please sign in to comment.