Skip to content

Unable to write tests for schema-based check functions #95

Closed
@per1234

Description

@per1234

The schemas themselves and the schema handling functions have pretty good coverage, but I'm still missing the ability to add tests for the check functions based on them, For example:

// LibraryPropertiesNameFieldLTMinLength checks if the library.properties "name" value is less than the minimum length.
func LibraryPropertiesNameFieldLTMinLength() (result checkresult.Type, output string) {
if checkdata.LibraryPropertiesLoadError() != nil {
return checkresult.NotRun, "Couldn't load library.properties"
}
if !checkdata.LibraryProperties().ContainsKey("name") {
return checkresult.NotRun, "Field not present"
}
if schema.PropertyLessThanMinLength("name", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
return checkresult.Fail, ""
}
return checkresult.Pass, ""
}

I haven't figured out how to do this.

This is related to the previous discussion here:
#14 (review)

The trouble is that the schema path is configured relative to the executable path (#21):

executablePath, err := os.Executable()

which doesn't work when running tests.

The tests I have written for functions using the schemas were possible because they had a schema path parameter. But the check functions don't have such a parameter and I don't like the idea of adding such a parameter to every check function.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions