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

Setup mocks #35

Merged
merged 4 commits into from
Jan 26, 2021
Merged

Setup mocks #35

merged 4 commits into from
Jan 26, 2021

Conversation

cyx
Copy link
Contributor

@cyx cyx commented Jan 26, 2021

Description

In order to provide easier testability, we're going to utilize https://github.com/golang/mock. For us to utilize that, we'll want to have clear interfaces we can mock.

Unfortunately, the go sdk today doesn't have that, so we're going to shim interfaces / functions which would allow us to mock cleanly.

Changes

  • Uses golang/mock/mockgen to generate mock files.
  • Uses golang/mock/go-mock to work with mocks during the client test.
  • Adds a client test for listing to show it working for one spot.
  • Adds an internal/auth0 package to create a point of mocking.
  • Adds internal/auth0.API struct to hold our interface style management client.

Comment on lines +3 to +7
package main

import (
_ "github.com/golang/mock/mockgen"
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is important so we can vendor our tooling deps.

ResourceServer ResourceServerAPI
}

func NewAPI(m *management.Management) *API {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not pass the token details instead and make the client directly here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's basically because the management constructor having a plethora of options and encoding that vs catching a fully formed struct being easier

@paddycarey
Copy link
Contributor

I like it 👍🏻

I wonder though if we should specify more minimal interfaces, only the methods we're actually using to keep the verbosity down. On the other hand, if the goal is to just get something working such that we can later push the interfaces (and maybe even the mocks) upstream then great, that works too.

@cyx
Copy link
Contributor Author

cyx commented Jan 26, 2021

I like it 👍🏻

I wonder though if we should specify more minimal interfaces, only the methods we're actually using to keep the verbosity down. On the other hand, if the goal is to just get something working such that we can later push the interfaces (and maybe even the mocks) upstream then great, that works too.

Yes the intention is for us to upstream this, or basically push the envelope in terms of the current sdk's limitations

@cyx cyx merged commit 0443bcc into main Jan 26, 2021
@cyx cyx deleted the setup-mocks branch January 26, 2021 11:56
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

Successfully merging this pull request may close these issues.

3 participants