Skip to content

How to mock resolver with V2 client? #166

@Grendel7

Description

@Grendel7

I make quite heavy use of NetDNS2 in my application, especially to get a lot more insight and control into DNS lookups. It's a great library if you want to control which nameservers to send your query, and truly disect the exact DNS response.

To test my implementation code, I make use of Mockery to mock the Resolver, as well as the Response packet, so I know my code makes the right decision based on the information returned by the DNS query.

This worked fine with the V1 client. But this approach doesn't work at all with the V2 client, because:

  • Mockery works by dynamically extending the parent class with a mock class, so it can intercept calls while still passing type checks. But with the V2 client, almost every class is designated as final, which prevents this trick from working.
  • An alternative to this would be to build a mock based on an abstract or an interface, but the client contains no abstract classes or interfaces.
  • Mockery supports proxy objects, but this breaks all type checks. And I need input types for the dependency injection to work correctly.
  • Many data representation objects take only data as their input argument, with no definition as to what this data is supposed to look like, making it hard to construct these data objects manually for testing.

Based on this, my questions are:

  • What is the recommended way to test code that uses this library? Was this use case even considered? And no, just testing against actual DNS servers is not feasible for me.
  • Would you be willing to add interfaces to the library, at least for any class that's final?
  • Or would you be open to dropping the final designation from most classes at all?

For these last two, I'd be willing to put in the work, but I would like to know beforehand what you'd be willing to accept.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions