Convert bool string comparisons to strconv.ParseBool for REST parameters (#13650)
* Convert bool string comparisons to strconv.ParseBool for REST parameters * Log failed bool conversions * Rename errors, changed log levels * drop strconv.ParseBool error handling If the query string parameter is omitted, strconv.ParseBool returns an error for the empty strings, which spams the logs. Instead, just assume the default semantics of a `false` return value if an error occurs. * allow randomized Client4 booleans It's hard to test api4's handling of the various boolean input values accepted. Extend Client4 with support for overriding how it builds those strings, and pick a random value on test startup. * gofmt -s Co-authored-by: mattermod <mattermod@users.noreply.github.com> Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com> Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f7a91c7cf9
Коммит
2135096d88
@@ -6,6 +6,7 @@ package api4
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -153,6 +154,16 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
|
||||
th.Client = th.CreateClient()
|
||||
th.SystemAdminClient = th.CreateClient()
|
||||
|
||||
// Verify handling of the supported true/false values by randomizing on each run.
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
trueValues := []string{"1", "t", "T", "TRUE", "true", "True"}
|
||||
falseValues := []string{"0", "f", "F", "FALSE", "false", "False"}
|
||||
trueString := trueValues[rand.Intn(len(trueValues))]
|
||||
falseString := falseValues[rand.Intn(len(falseValues))]
|
||||
mlog.Debug("Configured Client4 bool string values", mlog.String("true", trueString), mlog.String("false", falseString))
|
||||
th.Client.SetBoolString(true, trueString)
|
||||
th.Client.SetBoolString(false, falseString)
|
||||
|
||||
th.LocalClient = th.CreateLocalClient(*config.ServiceSettings.LocalModeSocketLocation)
|
||||
|
||||
if th.tempWorkspace == "" {
|
||||
|
||||
Ссылка в новой задаче
Block a user