Conversation
provider/metadata.go
Outdated
| Type: schema.TypeInt, | ||
| Description: "The order determines the position of item in the UI presentation. The lowest order is shown first and items with equal order are sorted by key (ascending order).", | ||
| ForceNew: true, | ||
| Computed: true, |
There was a problem hiding this comment.
If you set Computed on an attribute, it cannot be changed. Ref: https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-behaviors#computed
|
@johnstcn I have updated the Do you have any idea why? |
|
@johnstcn about adding an integration test for this, I think this change is simple enough to be tested only in the |
Purely out of paranoia, but it's only a suggestion. |
provider/metadata_test.go
Outdated
| item { | ||
| key = "foo" | ||
| value = "bar" | ||
| order = 4 |
There was a problem hiding this comment.
Can you add more test cases?
- All items have
orderpresent. - Order is negative.
- Only a few items have
orderpresent
There was a problem hiding this comment.
I think we can have 1 and 3 on the same test. We can just add orders to all the items and leave one empty and check if it is set to 0(the expected default value).
About 2, I don't see we handling that in any other part of the provider for app or agent metadata order, but putting some thoughts on that, I think it should not be a problem since you can still sort things by negative numbers.
| "order": { | ||
| Type: schema.TypeInt, | ||
| Description: "The order determines the position of item in the UI presentation. The lowest order is shown first and items with equal order are sorted by key (ascending order).", | ||
| ForceNew: true, |
There was a problem hiding this comment.
I'm not 100% sure, but it is already used in agent.metadata.order so it may be no harm to be safe and stick to the status quo.
provider/metadata_test.go
Outdated
| "item.0.key": "foo", | ||
| "item.0.value": "bar", | ||
| "item.0.sensitive": "false", | ||
| "item.0.order": "4", |
There was a problem hiding this comment.
BTW this is not enough for metadata items. See the comment on top of this function.
PS. VS code debugger is very handy when dealing with Terraform schema.
|
@johnstcn related to the integration tests, what |
If you set In CI, the integration tests run against three different versions (from
So basically if a particular integration test only makes sense to run from a particular Coder version onwards, you set |
provider/provider.go
Outdated
| return nil | ||
| } | ||
| var valueAsInt int64 | ||
| gocty.FromCtyValue(value, &valueAsInt) |
There was a problem hiding this comment.
This can return an error, so we may to modify the return signature to (interface{}, error) and handle it in the calling function.
| func valueAsInt(value cty.Value) (interface{}, error) { | ||
| if value.IsNull() { | ||
| return nil, nil | ||
| } | ||
| var valueAsInt int64 | ||
| err := gocty.FromCtyValue(value, &valueAsInt) | ||
| return valueAsInt, err | ||
| } |
There was a problem hiding this comment.
With this change, it would be good to have a test for a non-numeric value for order.
mtojek
left a comment
There was a problem hiding this comment.
Once tests pointed our by Cian are 👍 , feel free to proceed.
Closes #325