go-xml icon indicating copy to clipboard operation
go-xml copied to clipboard

Test generated Go code in `xsdgen`, `wsdlgen` packages

Open droyo opened this issue 8 years ago • 4 comments

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.

droyo avatar Sep 18 '17 01:09 droyo

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.

droyo avatar Sep 28 '17 07:09 droyo

In case it's of interest/inspiration zeep is relatively new, and seems to have a nice unit & integration test suite

leth avatar Jan 03 '19 11:01 leth

Thanks! That has some nice examples.

droyo avatar Jan 03 '19 12:01 droyo

working on this in the issue-25 branch.

droyo avatar Jan 03 '19 16:01 droyo