Skip to content

Commit

Permalink
fix: error when generating mocks (#414)
Browse files Browse the repository at this point in the history
While generating mocks for new methods from hcloud-go 1.37.0 we encountered
following error log when running `go generate`:

    prog.go:12:2: no required module provides package github.com/golang/mock/mockgen/model: go.mod file not found in current directory or any parent directory; see 'go help modules'
    prog.go:14:2: no required module provides package github.com/hetznercloud/cli/internal/hcapi2: go.mod file not found in current directory or any parent directory; see 'go help modules'
    2022/11/10 14:52:03 Loading input failed: exit status 1
    internal/hcapi2/mock_gen.go:3: running "mockgen": exit status 1

This was solved by moving the mocks into a seperate package.
  • Loading branch information
apricote authored Nov 11, 2022
1 parent 27b41d0 commit edb0bdf
Show file tree
Hide file tree
Showing 39 changed files with 171 additions and 183 deletions.
108 changes: 0 additions & 108 deletions internal/hcapi2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package hcapi2
import (
"sync"

"github.com/golang/mock/gomock"
"github.com/hetznercloud/hcloud-go/hcloud"
)

Expand Down Expand Up @@ -206,110 +205,3 @@ func (c *client) PlacementGroup() PlacementGroupClient {
defer c.mu.Unlock()
return c.placementGroupClient
}

type MockClient struct {
CertificateClient *MockCertificateClient
DatacenterClient *MockDatacenterClient
FirewallClient *MockFirewallClient
FloatingIPClient *MockFloatingIPClient
PrimaryIPClient *MockPrimaryIPClient
ImageClient *MockImageClient
LocationClient *MockLocationClient
LoadBalancerClient *MockLoadBalancerClient
LoadBalancerTypeClient *MockLoadBalancerTypeClient
NetworkClient *MockNetworkClient
ServerClient *MockServerClient
ServerTypeClient *MockServerTypeClient
SSHKeyClient *MockSSHKeyClient
VolumeClient *MockVolumeClient
ISOClient *MockISOClient
PlacementGroupClient *MockPlacementGroupClient
RDNSClient *MockRDNSClient
}

func NewMockClient(ctrl *gomock.Controller) *MockClient {
return &MockClient{
CertificateClient: NewMockCertificateClient(ctrl),
DatacenterClient: NewMockDatacenterClient(ctrl),
FirewallClient: NewMockFirewallClient(ctrl),
FloatingIPClient: NewMockFloatingIPClient(ctrl),
PrimaryIPClient: NewMockPrimaryIPClient(ctrl),
ImageClient: NewMockImageClient(ctrl),
LocationClient: NewMockLocationClient(ctrl),
LoadBalancerClient: NewMockLoadBalancerClient(ctrl),
LoadBalancerTypeClient: NewMockLoadBalancerTypeClient(ctrl),
NetworkClient: NewMockNetworkClient(ctrl),
ServerClient: NewMockServerClient(ctrl),
ServerTypeClient: NewMockServerTypeClient(ctrl),
SSHKeyClient: NewMockSSHKeyClient(ctrl),
VolumeClient: NewMockVolumeClient(ctrl),
ISOClient: NewMockISOClient(ctrl),
PlacementGroupClient: NewMockPlacementGroupClient(ctrl),
RDNSClient: NewMockRDNSClient(ctrl),
}
}
func (c *MockClient) Certificate() CertificateClient {
return c.CertificateClient
}
func (c *MockClient) Datacenter() DatacenterClient {
return c.DatacenterClient
}

func (c *MockClient) Firewall() FirewallClient {
return c.FirewallClient
}

func (c *MockClient) FloatingIP() FloatingIPClient {
return c.FloatingIPClient
}

func (c *MockClient) PrimaryIP() PrimaryIPClient {
return c.PrimaryIPClient
}

func (c *MockClient) Image() ImageClient {
return c.ImageClient
}

func (c *MockClient) ISO() ISOClient {
return c.ISOClient
}

func (c *MockClient) Location() LocationClient {
return c.LocationClient
}

func (c *MockClient) LoadBalancer() LoadBalancerClient {
return c.LoadBalancerClient
}

func (c *MockClient) LoadBalancerType() LoadBalancerTypeClient {
return c.LoadBalancerTypeClient
}

func (c *MockClient) Network() NetworkClient {
return c.NetworkClient
}

func (c *MockClient) Server() ServerClient {
return c.ServerClient
}

func (c *MockClient) ServerType() ServerTypeClient {
return c.ServerTypeClient
}

func (c *MockClient) SSHKey() SSHKeyClient {
return c.SSHKeyClient
}

func (c *MockClient) Volume() VolumeClient {
return c.VolumeClient
}
func (c *MockClient) RDNS() RDNSClient {
return c.RDNSClient
}

func (c *MockClient) PlacementGroup() PlacementGroupClient {
return c.PlacementGroupClient
}
113 changes: 113 additions & 0 deletions internal/hcapi2/mock/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package hcapi2_mock

import (
"github.com/golang/mock/gomock"
"github.com/hetznercloud/cli/internal/hcapi2"
)

type MockClient struct {
CertificateClient *MockCertificateClient
DatacenterClient *MockDatacenterClient
FirewallClient *MockFirewallClient
FloatingIPClient *MockFloatingIPClient
PrimaryIPClient *MockPrimaryIPClient
ImageClient *MockImageClient
LocationClient *MockLocationClient
LoadBalancerClient *MockLoadBalancerClient
LoadBalancerTypeClient *MockLoadBalancerTypeClient
NetworkClient *MockNetworkClient
ServerClient *MockServerClient
ServerTypeClient *MockServerTypeClient
SSHKeyClient *MockSSHKeyClient
VolumeClient *MockVolumeClient
ISOClient *MockISOClient
PlacementGroupClient *MockPlacementGroupClient
RDNSClient *MockRDNSClient
}

func NewMockClient(ctrl *gomock.Controller) *MockClient {
return &MockClient{
CertificateClient: NewMockCertificateClient(ctrl),
DatacenterClient: NewMockDatacenterClient(ctrl),
FirewallClient: NewMockFirewallClient(ctrl),
FloatingIPClient: NewMockFloatingIPClient(ctrl),
PrimaryIPClient: NewMockPrimaryIPClient(ctrl),
ImageClient: NewMockImageClient(ctrl),
LocationClient: NewMockLocationClient(ctrl),
LoadBalancerClient: NewMockLoadBalancerClient(ctrl),
LoadBalancerTypeClient: NewMockLoadBalancerTypeClient(ctrl),
NetworkClient: NewMockNetworkClient(ctrl),
ServerClient: NewMockServerClient(ctrl),
ServerTypeClient: NewMockServerTypeClient(ctrl),
SSHKeyClient: NewMockSSHKeyClient(ctrl),
VolumeClient: NewMockVolumeClient(ctrl),
ISOClient: NewMockISOClient(ctrl),
PlacementGroupClient: NewMockPlacementGroupClient(ctrl),
RDNSClient: NewMockRDNSClient(ctrl),
}
}
func (c *MockClient) Certificate() hcapi2.CertificateClient {
return c.CertificateClient
}
func (c *MockClient) Datacenter() hcapi2.DatacenterClient {
return c.DatacenterClient
}

func (c *MockClient) Firewall() hcapi2.FirewallClient {
return c.FirewallClient
}

func (c *MockClient) FloatingIP() hcapi2.FloatingIPClient {
return c.FloatingIPClient
}

func (c *MockClient) PrimaryIP() hcapi2.PrimaryIPClient {
return c.PrimaryIPClient
}

func (c *MockClient) Image() hcapi2.ImageClient {
return c.ImageClient
}

func (c *MockClient) ISO() hcapi2.ISOClient {
return c.ISOClient
}

func (c *MockClient) Location() hcapi2.LocationClient {
return c.LocationClient
}

func (c *MockClient) LoadBalancer() hcapi2.LoadBalancerClient {
return c.LoadBalancerClient
}

func (c *MockClient) LoadBalancerType() hcapi2.LoadBalancerTypeClient {
return c.LoadBalancerTypeClient
}

func (c *MockClient) Network() hcapi2.NetworkClient {
return c.NetworkClient
}

func (c *MockClient) Server() hcapi2.ServerClient {
return c.ServerClient
}

func (c *MockClient) ServerType() hcapi2.ServerTypeClient {
return c.ServerTypeClient
}

func (c *MockClient) SSHKey() hcapi2.SSHKeyClient {
return c.SSHKeyClient
}

func (c *MockClient) Volume() hcapi2.VolumeClient {
return c.VolumeClient
}
func (c *MockClient) RDNS() hcapi2.RDNSClient {
return c.RDNSClient
}

func (c *MockClient) PlacementGroup() hcapi2.PlacementGroupClient {
return c.PlacementGroupClient
}
19 changes: 19 additions & 0 deletions internal/hcapi2/mock/mock_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package hcapi2_mock

//go:generate mockgen -package hcapi2_mock -destination zz_certificate_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 CertificateClient
//go:generate mockgen -package hcapi2_mock -destination zz_datacenter_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 DatacenterClient
//go:generate mockgen -package hcapi2_mock -destination zz_image_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 ImageClient
//go:generate mockgen -package hcapi2_mock -destination zz_iso_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 ISOClient
//go:generate mockgen -package hcapi2_mock -destination zz_firewall_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 FirewallClient
//go:generate mockgen -package hcapi2_mock -destination zz_floating_ip_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 FloatingIPClient
//go:generate mockgen -package hcapi2_mock -destination zz_primary_ip_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 PrimaryIPClient
//go:generate mockgen -package hcapi2_mock -destination zz_location_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 LocationClient
//go:generate mockgen -package hcapi2_mock -destination zz_loadbalancer_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 LoadBalancerClient
//go:generate mockgen -package hcapi2_mock -destination zz_loadbalancer_type_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 LoadBalancerTypeClient
//go:generate mockgen -package hcapi2_mock -destination zz_network_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 NetworkClient
//go:generate mockgen -package hcapi2_mock -destination zz_server_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 ServerClient
//go:generate mockgen -package hcapi2_mock -destination zz_server_type_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 ServerTypeClient
//go:generate mockgen -package hcapi2_mock -destination zz_ssh_key_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 SSHKeyClient
//go:generate mockgen -package hcapi2_mock -destination zz_volume_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 VolumeClient
//go:generate mockgen -package hcapi2_mock -destination zz_placement_group_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 PlacementGroupClient
//go:generate mockgen -package hcapi2_mock -destination zz_rdns_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 RDNSClient

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit edb0bdf

Please sign in to comment.