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

Commit

Permalink
Merge pull request #59 from isaacdorfman/new-test-framework
Browse files Browse the repository at this point in the history
New test framework
  • Loading branch information
bardielle authored Nov 27, 2022
2 parents d4be1c8 + bfc7006 commit a67c102
Show file tree
Hide file tree
Showing 15 changed files with 507 additions and 304 deletions.
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,24 @@ install: build
mkdir -p "$${dir}"; \
mv ${BINARY} "$${dir}/$${file}"

.PHONY: test tests
test tests: install
.PHONY: subsystem-test
subsystem-test: install
ginkgo run \
--succinct \
-ldflags="$(ldflags)" \
-r
-r \
--focus-file subsystem/.*

.PHONY: unit-test
unit-test:
ginkgo run \
--succinct \
-ldflags="$(ldflags)" \
-r \
--focus-file provider/.*

.PHONY: test tests
test tests: unit-test subsystem-test

.PHONY: fmt_go
fmt_go:
Expand Down
41 changes: 25 additions & 16 deletions provider/cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,8 @@ func (t *ClusterResourceType) NewResource(ctx context.Context,
return
}

func (r *ClusterResource) Create(ctx context.Context,
request tfsdk.CreateResourceRequest, response *tfsdk.CreateResourceResponse) {
// Get the plan:
state := &ClusterState{}
diags := request.Plan.Get(ctx, state)
response.Diagnostics.Append(diags...)
if response.Diagnostics.HasError() {
return
}

func createClusterObject(ctx context.Context,
state *ClusterState, diags diag.Diagnostics) (*cmv1.Cluster, error) {
// Create the cluster:
builder := cmv1.NewCluster()
builder.Name(state.Name.Value)
Expand Down Expand Up @@ -353,7 +345,23 @@ func (r *ClusterResource) Create(ctx context.Context,
proxy.HTTPSProxy(state.Proxy.HttpsProxy.Value)
builder.Proxy(proxy)
}

object, err := builder.Build()

return object, err
}

func (r *ClusterResource) Create(ctx context.Context,
request tfsdk.CreateResourceRequest, response *tfsdk.CreateResourceResponse) {
// Get the plan:
state := &ClusterState{}
diags := request.Plan.Get(ctx, state)
response.Diagnostics.Append(diags...)
if response.Diagnostics.HasError() {
return
}

object, err := createClusterObject(ctx, state, diags)
if err != nil {
response.Diagnostics.AddError(
"Can't build cluster",
Expand All @@ -364,6 +372,7 @@ func (r *ClusterResource) Create(ctx context.Context,
)
return
}

add, err := r.collection.Add().Body(object).SendContext(ctx)
if err != nil {
response.Diagnostics.AddError(
Expand Down Expand Up @@ -403,7 +412,7 @@ func (r *ClusterResource) Create(ctx context.Context,
}

// Save the state:
r.populateState(ctx, object, state)
populateClusterState(object, state)
diags = response.State.Set(ctx, state)
response.Diagnostics.Append(diags...)
}
Expand Down Expand Up @@ -433,7 +442,7 @@ func (r *ClusterResource) Read(ctx context.Context, request tfsdk.ReadResourceRe
object := get.Body()

// Save the state:
r.populateState(ctx, object, state)
populateClusterState(object, state)
diags = response.State.Set(ctx, state)
response.Diagnostics.Append(diags...)
}
Expand Down Expand Up @@ -495,7 +504,7 @@ func (r *ClusterResource) Update(ctx context.Context, request tfsdk.UpdateResour
object := update.Body()

// Update the state:
r.populateState(ctx, object, state)
populateClusterState(object, state)
diags = response.State.Set(ctx, state)
response.Diagnostics.Append(diags...)
}
Expand Down Expand Up @@ -570,13 +579,13 @@ func (r *ClusterResource) ImportState(ctx context.Context, request tfsdk.ImportR

// Save the state:
state := &ClusterState{}
r.populateState(ctx, object, state)
populateClusterState(object, state)
diags := response.State.Set(ctx, state)
response.Diagnostics.Append(diags...)
}

// populateState copies the data from the API object to the Terraform state.
func (r *ClusterResource) populateState(ctx context.Context, object *cmv1.Cluster, state *ClusterState) {
// populateClusterState copies the data from the API object to the Terraform state.
func populateClusterState(object *cmv1.Cluster, state *ClusterState) {
state.ID = types.String{
Value: object.ID(),
}
Expand Down
Loading

0 comments on commit a67c102

Please sign in to comment.