Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Dorfman committed Jan 12, 2023
1 parent ead08b8 commit 0a8678d
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions provider/cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ type ClusterClient interface {
}

type ClusterClientImpl struct {
internalClient *cmv1.ClustersClient
InternalClient *cmv1.ClustersClient
}

func (clusterClient *ClusterClientImpl) Get(ctx context.Context, id string) (*cmv1.Cluster, error) {
response, err := clusterClient.internalClient.Cluster(id).Get().SendContext(ctx)
response, err := clusterClient.InternalClient.Cluster(id).Get().SendContext(ctx)
if err != nil {
return nil, err
}
return response.Body(), nil
}

func (clusterClient *ClusterClientImpl) Create(ctx context.Context, cluster *cmv1.Cluster) (*cmv1.Cluster, error) {
response, err := clusterClient.internalClient.Add().Body(cluster).SendContext(ctx)
response, err := clusterClient.InternalClient.Add().Body(cluster).SendContext(ctx)
if err != nil {
return nil, err
}
Expand All @@ -79,7 +79,7 @@ func (clusterClient *ClusterClientImpl) Create(ctx context.Context, cluster *cmv
func (clusterClient *ClusterClientImpl) PollReady(ctx context.Context, id string) error {
pollCtx, cancel := context.WithTimeout(ctx, 1*time.Hour)
defer cancel()
_, err := clusterClient.internalClient.Cluster(id).Poll().
_, err := clusterClient.InternalClient.Cluster(id).Poll().
Interval(30 * time.Second).
Predicate(func(get *cmv1.ClusterGetResponse) bool {
object := get.Body()
Expand All @@ -96,7 +96,7 @@ func (clusterClient *ClusterClientImpl) PollReady(ctx context.Context, id string
func (clusterClient *ClusterClientImpl) PollRemoved(ctx context.Context, id string) error {
pollCtx, cancel := context.WithTimeout(ctx, 10*time.Minute)
defer cancel()
_, err := clusterClient.internalClient.Cluster(id).Poll().
_, err := clusterClient.InternalClient.Cluster(id).Poll().
Interval(30 * time.Second).
Status(http.StatusNotFound).
StartContext(pollCtx)
Expand All @@ -112,7 +112,7 @@ func (clusterClient *ClusterClientImpl) PollRemoved(ctx context.Context, id stri
}

func (clusterClient *ClusterClientImpl) Update(ctx context.Context, id string, patch *cmv1.Cluster) (*cmv1.Cluster, error) {
update, err := clusterClient.internalClient.Cluster(id).Update().
update, err := clusterClient.InternalClient.Cluster(id).Update().
Body(patch).
SendContext(ctx)
if err != nil {
Expand All @@ -122,7 +122,7 @@ func (clusterClient *ClusterClientImpl) Update(ctx context.Context, id string, p
}

func (clusterClient *ClusterClientImpl) Delete(ctx context.Context, id string) error {
_, err := clusterClient.internalClient.Cluster(id).Delete().SendContext(ctx)
_, err := clusterClient.InternalClient.Cluster(id).Delete().SendContext(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -515,7 +515,9 @@ func (r *ClusterResource) Create(ctx context.Context,
return
}

clusterUtils := ClusterResourceUtilsImpl{}
clusterClient := &ClusterClientImpl{InternalClient: r.collection}

clusterUtils := ClusterResourceUtilsImpl{clusterClient: clusterClient}

err := clusterUtils.create(ctx, state, &diags)
if err != nil {
Expand All @@ -536,7 +538,8 @@ func (r *ClusterResource) Read(ctx context.Context, request tfsdk.ReadResourceRe
return
}

clusterUtils := ClusterResourceUtilsImpl{}
clusterClient := &ClusterClientImpl{InternalClient: r.collection}
clusterUtils := ClusterResourceUtilsImpl{clusterClient: clusterClient}

// Find the cluster:
get, err := r.collection.Cluster(state.ID.Value).Get().SendContext(ctx)
Expand Down Expand Up @@ -619,7 +622,9 @@ func (r *ClusterResource) Update(ctx context.Context, request tfsdk.UpdateResour
return
}

clusterUtils := ClusterResourceUtilsImpl{}
clusterClient := &ClusterClientImpl{InternalClient: r.collection}

clusterUtils := ClusterResourceUtilsImpl{clusterClient: clusterClient}
err := clusterUtils.update(ctx, state, plan, &diags)
if err != nil {
return
Expand Down Expand Up @@ -671,7 +676,9 @@ func (r *ClusterResource) Delete(ctx context.Context, request tfsdk.DeleteResour
return
}

clusterUtils := ClusterResourceUtilsImpl{}
clusterClient := &ClusterClientImpl{InternalClient: r.collection}

clusterUtils := ClusterResourceUtilsImpl{clusterClient: clusterClient}
shouldPoll := state.Wait.Unknown || state.Wait.Null || state.Wait.Value
err := clusterUtils.delete(ctx, state.ID.Value, shouldPoll, &diags)
if err != nil {
Expand Down

0 comments on commit 0a8678d

Please sign in to comment.