From feb823a021a544819c1f9cf50c55edee79fecf06 Mon Sep 17 00:00:00 2001 From: thxCode Date: Sun, 18 Jun 2023 14:31:23 +0800 Subject: [PATCH] refactor: shift up cost field Signed-off-by: thxCode --- byteset/resource_pipeline.go | 12 ++++++------ byteset/resource_pipeline_test.go | 16 ++++++++-------- docs/resources/pipeline.md | 5 +---- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/byteset/resource_pipeline.go b/byteset/resource_pipeline.go index 7ed4f64..649e6d3 100644 --- a/byteset/resource_pipeline.go +++ b/byteset/resource_pipeline.go @@ -41,7 +41,6 @@ type ResourcePipelineDestination struct { ConnMax types.Int64 `tfsdk:"conn_max"` BatchCap types.Int64 `tfsdk:"batch_cap"` Salt types.String `tfsdk:"salt"` - Cost types.String `tfsdk:"cost"` } func (r ResourcePipelineDestination) Reflect(ctx context.Context) (pipeline.Destination, error) { @@ -58,6 +57,7 @@ type ResourcePipeline struct { Source ResourcePipelineSource `tfsdk:"source"` Destination ResourcePipelineDestination `tfsdk:"destination"` Timeouts timeouts.Value `tfsdk:"timeouts"` + Cost types.String `tfsdk:"cost"` } func (r ResourcePipeline) Corrupted() bool { @@ -170,16 +170,16 @@ choose from local/remote SQL file or database. Description: `The salt assist calculating the destination database has changed but the address not, like the database Terraform Managed Resource ID.`, }, - "cost": schema.StringAttribute{ - Computed: true, - Description: `The time consumption of this transfer.`, - }, }, }, "timeouts": timeouts.Attributes(ctx, timeouts.Opts{ Create: true, Update: true, }), + "cost": schema.StringAttribute{ + Computed: true, + Description: `The time spent on this transfer.`, + }, }, } } @@ -242,7 +242,7 @@ func (r ResourcePipeline) Create(ctx context.Context, req resource.CreateRequest return } - plan.Destination.Cost = types.StringValue(time.Since(start).String()) + plan.Cost = types.StringValue(time.Since(start).String()) plan.Read( ctx, diff --git a/byteset/resource_pipeline_test.go b/byteset/resource_pipeline_test.go index 715643e..44fbbb7 100644 --- a/byteset/resource_pipeline_test.go +++ b/byteset/resource_pipeline_test.go @@ -80,7 +80,7 @@ INSERT INTO company (name, age, address, salary) VALUES ('James', 24, 'Houston', ), resource.TestCheckResourceAttr(resourceName, "destination.address", basicDst), resource.TestCheckResourceAttr(resourceName, "destination.conn_max", "1"), - resource.TestCheckResourceAttrSet(resourceName, "destination.cost"), + resource.TestCheckResourceAttrSet(resourceName, "cost"), ), }, }, @@ -151,7 +151,7 @@ INSERT INTO company (name, age, address, salary) VALUES ('James', 24, 'Houston', resource.TestCheckResourceAttr(resourceName, "source.address", basicSrc), resource.TestCheckResourceAttr(resourceName, "destination.address", basicDst), resource.TestCheckResourceAttr(resourceName, "destination.conn_max", "10"), - resource.TestCheckResourceAttrSet(resourceName, "destination.cost"), + resource.TestCheckResourceAttrSet(resourceName, "cost"), ), }, }, @@ -210,7 +210,7 @@ func TestAccResourcePipeline_file_to_mysql(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "source.address", basicSrc), resource.TestCheckResourceAttr(resourceName, "destination.address", basicDst), resource.TestCheckResourceAttr(resourceName, "destination.conn_max", "5"), - resource.TestCheckResourceAttrSet(resourceName, "destination.cost"), + resource.TestCheckResourceAttrSet(resourceName, "cost"), ), }, { @@ -219,7 +219,7 @@ func TestAccResourcePipeline_file_to_mysql(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "source.address", fkSrc), resource.TestCheckResourceAttr(resourceName, "destination.address", fkDst), resource.TestCheckResourceAttr(resourceName, "destination.conn_max", "5"), - resource.TestCheckResourceAttrSet(resourceName, "destination.cost"), + resource.TestCheckResourceAttrSet(resourceName, "cost"), ), }, { @@ -228,7 +228,7 @@ func TestAccResourcePipeline_file_to_mysql(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "source.address", largeSrc), resource.TestCheckResourceAttr(resourceName, "destination.address", largeDst), resource.TestCheckResourceAttr(resourceName, "destination.conn_max", "5"), - resource.TestCheckResourceAttrSet(resourceName, "destination.cost"), + resource.TestCheckResourceAttrSet(resourceName, "cost"), ), }, }, @@ -288,7 +288,7 @@ func TestAccResourcePipeline_file_to_postgres(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "source.address", basicSrc), resource.TestCheckResourceAttr(resourceName, "destination.address", basicDst), resource.TestCheckResourceAttr(resourceName, "destination.conn_max", "10"), - resource.TestCheckResourceAttrSet(resourceName, "destination.cost"), + resource.TestCheckResourceAttrSet(resourceName, "cost"), ), }, { @@ -297,7 +297,7 @@ func TestAccResourcePipeline_file_to_postgres(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "source.address", fkSrc), resource.TestCheckResourceAttr(resourceName, "destination.address", fkDst), resource.TestCheckResourceAttr(resourceName, "destination.conn_max", "10"), - resource.TestCheckResourceAttrSet(resourceName, "destination.cost"), + resource.TestCheckResourceAttrSet(resourceName, "cost"), ), }, { @@ -306,7 +306,7 @@ func TestAccResourcePipeline_file_to_postgres(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "source.address", largeSrc), resource.TestCheckResourceAttr(resourceName, "destination.address", largeDst), resource.TestCheckResourceAttr(resourceName, "destination.conn_max", "10"), - resource.TestCheckResourceAttrSet(resourceName, "destination.cost"), + resource.TestCheckResourceAttrSet(resourceName, "cost"), ), }, }, diff --git a/docs/resources/pipeline.md b/docs/resources/pipeline.md index bc829c9..45de2db 100644 --- a/docs/resources/pipeline.md +++ b/docs/resources/pipeline.md @@ -39,6 +39,7 @@ resource "byteset_pipeline" "example" { ### Read-Only +- `cost` (String) The time spent on this transfer. - `id` (String) The ID of this resource. @@ -62,10 +63,6 @@ Optional: - `salt` (String) The salt assist calculating the destination database has changed but the address not, like the database Terraform Managed Resource ID. -Read-Only: - -- `cost` (String) The time consumption of this transfer. - ### Nested Schema for `source`