-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore_mocks_test.go
More file actions
61 lines (52 loc) · 2.11 KB
/
core_mocks_test.go
File metadata and controls
61 lines (52 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package provider
import (
"context"
api "github.com/stackitcloud/machine-controller-manager-provider-stackit/pkg/provider/apis"
)
// mockStackitClient is a mock implementation of StackitClient for testing
// Note: Single-tenant design - each client is bound to one set of credentials
type mockStackitClient struct {
createServerFunc func(ctx context.Context, projectID, region string, req *CreateServerRequest) (*Server, error)
getServerFunc func(ctx context.Context, projectID, region, serverID string) (*Server, error)
deleteServerFunc func(ctx context.Context, projectID, region, serverID string) error
listServersFunc func(ctx context.Context, projectID, region, labelSelector string) ([]*Server, error)
}
func (m *mockStackitClient) CreateServer(ctx context.Context, projectID, region string, req *CreateServerRequest) (*Server, error) {
if m.createServerFunc != nil {
return m.createServerFunc(ctx, projectID, region, req)
}
return &Server{
ID: "550e8400-e29b-41d4-a716-446655440000",
Name: req.Name,
Status: "CREATING",
}, nil
}
func (m *mockStackitClient) GetServer(ctx context.Context, projectID, region, serverID string) (*Server, error) {
if m.getServerFunc != nil {
return m.getServerFunc(ctx, projectID, region, serverID)
}
return &Server{
ID: serverID,
Name: "test-machine",
Status: "RUNNING",
}, nil
}
func (m *mockStackitClient) DeleteServer(ctx context.Context, projectID, region, serverID string) error {
if m.deleteServerFunc != nil {
return m.deleteServerFunc(ctx, projectID, region, serverID)
}
return nil
}
func (m *mockStackitClient) ListServers(ctx context.Context, projectID, region, labelSelector string) ([]*Server, error) {
if m.listServersFunc != nil {
return m.listServersFunc(ctx, projectID, region, labelSelector)
}
return []*Server{}, nil
}
// encodeProviderSpec is a helper function to encode ProviderSpec for tests
func encodeProviderSpec(spec *api.ProviderSpec) ([]byte, error) {
return encodeProviderSpecForResponse(spec)
}