feat(site): add annotation to display values of type clibase.Duration correctly (#10667)

* Adds an annotation format_duration_ns to all deployment values of type clibase.Duration
* Adds a unit test that complains if you forget to add the above annotation to a clibase.Duration
* Modifies optionValue() to check for the presence of format_duration_ns when displaying an option.
This commit is contained in:
Cian Johnston
2023-11-15 12:29:20 +00:00
committed by GitHub
parent 34c9661f1b
commit 6085b92fae
4 changed files with 85 additions and 14 deletions
+21
View File
@@ -256,3 +256,24 @@ func must[T any](value T, err error) T {
}
return value
}
func TestDeploymentValues_DurationFormatNanoseconds(t *testing.T) {
t.Parallel()
set := (&codersdk.DeploymentValues{}).Options()
for _, s := range set {
if s.Value.Type() != "duration" {
continue
}
// Just make sure the annotation is set.
// If someone wants to not format a duration, they can
// explicitly set the annotation to false.
if s.Annotations.IsSet("format_duration") {
continue
}
t.Logf("Option %q is a duration but does not have the format_duration annotation.", s.Name)
t.Logf("To fix this, add the following to the option declaration:")
t.Logf(`Annotations: clibase.Annotations{}.Mark(annotationFormatDurationNS, "true"),`)
t.FailNow()
}
}