Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interfaces around Services for testing #13

Open
ciroque opened this issue Sep 17, 2019 · 4 comments
Open

Interfaces around Services for testing #13

ciroque opened this issue Sep 17, 2019 · 4 comments

Comments

@ciroque
Copy link

ciroque commented Sep 17, 2019

We are using go-kong and have been writing unit tests around our code. To help with this we have written interfaces for the various Services (RouteService, Svcservice, UpstreamService, and TargetService thus far).

In a way we have painted ourselves into a corner with this.

In trying to hook up the actual go-kong library we are writing super thin wrappers that meet our interface definitions and adapt to go-kong.

It would be much easier if the interfaces existed in go-kong.

Does this sound reasonable? We can prepare a PR if it something people think would be helpful.

@hbagdi
Copy link
Owner

hbagdi commented Sep 17, 2019

@ciroque Some questions before I answer:

  1. Have you considered injecting a mock http.Client into the New() method to mock the entire package?
  2. What is your use-case for this library?
  3. Could you provide a small code sample of what you mean here?

@ciroque
Copy link
Author

ciroque commented Sep 18, 2019

Hi @hbagdi

  1. I had not considered this, sounds intriguing. My trouble with that approach is that we'd be testing that go-kong uses the http.Client as expected. We'd rather put the interfaces / mocks at the natural boundaries of our code.

  2. Perhaps easiest to link to the repo: https://github.com/ciroque/k8s-kong-federated-ingress
    Basically we are creating a k8s controller to synchronize Kong resources to k8s resources. While we are using Ingress Controllers we need a Global Ingress Gateway.

  3. https://github.com/ciroque/k8s-kong-federated-ingress/blob/master/internal/kong/client.go is the most specific example. Yeah, it's kind of a disaster, but represents the boundaries we wish to enforce.

Thanks!

@hbagdi
Copy link
Owner

hbagdi commented Sep 24, 2019

@ciroque Sounds like a good addition.
Please feel free to PR this.
Let's use Go's codegen facilities to generate the Interfaces from the struct definitions so that there is no drift and a user doesn't forget to add a method to the Interface if they are implementing it in the struct.

@ciroque
Copy link
Author

ciroque commented Sep 26, 2019

Trying to eke out some time at work to get this done. The Go codegen is not something I am familiar with, but going to learn it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants