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

Return error on unknown server types #151

Merged
merged 5 commits into from
Jun 16, 2024
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
8 changes: 8 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
all: true
disable-version-string: true
outpkg: 'mocks'
packages:
go.woodpecker-ci.org/autoscaler/providers/hetznercloud/hcapi:
config:
dir: 'providers/hetznercloud/{{.PackageName}}/mocks'
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ install-tools: ## Install development tools
hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go install mvdan.cc/gofumpt@latest; \
fi ; \
hash mockery > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go install github.com/vektra/mockery/v2@latest; \
fi ; \

##@ Test

Expand All @@ -91,6 +94,10 @@ test-autoscaler: ## Test autoscaler code
.PHONY: test
test: test-autoscaler ## Run all tests

.PHONY: generate
generate:
mockery

##@ Build

build:
Expand Down
18 changes: 9 additions & 9 deletions engine/stringmaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ func TestSliceToMap(t *testing.T) {
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
actual, err := SliceToMap(tc.input, tc.del)
if tc.wantErr != nil {
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
actual, err := SliceToMap(tt.input, tt.del)
if tt.wantErr != nil {
assert.Error(t, err)

return
}

assert.NoError(t, err)
assert.Equal(t, tc.want, actual)
assert.Equal(t, tt.want, actual)
})
}
}
Expand Down Expand Up @@ -85,10 +85,10 @@ func TestMergeMaps(t *testing.T) {
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
merged := MergeMaps(tc.m1, tc.m2)
assert.Equal(t, tc.want, merged)
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
merged := MergeMaps(tt.m1, tt.m2)
assert.Equal(t, tt.want, merged)
})
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require (
github.com/prometheus/common v0.54.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
Expand Down
132 changes: 132 additions & 0 deletions providers/hetznercloud/hcapi/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package hcapi

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

type Client interface {
Firewall() FirewallClient
Image() ImageClient
Network() NetworkClient
Server() ServerClient
ServerType() ServerTypeClient
SSHKey() SSHKeyClient
}

type client struct {
client *hcloud.Client
}

type ServerTypeClient interface {
hcloud.IServerTypeClient
}

type serverTypeClient struct {
hcloud.IServerTypeClient
}

type ImageClient interface {
hcloud.IImageClient
}

type imageClient struct {
hcloud.IImageClient
}

type SSHKeyClient interface {
hcloud.ISSHKeyClient
}

type sshKeyClient struct {
hcloud.ISSHKeyClient
}

type ServerClient interface {
hcloud.IServerClient
}

type serverClient struct {
hcloud.IServerClient
}

type NetworkClient interface {
hcloud.INetworkClient
}

type networkClient struct {
hcloud.INetworkClient
}

type FirewallClient interface {
hcloud.IFirewallClient
}

type firewallClient struct {
hcloud.IFirewallClient
}

func NewClient(opts ...hcloud.ClientOption) Client {
return &client{
client: hcloud.NewClient(opts...),
}
}

func NewServerTypeClient(client hcloud.IServerTypeClient) ServerTypeClient {
return &serverTypeClient{
IServerTypeClient: client,
}
}

func (c *client) ServerType() ServerTypeClient {
return NewServerTypeClient(&c.client.ServerType)
anbraten marked this conversation as resolved.
Show resolved Hide resolved
}

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

func (c *client) Image() ImageClient {
return NewImageClient(&c.client.Image)
}

func NewSSHKeyClient(client hcloud.ISSHKeyClient) SSHKeyClient {
return &sshKeyClient{
ISSHKeyClient: client,
}
}

func (c *client) SSHKey() SSHKeyClient {
return NewSSHKeyClient(&c.client.SSHKey)
}

func NewServerClient(client *hcloud.ServerClient) ServerClient {
return &serverClient{
IServerClient: client,
}
}

func (c *client) Server() ServerClient {
return NewServerClient(&c.client.Server)
}

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

func (c *client) Firewall() FirewallClient {
return NewFirewallClient(&c.client.Firewall)
}

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

func (c *client) Network() NetworkClient {
return NewNetworkClient(&c.client.Network)
}
Loading