-
Notifications
You must be signed in to change notification settings - Fork 0
refactor code into multiple files #91
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package client | ||
|
|
||
| // ptr returns a pointer to the given value | ||
| // This helper is needed because the STACKIT SDK uses pointers for optional fields | ||
| func ptr[T any](v T) *T { | ||
| return &v | ||
| } | ||
|
|
||
| // convertLabelsToSDK converts map[string]string to *map[string]interface{} for SDK | ||
| // | ||
| //nolint:gocritic // SDK requires *map | ||
| func convertLabelsToSDK(labels map[string]string) *map[string]interface{} { | ||
| if labels == nil { | ||
| return nil | ||
| } | ||
|
|
||
| result := make(map[string]interface{}, len(labels)) | ||
| for k, v := range labels { | ||
| result[k] = v | ||
| } | ||
| return &result | ||
| } | ||
|
|
||
| // convertLabelsFromSDK converts *map[string]interface{} from SDK to map[string]string | ||
| // | ||
| //nolint:gocritic // SDK requires *map | ||
| func convertLabelsFromSDK(labels *map[string]interface{}) map[string]string { | ||
| if labels == nil { | ||
| return nil | ||
| } | ||
|
|
||
| result := make(map[string]string, len(*labels)) | ||
| for k, v := range *labels { | ||
| if strVal, ok := v.(string); ok { | ||
| result[k] = strVal | ||
| } | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| // convertStringSliceToSDK converts []string to *[]string for SDK | ||
| func convertStringSliceToSDK(slice []string) *[]string { | ||
| if slice == nil { | ||
| return nil | ||
| } | ||
| return &slice | ||
| } | ||
|
|
||
| // convertMetadataToSDK converts map[string]interface{} to *map[string]interface{} for SDK | ||
| // | ||
| //nolint:gocritic // SDK requires *map | ||
| func convertMetadataToSDK(metadata map[string]interface{}) *map[string]interface{} { | ||
| if metadata == nil { | ||
| return nil | ||
| } | ||
| return &metadata | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package mock | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
|
|
||
| "github.com/stackitcloud/machine-controller-manager-provider-stackit/pkg/client" | ||
| api "github.com/stackitcloud/machine-controller-manager-provider-stackit/pkg/provider/apis" | ||
| ) | ||
|
|
||
| // StackitClient is a mock implementation of StackitClient for testing | ||
| // Note: Single-tenant design - each client is bound to one set of credentials | ||
| type StackitClient struct { | ||
| CreateServerFunc func(ctx context.Context, projectID, region string, req *client.CreateServerRequest) (*client.Server, error) | ||
| GetServerFunc func(ctx context.Context, projectID, region, serverID string) (*client.Server, error) | ||
| DeleteServerFunc func(ctx context.Context, projectID, region, serverID string) error | ||
| ListServersFunc func(ctx context.Context, projectID, region string, labelSelector map[string]string) ([]*client.Server, error) | ||
| GetNICsFunc func(ctx context.Context, projectID, region, serverID string) ([]*client.NIC, error) | ||
| UpdateNICFunc func(ctx context.Context, projectID, region, networkID, nicID string, allowedAddresses []string) (*client.NIC, error) | ||
| } | ||
|
|
||
| func (m *StackitClient) CreateServer(ctx context.Context, projectID, region string, req *client.CreateServerRequest) (*client.Server, error) { | ||
| if m.CreateServerFunc != nil { | ||
| return m.CreateServerFunc(ctx, projectID, region, req) | ||
| } | ||
| return &client.Server{ | ||
| ID: "550e8400-e29b-41d4-a716-446655440000", | ||
| Name: req.Name, | ||
| Status: "CREATING", | ||
| }, nil | ||
| } | ||
|
|
||
| func (m *StackitClient) GetServer(ctx context.Context, projectID, region, serverID string) (*client.Server, error) { | ||
| if m.GetServerFunc != nil { | ||
| return m.GetServerFunc(ctx, projectID, region, serverID) | ||
| } | ||
| return &client.Server{ | ||
| ID: serverID, | ||
| Name: "test-machine", | ||
| Status: "ACTIVE", | ||
| }, nil | ||
| } | ||
|
|
||
| func (m *StackitClient) DeleteServer(ctx context.Context, projectID, region, serverID string) error { | ||
| if m.DeleteServerFunc != nil { | ||
| return m.DeleteServerFunc(ctx, projectID, region, serverID) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (m *StackitClient) ListServers(ctx context.Context, projectID, region string, labelSelector map[string]string) ([]*client.Server, error) { | ||
| if m.ListServersFunc != nil { | ||
| return m.ListServersFunc(ctx, projectID, region, labelSelector) | ||
| } | ||
| return []*client.Server{}, nil | ||
| } | ||
|
|
||
| func (m *StackitClient) GetNICsForServer(ctx context.Context, projectID, region, serverID string) ([]*client.NIC, error) { | ||
| if m.GetNICsFunc != nil { | ||
| return m.GetNICsFunc(ctx, projectID, region, serverID) | ||
| } | ||
| return []*client.NIC{}, nil | ||
| } | ||
|
|
||
| func (m *StackitClient) UpdateNIC(ctx context.Context, projectID, region, networkID, nicID string, allowedAddresses []string) (*client.NIC, error) { | ||
| if m.UpdateNICFunc != nil { | ||
| return m.UpdateNICFunc(ctx, projectID, region, networkID, nicID, allowedAddresses) | ||
| } | ||
| return &client.NIC{}, nil | ||
| } | ||
|
|
||
| // UpdateNIC updates a network interface | ||
|
|
||
| // encodeProviderSpec is a helper function to encode ProviderSpec for tests | ||
| func EncodeProviderSpec(spec *api.ProviderSpec) ([]byte, error) { | ||
| return json.Marshal(spec) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.