fix: set preset parameters in the API rather than the frontend (#17403)

Follow-up from a [previous Pull
Request](https://github.com/coder/coder/pull/16965) required some
additional testing of Presets from the API perspective.

In the process of adding the new tests, I updated the API to enforce
preset parameter values based on the selected preset instead of trusting
whichever frontend makes the request. This avoids errors scenarios in
prebuilds where a prebuild might expect a certain preset but find a
different set of actual parameter values.
This commit is contained in:
Sas Swart
2025-04-16 15:54:06 +02:00
committed by GitHub
parent d78215cdcb
commit 64172d374f
4 changed files with 387 additions and 46 deletions

View File

@ -66,6 +66,19 @@ func Contains[T comparable](haystack []T, needle T) bool {
})
}
func CountMatchingPairs[A, B any](a []A, b []B, match func(A, B) bool) int {
count := 0
for _, a := range a {
for _, b := range b {
if match(a, b) {
count++
break
}
}
}
return count
}
// Find returns the first element that satisfies the condition.
func Find[T any](haystack []T, cond func(T) bool) (T, bool) {
for _, hay := range haystack {