Skip to content

Commit

Permalink
refactor: shift up cost field
Browse files Browse the repository at this point in the history
Signed-off-by: thxCode <[email protected]>
  • Loading branch information
thxCode committed Jun 18, 2023
1 parent 258aabb commit feb823a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
12 changes: 6 additions & 6 deletions byteset/resource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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.`,
},
},
}
}
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions byteset/resource_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
Expand Down Expand Up @@ -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"),
),
},
},
Expand Down Expand Up @@ -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"),
),
},
{
Expand All @@ -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"),
),
},
{
Expand All @@ -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"),
),
},
},
Expand Down Expand Up @@ -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"),
),
},
{
Expand All @@ -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"),
),
},
{
Expand All @@ -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"),
),
},
},
Expand Down
5 changes: 1 addition & 4 deletions docs/resources/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<a id="nestedatt--destination"></a>
Expand All @@ -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.


<a id="nestedatt--source"></a>
### Nested Schema for `source`
Expand Down

0 comments on commit feb823a

Please sign in to comment.