Skip to content

Commit 586c9ca

Browse files
committed
...
1 parent 4460b26 commit 586c9ca

4 files changed

Lines changed: 17 additions & 12 deletions

File tree

hcloud/cloud_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/syself/hetzner-cloud-controller-manager/internal/annotation"
3535
"github.com/syself/hetzner-cloud-controller-manager/internal/credentials"
3636
"github.com/syself/hetzner-cloud-controller-manager/internal/hcops"
37+
robotclient "github.com/syself/hetzner-cloud-controller-manager/internal/robot/client"
3738
hrobot "github.com/syself/hrobot-go"
3839
"github.com/syself/hrobot-go/models"
3940
corev1 "k8s.io/api/core/v1"
@@ -44,7 +45,15 @@ type testEnv struct {
4445
Server *httptest.Server
4546
Mux *http.ServeMux
4647
Client *hcloud.Client
47-
RobotClient hrobot.RobotClient
48+
RobotClient robotclient.Client
49+
}
50+
51+
type testRobotClient struct {
52+
hrobot.RobotClient
53+
}
54+
55+
func (c testRobotClient) ServerGetListForceRefresh() ([]models.Server, error) {
56+
return c.ServerGetList()
4857
}
4958

5059
func (env *testEnv) Teardown() {
@@ -70,7 +79,7 @@ func newTestEnv() testEnv {
7079
Server: server,
7180
Mux: mux,
7281
Client: client,
73-
RobotClient: robotClient,
82+
RobotClient: testRobotClient{RobotClient: robotClient},
7483
}
7584
}
7685

hcloud/util.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ import (
3535
// youngRobotServerLookupWindow limits forced Robot refreshes to newly created nodes.
3636
var youngRobotServerLookupWindow = 10 * time.Minute
3737

38-
type robotServerListForceRefreshClient interface {
39-
ServerGetListForceRefresh() ([]models.Server, error)
40-
}
41-
4238
func getHCloudServerByName(ctx context.Context, c *hcloud.Client, name string) (*hcloud.Server, error) {
4339
const op = "hcloud/getServerByName"
4440
metrics.OperationCalled.WithLabelValues(op).Inc()
@@ -85,12 +81,7 @@ func getRobotServerByName(c robotclient.Client, node *corev1.Node) (server *mode
8581
return server, nil
8682
}
8783

88-
forceRefreshClient, ok := c.(robotServerListForceRefreshClient)
89-
if !ok {
90-
return nil, nil
91-
}
92-
93-
serverList, err = forceRefreshClient.ServerGetListForceRefresh()
84+
serverList, err = c.ServerGetListForceRefresh()
9485
if err != nil {
9586
hcops.HandleRateLimitExceededError(err, node)
9687
return nil, fmt.Errorf("%s: refresh for young node: %w", op, err)

internal/mocks/robot.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ func (m *RobotClient) ServerGetList() ([]models.Server, error) {
1414
return getRobotServers(args, 0), args.Error(1)
1515
}
1616

17+
func (m *RobotClient) ServerGetListForceRefresh() ([]models.Server, error) {
18+
return m.ServerGetList()
19+
}
20+
1721
func (m *RobotClient) SetCredentials(_, _ string) error {
1822
args := m.Called()
1923
return args.Error(3)

internal/robot/client/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ import "github.com/syself/hrobot-go/models"
55
type Client interface {
66
ServerGet(id int) (*models.Server, error)
77
ServerGetList() ([]models.Server, error)
8+
ServerGetListForceRefresh() ([]models.Server, error)
89
SetCredentials(username, password string) error
910
}

0 commit comments

Comments
 (0)