mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
fix: Sort ComputedValue
according to parameter schema index (#3022)
This fixes a test-flake in TestTemplateVersionParameters/List and gives us consistent sorting for parameters.
This commit is contained in:
committed by
GitHub
parent
c0d19ebea2
commit
3a692a6cdb
@ -6,6 +6,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/coder/coder/coderd/database"
|
"github.com/coder/coder/coderd/database"
|
||||||
@ -32,6 +33,7 @@ type ComputedValue struct {
|
|||||||
database.ParameterValue
|
database.ParameterValue
|
||||||
SchemaID uuid.UUID `json:"schema_id"`
|
SchemaID uuid.UUID `json:"schema_id"`
|
||||||
DefaultSourceValue bool `json:"default_source_value"`
|
DefaultSourceValue bool `json:"default_source_value"`
|
||||||
|
index int32 // Track parameter schema index for sorting.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute accepts a scope in which parameter values are sourced.
|
// Compute accepts a scope in which parameter values are sourced.
|
||||||
@ -137,6 +139,9 @@ func Compute(ctx context.Context, db database.Store, scope ComputeScope, options
|
|||||||
for _, value := range compute.computedParameterByName {
|
for _, value := range compute.computedParameterByName {
|
||||||
values = append(values, value)
|
values = append(values, value)
|
||||||
}
|
}
|
||||||
|
slices.SortFunc(values, func(a, b ComputedValue) bool {
|
||||||
|
return a.index < b.index
|
||||||
|
})
|
||||||
return values, nil
|
return values, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,6 +193,7 @@ func (c *compute) injectSingle(scopedParameter database.ParameterValue, defaultV
|
|||||||
ParameterValue: scopedParameter,
|
ParameterValue: scopedParameter,
|
||||||
SchemaID: parameterSchema.ID,
|
SchemaID: parameterSchema.ID,
|
||||||
DefaultSourceValue: defaultValue,
|
DefaultSourceValue: defaultValue,
|
||||||
|
index: parameterSchema.Index,
|
||||||
}
|
}
|
||||||
if c.options.HideRedisplayValues && !parameterSchema.RedisplayValue {
|
if c.options.HideRedisplayValues && !parameterSchema.RedisplayValue {
|
||||||
value.SourceValue = ""
|
value.SourceValue = ""
|
||||||
|
Reference in New Issue
Block a user