Skip to content

Commit

Permalink
fix(warehouse|bigquery): read operation - inconsistent data collector…
Browse files Browse the repository at this point in the history
… uuid fixed tests
  • Loading branch information
ndopj committed Oct 4, 2023
1 parent 2c238ff commit 4ed06ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
11 changes: 5 additions & 6 deletions monte_carlo/resources/bigquery_warehouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,14 @@ func (r *BigQueryWarehouseResource) Delete(ctx context.Context, req resource.Del
}

func (r *BigQueryWarehouseResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
if idsImported := strings.Split(req.ID, ","); len(idsImported) == 2 && idsImported[0] != "" && idsImported[1] != "" {
idsImported := strings.Split(req.ID, ",")
if len(idsImported) == 3 && idsImported[0] != "" && idsImported[1] != "" && idsImported[2] != "" {
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("uuid"), idsImported[0])...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("connection_uuid"), idsImported[1])...)
// since the Read operation is not capable of reading service_account_key - force its update right after import
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("service_account_key"), (*string)(nil))...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("data_collector_uuid"), idsImported[2])...)
} else {
resp.Diagnostics.AddError(
"Unexpected Import Identifier",
fmt.Sprintf("Expected import identifier with format: <warehouse_uuid>,<connection_uuid>. Got: %q", req.ID),
resp.Diagnostics.AddError("Unexpected Import Identifier", fmt.Sprintf(
"Expected import identifier with format: <warehouse_uuid>,<connection_uuid>,<data_collector_uuid>. Got: %q", req.ID),
)
}
}
Expand Down
8 changes: 4 additions & 4 deletions monte_carlo/resources/bigquery_warehouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func TestAccBigQueryWarehouseResource(t *testing.T) {
ResourceName: "montecarlo_bigquery_warehouse.test",
ImportState: true,
ImportStateVerify: true,
ImportStateId: "8bfc4,8cd5a",
ImportStateId: "8bfc4,8cd5a,dataCollector1",
ImportStateVerifyIdentifierAttribute: "uuid",
ImportStateVerifyIgnore: []string{"data_collector_uuid", "deletion_protection", "service_account_key"},
ImportStateVerifyIgnore: []string{"deletion_protection", "service_account_key"},
},
// Update and Read testing
{
Expand Down Expand Up @@ -98,7 +98,7 @@ func initMonteCarloClient() client.MonteCarloClient {
// Read operations
readQuery := "query getWarehouse($uuid: UUID) { getWarehouse(uuid: $uuid) { name,connections{uuid,type} } }"
readVariables1 := map[string]interface{}{"uuid": client.UUID("8bfc4")}
readResponse1 := []byte(`{"getWarehouse":{"name":"name1","connections":[{"uuid":"8cd5a"}]}}`)
readResponse1 := []byte(`{"getWarehouse":{"name":"name1","connections":[{"uuid":"8cd5a"}],"dataCollector":{"uuid":"dataCollector1"}}}`)
mcClient.On("ExecRaw", mock.Anything, readQuery, readVariables1).Return(readResponse1, nil)

// Delete operations
Expand All @@ -120,7 +120,7 @@ func initMonteCarloClient() client.MonteCarloClient {
arg.UpdateCredentials.Success = true
// after update, read operation must return new results
mcClient.On("ExecRaw", mock.Anything, readQuery, readVariables1).Unset()
readResponse := []byte(`{"getWarehouse":{"name":"name2","connections":[{"uuid":"8cd5a"}]}}`)
readResponse := []byte(`{"getWarehouse":{"name":"name2","connections":[{"uuid":"8cd5a"}],"dataCollector":{"uuid":"dataCollector1"}}}`)
mcClient.On("ExecRaw", mock.Anything, readQuery, readVariables1).Return(readResponse, nil)
})
return &mcClient
Expand Down

0 comments on commit 4ed06ce

Please sign in to comment.