hetznercloud / hcloud-go

A Go library for the Hetzner Cloud API
https://pkg.go.dev/github.com/hetznercloud/hcloud-go/v2/hcloud
MIT License
372 stars 45 forks source link

feat(exp): add hcloud client mock package #442

Closed jooola closed 3 months ago

jooola commented 4 months ago

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

codecov[bot] commented 4 months ago

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 ```diff @@ 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.

phm07 commented 3 months ago

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.

jooola commented 3 months ago

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 commented 3 months ago

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.