hcloud-go icon indicating copy to clipboard operation
hcloud-go copied to clipboard

feat(exp): add hcloud client mock package

Open jooola opened this issue 1 year ago • 2 comments

This adds a generated mock for the hcloud.Client that will be usable for external library for testing.

jooola avatar May 13 '24 13:05 jooola

Codecov Report

Attention: Patch coverage is 0% with 20 lines in your changes are missing coverage. Please review.

Project coverage is 70.54%. Comparing base (a61c494) to head (0f02426).

Files Patch % Lines
hcloud/exp/hcloudmock/client.go 0.00% 20 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #442      +/-   ##
==========================================
- Coverage   70.91%   70.54%   -0.38%     
==========================================
  Files          35       36       +1     
  Lines        3772     3792      +20     
==========================================
  Hits         2675     2675              
- Misses        688      708      +20     
  Partials      409      409              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar May 13 '24 13:05 codecov[bot]

I started implementing the new mocks in the CLI: https://github.com/hetznercloud/cli/commit/43295830767194d1aaa7ff680d11223c08716e4b It saves us quite a bit of code there. Although it would be nicer if we had a unified interface that the mock client would implement and also a wrapper for the regular hcloud-go client that has those methods, like we do in the hcapi2 package in the cli. On a side note, I think the package name mock is a bit too generic and could cause some collisions. I still think it's a very good idea to put this logic into hcloud-go instead of cluttering other integrations with it.

phm07 avatar May 21 '24 16:05 phm07

Although it would be nicer if we had a unified interface that the mock client would implement and also a wrapper for the regular hcloud-go client that has those methods, like we do in the hcapi2 package in the cli.

I am not sure to fully understand your suggestions, could you elaborate please?

jooola avatar May 24 '24 11:05 jooola

Implementing a mock for the client will be on hold until we can implement an interface first client. The current struct based client does not allow us to swap the client implementation (real and mock) easily.

jooola avatar May 29 '24 17:05 jooola