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

test: use client interfaces provided by hcloud-go for mocking #614

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/guptarohit/asciigraph v0.5.6
github.com/hetznercloud/hcloud-go/v2 v2.5.0
github.com/pelletier/go-toml/v2 v2.1.1
github.com/rjeczalik/interfaces v0.3.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwa
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rjeczalik/interfaces v0.3.0 h1:BM+eRAwfOcvW5qVhxv7x09x/0jwHN6z2GB9HsSA2weM=
github.com/rjeczalik/interfaces v0.3.0/go.mod h1:wfGcwiM/PXv9l6U/CPCb4Yh5KngED3dR3OppEVHMWuU=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down
10 changes: 6 additions & 4 deletions internal/hcapi2/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@ package hcapi2
import (
"context"
"strconv"

"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

// CertificateClient embeds the Hetzner Cloud Certificate client and provides some
// additional helper functions.
type CertificateClient interface {
CertificateClientBase
hcloud.ICertificateClient
Names() []string
LabelKeys(string) []string
}

func NewCertificateClient(client CertificateClientBase) CertificateClient {
func NewCertificateClient(client hcloud.ICertificateClient) CertificateClient {
return &certificateClient{
CertificateClientBase: client,
ICertificateClient: client,
}
}

type certificateClient struct {
CertificateClientBase
hcloud.ICertificateClient
}

// Names obtains a list of available data centers. It returns nil if
Expand Down
10 changes: 6 additions & 4 deletions internal/hcapi2/datacenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ package hcapi2
import (
"context"
"strconv"

"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

// DatacenterClient embeds the Hetzner Cloud DataCenter client and provides some
// additional helper functions.
type DatacenterClient interface {
DatacenterClientBase
hcloud.IDatacenterClient
Names() []string
}

func NewDatacenterClient(client DatacenterClientBase) DatacenterClient {
func NewDatacenterClient(client hcloud.IDatacenterClient) DatacenterClient {
return &datacenterClient{
DatacenterClientBase: client,
IDatacenterClient: client,
}
}

type datacenterClient struct {
DatacenterClientBase
hcloud.IDatacenterClient
}

// Names obtains a list of available data centers. It returns nil if
Expand Down
10 changes: 6 additions & 4 deletions internal/hcapi2/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@ package hcapi2
import (
"context"
"strconv"

"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

type FirewallClient interface {
FirewallClientBase
hcloud.IFirewallClient
Names() []string
LabelKeys(string) []string
}

func NewFirewallClient(client FirewallClientBase) FirewallClient {
func NewFirewallClient(client hcloud.IFirewallClient) FirewallClient {
return &firewallClient{
FirewallClientBase: client,
IFirewallClient: client,
}
}

// FirewallClient embeds the Hetzner Cloud Firewall client and provides
// some additional helper functions.
type firewallClient struct {
FirewallClientBase
hcloud.IFirewallClient
}

// Names obtains a list of available firewalls. It returns nil if
Expand Down
10 changes: 6 additions & 4 deletions internal/hcapi2/floatingip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@ package hcapi2
import (
"context"
"strconv"

"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

// FloatingIPClient embeds the hcloud FloatingIPClient (via an interface) and provides
// some additional helper functions.
type FloatingIPClient interface {
FloatingIPClientBase
hcloud.IFloatingIPClient
Names() []string
LabelKeys(idOrName string) []string
}

// NewFloatingIPClient creates a new floating IP client.
func NewFloatingIPClient(client FloatingIPClientBase) FloatingIPClient {
func NewFloatingIPClient(client hcloud.IFloatingIPClient) FloatingIPClient {
return &floatingIPClient{
FloatingIPClientBase: client,
IFloatingIPClient: client,
}
}

// FloatingIPClient embeds the Hetzner Cloud FloatingIP client and provides some
// additional helper functions.
type floatingIPClient struct {
FloatingIPClientBase
hcloud.IFloatingIPClient
}

// Names obtains a list of available floating IPs. It returns nil if
Expand Down
8 changes: 4 additions & 4 deletions internal/hcapi2/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import (
// ImageClient embeds the Hetzner Cloud Image client and provides some
// additional helper functions.
type ImageClient interface {
ImageClientBase
hcloud.IImageClient
Names() []string
LabelKeys(string) []string
}

func NewImageClient(client ImageClientBase) ImageClient {
func NewImageClient(client hcloud.IImageClient) ImageClient {
return &imageClient{
ImageClientBase: client,
IImageClient: client,
}
}

type imageClient struct {
ImageClientBase
hcloud.IImageClient
}

// Names obtains a list of available images. It returns nil if image names
Expand Down
19 changes: 0 additions & 19 deletions internal/hcapi2/interface_gen.go

This file was deleted.

10 changes: 6 additions & 4 deletions internal/hcapi2/iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ package hcapi2
import (
"context"
"strconv"

"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

// ISOClient embeds the Hetzner Cloud iso client and provides some
// additional helper functions.
type ISOClient interface {
ISOClientBase
hcloud.IISOClient
Names() []string
}

func NewISOClient(client ISOClientBase) ISOClient {
func NewISOClient(client hcloud.IISOClient) ISOClient {
return &isoClient{
ISOClientBase: client,
IISOClient: client,
}
}

type isoClient struct {
ISOClientBase
hcloud.IISOClient
}

// Names obtains a list of available data centers. It returns nil if
Expand Down
8 changes: 4 additions & 4 deletions internal/hcapi2/load_balancer_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import (
)

type LoadBalancerTypeClient interface {
LoadBalancerTypeClientBase
hcloud.ILoadBalancerTypeClient
Names() []string
LoadBalancerTypeName(id int64) string
LoadBalancerTypeDescription(id int64) string
}

func NewLoadBalancerTypeClient(client LoadBalancerTypeClientBase) LoadBalancerTypeClient {
func NewLoadBalancerTypeClient(client hcloud.ILoadBalancerTypeClient) LoadBalancerTypeClient {
return &loadBalancerTypeClient{
LoadBalancerTypeClientBase: client,
ILoadBalancerTypeClient: client,
}
}

type loadBalancerTypeClient struct {
LoadBalancerTypeClientBase
hcloud.ILoadBalancerTypeClient

lbTypeByID map[int64]*hcloud.LoadBalancerType
once sync.Once
Expand Down
8 changes: 4 additions & 4 deletions internal/hcapi2/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import (
// LoadBalancerClient embeds the Hetzner Cloud LoadBalancer client and provides some
// additional helper functions.
type LoadBalancerClient interface {
LoadBalancerClientBase
hcloud.ILoadBalancerClient
LoadBalancerName(id int64) string
Names() []string
LabelKeys(string) []string
}

func NewLoadBalancerClient(client LoadBalancerClientBase) LoadBalancerClient {
func NewLoadBalancerClient(client hcloud.ILoadBalancerClient) LoadBalancerClient {
return &loadBalancerClient{
LoadBalancerClientBase: client,
ILoadBalancerClient: client,
}
}

type loadBalancerClient struct {
LoadBalancerClientBase
hcloud.ILoadBalancerClient

lbByID map[int64]*hcloud.LoadBalancer

Expand Down
10 changes: 6 additions & 4 deletions internal/hcapi2/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@ package hcapi2
import (
"context"
"strconv"

"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

// LocationClient embeds the Hetzner Cloud Location client and provides some
// additional helper functions.
type LocationClient interface {
LocationClientBase
hcloud.ILocationClient
Names() []string
NetworkZones() []string
}

func NewLocationClient(client LocationClientBase) LocationClient {
func NewLocationClient(client hcloud.ILocationClient) LocationClient {
return &locationClient{
LocationClientBase: client,
ILocationClient: client,
}
}

type locationClient struct {
LocationClientBase
hcloud.ILocationClient
}

// Names obtains a list of available locations. It returns nil if
Expand Down
8 changes: 4 additions & 4 deletions internal/hcapi2/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import (
// NetworkClient embeds the Hetzner Cloud Network client and provides some
// additional helper functions.
type NetworkClient interface {
NetworkClientBase
hcloud.INetworkClient
Names() []string
Name(int64) string
LabelKeys(string) []string
}

func NewNetworkClient(client NetworkClientBase) NetworkClient {
func NewNetworkClient(client hcloud.INetworkClient) NetworkClient {
return &networkClient{
NetworkClientBase: client,
INetworkClient: client,
}
}

type networkClient struct {
NetworkClientBase
hcloud.INetworkClient

netsByID map[int64]*hcloud.Network
netsByName map[string]*hcloud.Network
Expand Down
10 changes: 6 additions & 4 deletions internal/hcapi2/placement_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ package hcapi2
import (
"context"
"strconv"

"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

type PlacementGroupClient interface {
PlacementGroupClientBase
hcloud.IPlacementGroupClient
Names() []string
LabelKeys(string) []string
}

func NewPlacementGroupClient(client PlacementGroupClientBase) PlacementGroupClient {
func NewPlacementGroupClient(client hcloud.IPlacementGroupClient) PlacementGroupClient {
return &placementGroupClient{
PlacementGroupClientBase: client,
IPlacementGroupClient: client,
}
}

type placementGroupClient struct {
PlacementGroupClientBase
hcloud.IPlacementGroupClient
}

func (c *placementGroupClient) Names() []string {
Expand Down
8 changes: 4 additions & 4 deletions internal/hcapi2/primaryip.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ import (
// PrimaryIPClient embeds the hcloud PrimaryIPClient (via an interface) and provides
// some additional helper functions.
type PrimaryIPClient interface {
PrimaryIPClientBase
hcloud.IPrimaryIPClient
Names() []string
IPv4Names() []string
IPv6Names() []string
LabelKeys(idOrName string) []string
}

// NewPrimaryIPClient creates a new primary IP client.
func NewPrimaryIPClient(client PrimaryIPClientBase) PrimaryIPClient {
func NewPrimaryIPClient(client hcloud.IPrimaryIPClient) PrimaryIPClient {
return &primaryIPClient{
PrimaryIPClientBase: client,
IPrimaryIPClient: client,
}
}

// PrimaryIPClient embeds the Hetzner Cloud PrimaryIP client and provides some
// additional helper functions.
type primaryIPClient struct {
PrimaryIPClientBase
hcloud.IPrimaryIPClient
}

// Names obtains a list of available primary IPs. It returns nil if
Expand Down
Loading