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

add unittests for linodevpc_controller #284

Merged
merged 3 commits into from
Apr 30, 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
3 changes: 3 additions & 0 deletions cloud/scope/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type LinodeInstanceClient interface {
// LinodeVPCClient defines the methods that a Linode client must have to interact with Linode's VPC service.
type LinodeVPCClient interface {
GetVPC(ctx context.Context, vpcID int) (*linodego.VPC, error)
ListVPCs(ctx context.Context, opts *linodego.ListOptions) ([]linodego.VPC, error)
CreateVPC(ctx context.Context, opts linodego.VPCCreateOptions) (*linodego.VPC, error)
DeleteVPC(ctx context.Context, vpcID int) error
}

// LinodeNodeBalancerClient defines the methods that a Linode client must have to interact with Linode's Node Balancer service.
Expand Down
7 changes: 3 additions & 4 deletions cloud/scope/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"errors"
"fmt"

"github.com/linode/linodego"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

Expand All @@ -30,10 +29,10 @@ import (

// VPCScope defines the basic context for an actuator to operate upon.
type VPCScope struct {
client K8sClient
Client K8sClient

PatchHelper *patch.Helper
LinodeClient *linodego.Client
LinodeClient LinodeVPCClient
LinodeVPC *infrav1alpha1.LinodeVPC
}

Expand Down Expand Up @@ -77,7 +76,7 @@ func NewVPCScope(ctx context.Context, apiKey string, params VPCScopeParams) (*VP
}

return &VPCScope{
client: params.Client,
Client: params.Client,
LinodeClient: linodeClient,
LinodeVPC: params.LinodeVPC,
PatchHelper: helper,
Expand Down
8 changes: 4 additions & 4 deletions controller/linodevpc_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@
return ctrl.Result{}, fmt.Errorf("failed to create VPC scope: %w", err)
}

return r.reconcile(ctx, vpcScope, log)
return r.reconcile(ctx, log, vpcScope)

Check warning on line 103 in controller/linodevpc_controller.go

View check run for this annotation

Codecov / codecov/patch

controller/linodevpc_controller.go#L103

Added line #L103 was not covered by tests
}

func (r *LinodeVPCReconciler) reconcile(
ctx context.Context,
vpcScope *scope.VPCScope,
logger logr.Logger,
vpcScope *scope.VPCScope,
) (res ctrl.Result, err error) {
res = ctrl.Result{}

Expand Down Expand Up @@ -167,12 +167,12 @@
// Create
failureReason = infrav1alpha1.CreateVPCError

err = r.reconcileCreate(ctx, vpcScope, logger)
err = r.reconcileCreate(ctx, logger, vpcScope)

Check warning on line 170 in controller/linodevpc_controller.go

View check run for this annotation

Codecov / codecov/patch

controller/linodevpc_controller.go#L170

Added line #L170 was not covered by tests

return
}

func (r *LinodeVPCReconciler) reconcileCreate(ctx context.Context, vpcScope *scope.VPCScope, logger logr.Logger) error {
func (r *LinodeVPCReconciler) reconcileCreate(ctx context.Context, logger logr.Logger, vpcScope *scope.VPCScope) error {
logger.Info("creating vpc")

if err := r.reconcileVPC(ctx, vpcScope, logger); err != nil {
Expand Down
Loading
Loading