From 4ed06ce31bd7e17a55394d590c7a85d0473f13d9 Mon Sep 17 00:00:00 2001 From: ndopj Date: Wed, 4 Oct 2023 10:54:07 +0200 Subject: [PATCH] fix(warehouse|bigquery): read operation - inconsistent data collector uuid fixed tests --- monte_carlo/resources/bigquery_warehouse.go | 11 +++++------ monte_carlo/resources/bigquery_warehouse_test.go | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/monte_carlo/resources/bigquery_warehouse.go b/monte_carlo/resources/bigquery_warehouse.go index b53c201..85bfb6d 100644 --- a/monte_carlo/resources/bigquery_warehouse.go +++ b/monte_carlo/resources/bigquery_warehouse.go @@ -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: ,. Got: %q", req.ID), + resp.Diagnostics.AddError("Unexpected Import Identifier", fmt.Sprintf( + "Expected import identifier with format: ,,. Got: %q", req.ID), ) } } diff --git a/monte_carlo/resources/bigquery_warehouse_test.go b/monte_carlo/resources/bigquery_warehouse_test.go index 91fdcf8..5288618 100644 --- a/monte_carlo/resources/bigquery_warehouse_test.go +++ b/monte_carlo/resources/bigquery_warehouse_test.go @@ -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 { @@ -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 @@ -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