mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: archive template versions to hide them from the ui (#10179)
* api + cli implementation
This commit is contained in:
@@ -79,6 +79,17 @@ func (p *QueryParamParser) Int(vals url.Values, def int, queryParam string) int
|
||||
return v
|
||||
}
|
||||
|
||||
func (p *QueryParamParser) Boolean(vals url.Values, def bool, queryParam string) bool {
|
||||
v, err := parseQueryParam(p, vals, strconv.ParseBool, def, queryParam)
|
||||
if err != nil {
|
||||
p.Errors = append(p.Errors, codersdk.ValidationError{
|
||||
Field: queryParam,
|
||||
Detail: fmt.Sprintf("Query param %q must be a valid boolean (%s)", queryParam, err.Error()),
|
||||
})
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (p *QueryParamParser) Required(queryParam string) *QueryParamParser {
|
||||
p.RequiredParams[queryParam] = true
|
||||
return p
|
||||
|
||||
@@ -157,6 +157,48 @@ func TestParseQueryParams(t *testing.T) {
|
||||
testQueryParams(t, expParams, parser, parser.String)
|
||||
})
|
||||
|
||||
t.Run("Boolean", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expParams := []queryParamTestCase[bool]{
|
||||
{
|
||||
QueryParam: "valid_true",
|
||||
Value: "true",
|
||||
Expected: true,
|
||||
},
|
||||
{
|
||||
QueryParam: "casing",
|
||||
Value: "True",
|
||||
Expected: true,
|
||||
},
|
||||
{
|
||||
QueryParam: "all_caps",
|
||||
Value: "TRUE",
|
||||
Expected: true,
|
||||
},
|
||||
{
|
||||
QueryParam: "no_value_true_def",
|
||||
NoSet: true,
|
||||
Default: true,
|
||||
Expected: true,
|
||||
},
|
||||
{
|
||||
QueryParam: "no_value",
|
||||
NoSet: true,
|
||||
Expected: false,
|
||||
},
|
||||
|
||||
{
|
||||
QueryParam: "invalid_boolean",
|
||||
Value: "yes",
|
||||
Expected: false,
|
||||
ExpectedErrorContains: "must be a valid boolean",
|
||||
},
|
||||
}
|
||||
|
||||
parser := httpapi.NewQueryParamParser()
|
||||
testQueryParams(t, expParams, parser, parser.Boolean)
|
||||
})
|
||||
|
||||
t.Run("Int", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expParams := []queryParamTestCase[int]{
|
||||
|
||||
Reference in New Issue
Block a user