go-xml
go-xml copied to clipboard
Test generated Go code in `xsdgen`, `wsdlgen` packages
When developing new features and fixing bugs, progress is impeded by the lack of thorough automated tests. There are tests for each package that verify xsd files can be parsed without errors, and that Go code can be generated without errors. However, there is not enough tests of the generated code itself.
Develop unit tests that generate Go code for XSD fragments and check the following:
- Generated code is valid Go code
- Sample data is successfully decoded into the generated Go types
- Go type is encoded to equivalent XML
The tests should be data-driven, so it is easy to add additional test cases just by providing an XSD and some sample data. In the future the tests can be extended to ensure default values are set (see #2), but that is not a requirement for this issue.
Potential challenges
- The naive way of doing this requires compiling and running a Go program. This will make the tests more complicated and slower at best, flaky and non-portable at worst. Is there any way around compiling a Go program?
- Encoded XML data will be slightly different from the source XML due to the
encoding/xml's handling of XML namespaces, so a simple equivalency==check won't be enough.
Easy compromise; generate the tests and check them in with each change. It's a bit of tedium, but could be automated and is an easier problem to solve than running these tests on the fly.
In case it's of interest/inspiration zeep is relatively new, and seems to have a nice unit & integration test suite
Thanks! That has some nice examples.
working on this in the issue-25 branch.