Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
per1234 opened this issue Dec 9, 2020 · 2 comments · Fixed by #105
Closed

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

per1234 opened this issue Dec 9, 2020 · 2 comments · Fixed by #105
Assignees
Labels
conclusion: resolved Issue was resolved criticality: high Of high impact topic: code Related to content of the project itself type: enhancement Proposed improvement

Comments

@per1234
Copy link
Contributor

per1234 commented Dec 9, 2020

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.

@per1234
Copy link
Contributor Author

per1234 commented Dec 9, 2020

@silvanocerza any ideas?

@silvanocerza
Copy link
Contributor

First thing that comes to mind would be to embed the schemas directly into the code, so it's all contained in the final binary.
This would also ease the release process since we won't have to release the json files together with the final executable.

With Go 1.16 they should introduce a way to embed resource files using a new directive but there's still for some time before they release it.

Otherwise we could use the library go-bindata.

I found this info in this StackOverflow question, I suggest you give it a read, there are some interesting points in this answer.

Otherwise we could simply put the whole jsons in literal strings inside the code, that would make it harder to edit the schemas probably.

@per1234 per1234 added conclusion: resolved Issue was resolved priority: high Resolution is a high priority topic: code Related to content of the project itself type: enhancement Proposed improvement labels Feb 22, 2021
@rsora rsora added criticality: high Of high impact and removed priority: high Resolution is a high priority labels Nov 2, 2021
@per1234 per1234 self-assigned this Nov 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved criticality: high Of high impact topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants