Skip to content

Conversation

@JGAntunes
Copy link
Member

What this PR does / why we need it:

This is a PoC whose aim is to show how we can reduce the maintenance burden of mocks in our codebase. We used as an example the host preflight manager mock and introduced 2 key components:

  • A new struct that embeddeds testify mock's struct
  • A new method that we can use to register method calls ONLY if there are mocks that have been previously registered in our tests.

With this utility struct we can then, within each method of our mock, determine if we have registered calls we want to use or fallback to default stubs.

Drawbacks of the approach

  • Registering a wrong mock call (e.g. register something with a typo, m.On("RunHOSTAPreflights", ...)) can become hard to debug because we'll still get a response (albeit if we run the mock assertions at the end of the test we should get an error the registered method wasn't called).
  • Where in the past calls to "unknown" methods would have failed this will no longer be the case.
  • Over reliance on default stubs for everything might lead us to a "shared test harness" scenario where all the tests are coupled with the same state definition and we have the tendency to add/edit those VS defining specific mock method call overrides when we need to.

Which issue(s) this PR fixes:

Does this PR require a test?

Does this PR require a release note?


Does this PR require documentation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants