Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
XenServer: Initial commit for xenserver_guest module unit tests #56242
Initial commit for xenserver_guest module unit tests and refactoring of unit tests for xenserver_guest_facts and xenserver_guest_powerstate modules.
Since xenserver_guest is using a large number of XenAPI methods, mocking all of them individually and keeping track of data manipulation proved to be very hard to do. Mocking any XenAPI method itself is hard to do because of the way method calls are implemented in XenAPI library. They are implemented by dynamically resolving call stack (XenAPI class hierarchy) and instantiating callable objects along the way. Unlike xenserver_guest_facts and xenserver_guest_powerstate modules, for xenserver_guest module I needed a better solution. What I ended up with was to greatly extend FakeXenAPI library to support loading and manipulation of XenAPI DB sample data (kept in .json files). All needed XenAPI methods are implemented directly in FakeXenAPI library where they manipulate in-memory XenAPI DB data, valid during the lifetime of a test function. This way I almost entirely removed mocks. Some mocking is still done but usually mocks are used to wrap functions and keep track of their calls. Unit tests for xenserver_guest_facts and xenserver_guest_powerstate modules were then ported to this new FakeXenAPI library thus greatly reducing the number of mocks, simplifying test functions and producing better coverage.
I understand that some tests now look almost like integration tests but since there is no XenServer simulator and using real XenServer for integration tests would be hard or impossible to do, this is the next best thing.