问题
We use pact contract tests for services that communicate using rest calls and kafka messages. We would also like to implement a similar contract testing framework between services that exchange (xml) files via an sftp server. I might be able to use the message pact framework and treating the contents of the file as the contents of the message, but was wondering if there were better alternatives. No matter how I handle contract testing between a consumer and producer that exchange files, I will also have to deal with how to validate xml code, so any advice on that would also be appreciated.
回答1:
The Pact framework does not impose any restriction on the contents of interactions that are verified. You can use it with XML, or any other type of data. The main thing with JSON is there is good DSL support for defining the contract for a JSON payload. With other types of data, the support is not so good. We've started adding DSL support for XML, but it is still early days for it.
You can treat your files just like asynchronous messages, where the transport mechanism is an SFTP site. It would be possible to use the Message Pact format to then create contract tests for these. Your provider would be whatever writes the file to the server, and the consumer is what reads it. The contract would be between these two systems, and you can abstract away that the XML files are transferred via an SFTP server.
For your particular case, however, I wonder if using XSDs to verify the files would be sufficient?
来源:https://stackoverflow.com/questions/61346039/contract-testing-for-xml-file-exchange