-
Notifications
You must be signed in to change notification settings - Fork 23
feat: add order to coder_metadata #450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you set Computed on an attribute, it cannot be changed. Ref: https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-behaviors#computed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will need to update the tests and run make fmt / make gen in order for CI to pass.
My suggestion would also be to add/update tests in ./integration for this change.
|
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| "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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... is ForceNew necessary @johnstcn ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change, it would be good to have a test for a non-numeric value for order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once tests pointed our by Cian are 👍 , feel free to proceed.
Closes #325