diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 8075c645..7e30d25c 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -149,6 +149,21 @@ jobs: - name: Test run: | go test -race -v ./... + go-test-equal: + name: Test equal + needs: ["tidy","build"] + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + id: go + - name: Test + run: | + go test -tags equal -race -v ./... e2e: name: e2e on HAProxy needs: ["go-test"] diff --git a/.gitignore b/.gitignore index 762ab035..cecb79ec 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .idea/ bin/golangci-lint bin/swagger +.envrc diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 46815998..5d9dc6cb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,15 +1,28 @@ --- variables: DOCKER_HOST: tcp://docker:2375 - GO_VERSION: "1.22" - DOCKER_VERSION: "24.0.6" + GO_VERSION: "1.25" + DOCKER_VERSION: "26.0" stages: + - bots - check-commit - generate - build - lint - test - e2e +pipelines-check: + stage: bots + needs: [] + image: + name: $CI_REGISTRY_GO/docker:$DOCKER_VERSION-go$GO_VERSION + entrypoint: [""] + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + tags: + - go + script: + - go run cmd/gitlab-mr-pipelines/main.go build-specification: stage: build needs: [] @@ -148,6 +161,20 @@ test: rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' - if: $CI_PIPELINE_SOURCE == 'push' + +test-equal: + stage: test + needs: ["build"] + image: + name: $CI_REGISTRY_GO/golang:$GO_VERSION + entrypoint: [""] + tags: + - go + script: + - gotest -v -t equal + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + - if: $CI_PIPELINE_SOURCE == 'push' .e2e: stage: e2e needs: ["build"] @@ -170,26 +197,6 @@ test: - docker image tag $CI_REGISTRY_GO/haproxy-alpine:$HAPROXY_VERSION haproxytech/haproxy-alpine:$HAPROXY_VERSION script: - DOCKER_HAPROXY_VERSION=$HAPROXY_VERSION make e2e-docker -HAProxy-2.2: - extends: .e2e - variables: - HAPROXY_VERSION: "2.2" -HAProxy-2.4: - extends: .e2e - variables: - HAPROXY_VERSION: "2.4" -HAProxy-2.6: - extends: .e2e - variables: - HAPROXY_VERSION: "2.6" -HAProxy-2.8: - extends: .e2e - variables: - HAPROXY_VERSION: "2.8" -HAProxy-2.9: - extends: .e2e - variables: - HAPROXY_VERSION: "2.9" HAProxy-3.0: extends: .e2e variables: diff --git a/.golangci.yml b/.golangci.yml index 4cfe0acc..48920bb4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,79 +1,66 @@ ---- -linters-settings: - govet: - check-shadowing: true - golint: - min-confidence: 0 - gocyclo: - min-complexity: 42 - cyclop: - max-complexity: 42 - maligned: - suggest-new: true - dupl: - threshold: 200 - goconst: - min-len: 2 - min-occurrences: 3 - gci: - prefix: github.com/haproxytech/client-native/v6 - +version: "2" linters: - enable-all: true + settings: + cyclop: + max-complexity: 42 + gocyclo: + min-complexity: 42 + default: all disable: - - golint # deprecated, replaced with revive - - interfacer # deprecated - - maligned # deprecated - - wrapcheck - - nlreturn - - gomnd - - goerr113 - - exhaustivestruct - - wsl - - whitespace - - lll - - scopelint - - nestif + - depguard + - dupword + - dupl + - err113 + - exhaustruct + - forcetypeassert + - funcorder - funlen - - paralleltest - - godot - - varnamelen - - ireturn - - ifshort - - thelper - - wastedassign - goconst - - gci - - exhaustruct - - nonamedreturns + - godoclint + - godot - interfacebloat - - dupword - - forcetypeassert # tmp needs to be on - - ifshort # deprecated - - structcheck # deprecated - - deadcode # deprecated - - nosnakecase # deprecated - - varcheck # deprecated - - rowserrcheck # deprecated - - sqlclosecheck # deprecated - - wastedassign # deprecated - - golint # deprecated - - interfacer # deprecated - - maligned # deprecated - - depguard - -issues: - exclude: - # bugs of typecheck linter - - "undeclared name: `shellquote`" - - "github.com/kballard/go-shellquote\" imported but not used" - - "github.com/haproxytech/client-native/v6/config-parser/types\" imported but not used" - - "unused-parameter: parameter 'comment' seems to be unused" - - "unused-parameter: parameter 'parts' seems to be unused" - - "unused-parameter: parameter 'parserType' seems to be unused" - -run: - skip-dirs: - - test - skip-files: - - ".*_test\\.go$" + - ireturn + - lll + - mnd + - nestif + - nlreturn + - noinlineerr + - recvcheck + - revive + - varnamelen + - wrapcheck + - wsl + - wsl_v5 + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - path: (.+)\.go$ + text: 'unused-parameter: parameter ''comment'' seems to be unused' + - path: (.+)\.go$ + text: 'unused-parameter: parameter ''parts'' seems to be unused' + - path: (.+)\.go$ + text: 'unused-parameter: parameter ''parserType'' seems to be unused' + paths: + - .*_test\.go$ + - test + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - gofumpt + - goimports + exclusions: + generated: lax + paths: + - .*_test\.go$ + - test + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index f28de99c..f9726c61 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,18 @@ PROJECT_PATH=${PWD} -DOCKER_HAPROXY_VERSION?=2.8 -SWAGGER_VERSION=v0.30.2 +DOCKER_HAPROXY_VERSION?=3.0 +SWAGGER_VERSION=v0.32.3 GO_VERSION:=${shell go mod edit -json | jq -r .Go} -GOLANGCI_LINT_VERSION=1.55.2 +GOLANGCI_LINT_VERSION=2.8.0 +CHECK_COMMIT=5.2.0 .PHONY: test test: go test ./... +.PHONY: test-equal +test-equal: + go test -tags equal ./... + .PHONY: e2e e2e: go install github.com/oktalz/gotest@latest @@ -30,11 +35,13 @@ spec: .PHONY: models models: gentypes spec swagger-check ./bin/swagger generate model --additional-initialism=FCGI -f ${PROJECT_PATH}/specification/build/haproxy_spec.yaml -r ${PROJECT_PATH}/specification/copyright.txt -m models -t ${PROJECT_PATH} + rm -rf models/server_params_prepare_for_runtime.go rm -rf models/*_compare.go rm -rf models/*_compare_test.go go run cmd/struct_equal_generator/*.go -l ${PROJECT_PATH}/specification/copyright.txt ${PROJECT_PATH}/models go run cmd/struct_tags_checker/*.go ${PROJECT_PATH}/models go run cmd/kubebuilder_marker_generator/*.go ${PROJECT_PATH}/models + go run cmd/server_params_runtime/*.go ${PROJECT_PATH}/models .PHONY: swagger-check swagger-check: diff --git a/bin/swagger-check.sh b/bin/swagger-check.sh index 23944753..df6c928a 100644 --- a/bin/swagger-check.sh +++ b/bin/swagger-check.sh @@ -3,5 +3,5 @@ V=$(./swagger version | grep version | awk 'NF>1{print $NF}') case "$V" in *$SWAGGER_VERSION*) echo "swagger version $V is OK" ;; - *) echo "Detected $V, Installing $SWAGGER_VERSION"; GOBIN=$(pwd) go install "github.com/go-swagger/go-swagger/cmd/swagger@$SWAGGER_VERSION" ;; + *) echo "Detected $V, Installing $SWAGGER_VERSION"; GOTOOLCHAIN=go1.24.6 GOBIN=$(pwd) go install "github.com/go-swagger/go-swagger/cmd/swagger@$SWAGGER_VERSION" ;; esac diff --git a/cmd/gitlab-mr-pipelines/ascii.txt b/cmd/gitlab-mr-pipelines/ascii.txt new file mode 100644 index 00000000..d3b21f22 --- /dev/null +++ b/cmd/gitlab-mr-pipelines/ascii.txt @@ -0,0 +1,11 @@ + ____ _ _ _ _ + / ___(_) |_| | __ _| |__ + | | _| | __| |/ _` | '_ \ + | |_| | | |_| | (_| | |_) | + \____|_|\__|_|\__,_|_.__/ + ____ _ _ _ _ _ + | _ \(_)_ __ ___| (_)_ __ ___ ___| |__ ___ ___| | __ + | |_) | | '_ \ / _ \ | | '_ \ / _ \ / __| '_ \ / _ \/ __| |/ / + | __/| | |_) | __/ | | | | | __/ | (__| | | | __/ (__| < + |_| |_| .__/ \___|_|_|_| |_|\___| \___|_| |_|\___|\___|_|\_\ + |_| diff --git a/cmd/gitlab-mr-pipelines/main.go b/cmd/gitlab-mr-pipelines/main.go new file mode 100644 index 00000000..80c693f5 --- /dev/null +++ b/cmd/gitlab-mr-pipelines/main.go @@ -0,0 +1,159 @@ +// Copyright 2019 HAProxy Technologies LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package main + +import ( + _ "embed" + "encoding/json" + "fmt" + "io" + "net/http" + "os" + "strconv" + "strings" +) + +//go:embed ascii.txt +var hello string + +//nolint:forbidigo +func main() { + fmt.Println(hello) + // Check if we are in a merge request context + mrIID := os.Getenv("CI_MERGE_REQUEST_IID") + if mrIID == "" { + fmt.Println("Not a merge request. Exiting.") + os.Exit(0) + } + + // Get necessary environment variables + gitlabAPIURL := os.Getenv("CI_API_V4_URL") + projectID := os.Getenv("CI_PROJECT_ID") + sourceProjectID := os.Getenv("CI_MERGE_REQUEST_SOURCE_PROJECT_ID") + gitlabToken := os.Getenv("GITLAB_TOKEN") + + if gitlabAPIURL == "" || projectID == "" || sourceProjectID == "" { + fmt.Println("Missing required GitLab CI/CD environment variables.") + os.Exit(1) + } + + if gitlabToken == "" { + fmt.Print("GitLab token not found in environment variable.\n") + os.Exit(1) + } + + // 1. Get all old pipelines for this Merge Request + pipelinesToCancel, err := getOldMergeRequestPipelines(gitlabAPIURL, projectID, mrIID, gitlabToken) + if err != nil { + fmt.Printf("Error getting merge request pipelines: %v\n", err) + os.Exit(1) + } + + if len(pipelinesToCancel) == 0 { + fmt.Println("No old, running pipelines found for this merge request.") + os.Exit(0) + } + + fmt.Printf("Found %d old pipelines to cancel.\n", len(pipelinesToCancel)) + + // 2. Cancel all found pipelines + for _, p := range pipelinesToCancel { + fmt.Printf("Canceling pipeline ID %d on project ID %d\n", p.ID, p.ProjectID) + err = cancelPipeline(gitlabAPIURL, strconv.Itoa(p.ProjectID), p.ID, gitlabToken) + if err != nil { + // Log error but continue trying to cancel others + fmt.Printf("Failed to cancel pipeline %d: %v\n", p.ID, err) + } else { + fmt.Printf("Successfully requested cancellation for pipeline %d\n", p.ID) + } + } +} + +type pipelineInfo struct { + ID int `json:"id"` + ProjectID int `json:"project_id"` //nolint:tagliatelle + Status string `json:"status"` +} + +func getOldMergeRequestPipelines(apiURL, projectID, mrIID, token string) ([]pipelineInfo, error) { + // Get the current pipeline ID to avoid canceling ourselves + currentPipelineIDStr := os.Getenv("CI_PIPELINE_ID") + var currentPipelineID int + if currentPipelineIDStr != "" { + // a non-integer value will result in 0, which is fine since pipeline IDs are positive + currentPipelineID, _ = strconv.Atoi(currentPipelineIDStr) + } + + url := fmt.Sprintf("%s/projects/%s/merge_requests/%s/pipelines", apiURL, projectID, mrIID) + req, err := http.NewRequest("GET", url, nil) //nolint:noctx,usestdlibvars + if err != nil { + return nil, err + } + req.Header.Set("PRIVATE-TOKEN", token) //nolint:canonicalheader + + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + body, _ := io.ReadAll(resp.Body) + return nil, fmt.Errorf("failed to list merge request pipelines: status %d, body: %s", resp.StatusCode, string(body)) + } + + var pipelines []pipelineInfo + if err := json.NewDecoder(resp.Body).Decode(&pipelines); err != nil { + return nil, err + } + + var pipelinesToCancel []pipelineInfo + for _, p := range pipelines { + // Cancel pipelines that are running or pending, and are not the current pipeline + if (p.Status == "running" || p.Status == "pending") && p.ID != currentPipelineID { + pipelinesToCancel = append(pipelinesToCancel, p) + } + } + + return pipelinesToCancel, nil +} + +func cancelPipeline(apiURL, projectID string, pipelineID int, token string) error { + url := fmt.Sprintf("%s/projects/%s/pipelines/%d/cancel", apiURL, projectID, pipelineID) + req, err := http.NewRequest("POST", url, nil) //nolint:noctx,usestdlibvars + if err != nil { + return err + } + req.Header.Set("PRIVATE-TOKEN", token) //nolint:canonicalheader + + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + body, _ := io.ReadAll(resp.Body) + // It's possible the pipeline is already finished. + if strings.Contains(string(body), "Cannot cancel a pipeline that is not pending or running") { + fmt.Println("Pipeline already finished, nothing to do.") //nolint:forbidigo + return nil + } + return fmt.Errorf("failed to cancel pipeline: status %d, body: %s", resp.StatusCode, string(body)) + } + + return nil +} diff --git a/cmd/kubebuilder_marker_generator/main.go b/cmd/kubebuilder_marker_generator/main.go index 1326493f..9c1f9478 100644 --- a/cmd/kubebuilder_marker_generator/main.go +++ b/cmd/kubebuilder_marker_generator/main.go @@ -32,7 +32,7 @@ func main() { } } -func generate(fileName string) error { //nolint:gocognit,unparam +func generate(fileName string) error { //nolint:gocognit f, err := decorator.ParseFile(token.NewFileSet(), fileName, nil, 0) if err != nil { log.Fatal(err) @@ -58,11 +58,12 @@ func generate(fileName string) error { //nolint:gocognit,unparam // We must keep empty strings: // For example in Globals HttpclientSslVerify: // Enum: [ none required] // from swagger: enum: ["", "none", "required"] - for _, enum := range strings.Split(comment, " ") { + for enum := range strings.SplitSeq(comment, ",") { + enum = strings.Trim(enum, "\"") if enum == "" { newComment += `""` } - newComment += enum + newComment += enum //nolint: perfsprint newComment += ";" } field.Decorations().Start.Append(newComment) @@ -86,7 +87,21 @@ func generate(fileName string) error { //nolint:gocognit,unparam field.Decorations().Start.Append("// +kubebuilder:validation:Optional") } } - + if strings.HasPrefix(comment, "// metadata") { + decorations := field.Decorations().Start + preserveField := "// +kubebuilder:pruning:PreserveUnknownFields" + schemalessField := "// +kubebuilder:validation:Schemaless" + updatedDecorations := make([]string, 0) + copy(updatedDecorations, decorations) + if !containsDecoration(updatedDecorations, preserveField) { + updatedDecorations = append(updatedDecorations, preserveField) + } + if !containsDecoration(updatedDecorations, schemalessField) { + updatedDecorations = append(updatedDecorations, schemalessField) + } + field.Decorations().Start = updatedDecorations + field.Decorations().Before = dst.NewLine + } } // if len(field.Names) > 0 { // log.Printf("Comments before the field %s: %v\n", field.Names[0].Name, comments) @@ -153,3 +168,14 @@ func cleanup(comments []string, prefixToRemove string) []string { } return res } + +// Helper function to check if a decoration exists +func containsDecoration(decorations []string, decoration string) bool { + for _, d := range decorations { + // Normalize whitespace to prevent mismatch + if strings.TrimSpace(d) == strings.TrimSpace(decoration) { + return true + } + } + return false +} diff --git a/cmd/server_params_runtime/README.md b/cmd/server_params_runtime/README.md new file mode 100644 index 00000000..6be6a952 --- /dev/null +++ b/cmd/server_params_runtime/README.md @@ -0,0 +1,60 @@ +# ![HAProxy](../../assets/images/haproxy-weblogo-210x49.png "HAProxy") + +## Generator for: `models/server_params_prepare_for_runtime.go` + +This genetator generates a file that will contains the needed functions to prepare a ServerParams to use in combination with `add server` command on the runtime socket. + +This file will contain 3 functions: + +``` +func (p *ServerParams) prepareForRuntimeDoNotSendDisabledFields() +func (p *ServerParams) prepareForRuntimeDoNotSendEnabledFields() +func (p *ServerParams) PrepareFieldsForRuntimeAddServer() +``` + +They are used for example in Ingress Controller the following way: +``` +params.PrepareFieldsForRuntimeAddServer() +serverParams := configuration.SerializeServerParams(defaultServer.ServerParams) +res := cp_params.ServerOptionsString(serverParams) +``` + +### func (p *ServerParams) prepareForRuntimeDoNotSendDisabledFields() +For example for `Check` that has the values [enabled disabled]. + +- if the value is `enabled` we must send `add server check` +- if the value is `disabled` we must not send `add server no-check` as `no-check` is not allowed on a dynamic server + +`no-check` is the default value. + +The purpose is to set `Check` to "" when the value was `disabled` so the commands sent are: + - `add server check` if value is `enabled` + - `add server` if value is `disabled` + + +### func (p *ServerParams) prepareForRuntimeDoNotSendEnabledFields() +It's just the opposite. + +For example for `NoSslv3` + +- if `enabled` we must send `no-sslv3` +- if `disabled` we must not sent an option + + +### func (p *ServerParams) PrepareFieldsForRuntimeAddServer()` +is just calling both `PrepareForRuntimeDoNotSendDisabledFields` and `PrepareForRuntimeDoNotSendEnabledFields` + + +## WHAT TO DO + +Just fill in `server_params_prepare_for_runtime.go` the map: +- `ServerParamsPrepareForRuntimeMap` + +for each field that has an `// Enum: [enabled disabled]"` +with the correct function to use + +## Ensure that the map is always filled in a field is added into ServerParams: CI check + +The generator checks all fields in ServerParams that have `// Enum: [enabled disabled]"` have an entry in the `ServerParamsPrepareForRuntimeMap`. + +If a new field is added and not declared in `ServerParamsPrepareForRuntimeMap`, the generator fails with an error and this will make the CI fail. diff --git a/cmd/server_params_runtime/args.go b/cmd/server_params_runtime/args.go new file mode 100644 index 00000000..1b26f075 --- /dev/null +++ b/cmd/server_params_runtime/args.go @@ -0,0 +1,97 @@ +package main + +import ( + _ "embed" + "errors" + "fmt" + "io/fs" + "log" + "os" + "path" + "path/filepath" + "strings" +) + +type Args struct { + Licence string + LicencePath string + Directory string + Selector string + Files []string +} + +func (a *Args) Parse() error { //nolint:gocognit + selector, err := os.Getwd() + if err != nil { + log.Panic(err) + } + for i := 1; i < len(os.Args); i++ { + val := os.Args[i] + switch { + case val == "-l": + if i+1 >= len(os.Args) { + return errors.New("missing licence file after -l") + } + a.LicencePath = os.Args[i+1] + i++ + case strings.HasPrefix(val, "--licence="): + a.LicencePath = strings.TrimPrefix(val, "--licence=") + default: + selector = val + } + } + + if a.LicencePath != "" { + var licence []byte + licence, err = os.ReadFile(a.LicencePath) + if err != nil { + return err + } + lines := strings.Split(string(licence), "\n") + var s strings.Builder + for _, line := range lines { + s.WriteString("// ") + s.WriteString(line) + s.WriteString("\n") + } + a.Licence = s.String() + } + isDirectory := false + file, err := os.Open(selector) + if err == nil { + var fileInfo fs.FileInfo + fileInfo, err = file.Stat() + if err == nil { + isDirectory = fileInfo.IsDir() + } + } + if selector == "*" || selector == "." || isDirectory { + err = filepath.Walk(selector, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if info.IsDir() { + return nil + } + + if strings.HasSuffix(path, serverParamFileName) { + fmt.Println(path) //nolint:forbidigo + a.Files = append(a.Files, path) + } + return nil + }) + if err != nil { + log.Panic(err) + } + } else { + a.Files = append(a.Files, selector) + } + a.Selector = selector + if isDirectory { + a.Directory = selector + } else { + a.Directory = path.Dir(selector) + } + + return nil +} diff --git a/cmd/server_params_runtime/embed.go b/cmd/server_params_runtime/embed.go new file mode 100644 index 00000000..a69564e8 --- /dev/null +++ b/cmd/server_params_runtime/embed.go @@ -0,0 +1,8 @@ +package main + +import ( + _ "embed" +) + +//go:embed generate.tmpl +var tmplResetEnumDisabledFields string diff --git a/cmd/server_params_runtime/formating.go b/cmd/server_params_runtime/formating.go new file mode 100644 index 00000000..febc1a90 --- /dev/null +++ b/cmd/server_params_runtime/formating.go @@ -0,0 +1,33 @@ +package main + +import ( + "bytes" + "fmt" + "go/format" + "go/parser" + "go/token" + "os" + + "golang.org/x/tools/imports" +) + +func fmtFile(fileName string) error { + fset := token.NewFileSet() + node, err := parser.ParseFile(fset, fileName, nil, parser.ParseComments) + if err != nil { + return err + } + + // gofmt the modified file + var buf bytes.Buffer + if err = format.Node(&buf, fset, node); err != nil { + return err + } + + formattedCode, err := imports.Process(fileName, buf.Bytes(), nil) + if err != nil { + return fmt.Errorf("failed to perform goimports: %w", err) + } + + return os.WriteFile(fileName, formattedCode, 0o600) +} diff --git a/cmd/server_params_runtime/generate.tmpl b/cmd/server_params_runtime/generate.tmpl new file mode 100644 index 00000000..aa501d4b --- /dev/null +++ b/cmd/server_params_runtime/generate.tmpl @@ -0,0 +1,36 @@ +// Code generated by server_params_runtime; DO NOT EDIT. + +{{ .Licence }} + +package {{ .Package }} + + +func (s ServerParams){{ .PrepareFieldsForRuntimeAddServer }}()* ServerParams { + serverParams := new(ServerParams) + // *defaultServer = p + a, _ := s.MarshalBinary() + _ = serverParams.UnmarshalBinary(a) + + serverParams.{{ .DoNotSendDisabledFieldsFunc }}() + serverParams.{{ .DoNotSendEnabledFieldsFunc }}() + + return serverParams +} + + +func (s *ServerParams){{ .DoNotSendDisabledFieldsFunc }}() { +{{- range .DoNotSendDisabledFields }} + if s.{{ . }} == "disabled" { + s.{{ . }} = "" + } +{{- end }} +} + + +func (s *ServerParams){{ .DoNotSendEnabledFieldsFunc }}() { +{{- range .DoNotSendEnabledFields }} + if s.{{ . }} == "enabled" { + s.{{ . }} = "" + } +{{- end }} +} diff --git a/cmd/server_params_runtime/header.tmpl b/cmd/server_params_runtime/header.tmpl new file mode 100644 index 00000000..804c9bc6 --- /dev/null +++ b/cmd/server_params_runtime/header.tmpl @@ -0,0 +1,22 @@ +// Code generated by server_params_runtime; DO NOT EDIT. + +{{ .Licence }} + +package {{ .Package }} + +import ( + cryptorand "crypto/rand" + "fmt" + "math" + "math/rand" + "strconv" + "testing" + "time" + "bytes" + "encoding/gob" + + "github.com/go-faker/faker/v4" + "github.com/go-openapi/strfmt" + + jsoniter "github.com/json-iterator/go" +) diff --git a/cmd/server_params_runtime/main.go b/cmd/server_params_runtime/main.go new file mode 100644 index 00000000..3533b892 --- /dev/null +++ b/cmd/server_params_runtime/main.go @@ -0,0 +1,117 @@ +package main + +import ( + _ "embed" + "go/token" + "log" + "os" + "strings" + "text/template" + + "github.com/sirkon/dst" + "github.com/sirkon/dst/decorator" +) + +const ( + serverParamFileName = "server_params.go" + commentEnumFieldsToReset = `// Enum: ["enabled","disabled"]` +) + +func main() { + var allEnumFields []string + var packageName string + args := Args{} + err := args.Parse() + if err != nil { + log.Panic(err) + } + for _, fileName := range args.Files { + packageName, allEnumFields = enumFieldsEnabledDisabled(fileName) + if err != nil { + log.Panic(err) + } + + // check that all enum + // Enum: [enabled disabled]" + // fields have an entry in the ServerParamsPrepareForRuntimeMap + missingFields, errMissingField := checkMissingEnumFields(allEnumFields) + if errMissingField != nil { + // Exit with error if any new enum field is found and its behavior is not defined in ServerParamsPrepareForRuntimeMap + log.Printf("There are some fields in models/server_params.go that are Enum[enabled disabled] but missing in `ServerParamsPrepareForRuntimeMap`") + log.Printf(" File location `cmd/server_params_runtime/server_parans_runtime_fields_behavior.go`") + log.Printf("ACTION: Please add them to `ServerParamsPrepareForRuntimeMap`") + log.Printf("Missing fields %v", missingFields) + log.Printf("\t For doc, read cmd/server_params_runtime/README.md") + + os.Exit(1) + } + + // Generate the reset function using the template + tmpl, errTmpl := template.New("generate.tmpl").Parse(tmplResetEnumDisabledFields) + // ParseFiles(path.Join(templatePath)) + if errTmpl != nil { + log.Panic(errTmpl) + } + + generatedFileName := strings.TrimSuffix(fileName, ".go") + "_prepare_for_runtime.go" + _ = os.Truncate(generatedFileName, 0) + file, errFile := os.OpenFile(generatedFileName, os.O_CREATE|os.O_WRONLY, 0o600) + if errFile != nil { + log.Panic(errFile) + } + defer file.Close() + + doNotSendDisabledFields := listEmptyDisabledFields(allEnumFields) + doNotSendEnabledFields := listEmtpyEnabledFields(allEnumFields) + + errTmpl = tmpl.Execute(file, map[string]any{ + "PrepareFieldsForRuntimeAddServer": FuncPrepareFieldsForRuntimeAddServer, + "DoNotSendDisabledFields": doNotSendDisabledFields, + "DoNotSendDisabledFieldsFunc": FuncDoNotSendDisabledFields, + "DoNotSendEnabledFields": doNotSendEnabledFields, + "DoNotSendEnabledFieldsFunc": FuncDoNotSendEnabledFields, + "Package": packageName, + "Licence": args.Licence, + }) + if errTmpl != nil { + log.Panic(errTmpl) + } + + errFmt := fmtFile(generatedFileName) + if errFmt != nil { + log.Panic(errFmt) + } + } +} + +func enumFieldsEnabledDisabled(filename string) (string, []string) { //nolint:gocognit + var fieldsWithComment []string + f, err := decorator.ParseFile(token.NewFileSet(), filename, nil, 0) + if err != nil { + log.Fatal(err) + } + + for _, decl := range f.Decls { + if genDecl, ok := decl.(*dst.GenDecl); ok && genDecl.Tok == token.TYPE { + for _, spec := range genDecl.Specs { + if typeSpec, ok := spec.(*dst.TypeSpec); ok { + if structType, ok := typeSpec.Type.(*dst.StructType); ok { + for _, field := range structType.Fields.List { + comments := field.Decorations().Start.All() + + for _, comment := range comments { + if comment == commentEnumFieldsToReset { + // Add field name to the list + if len(field.Names) > 0 { + fieldsWithComment = append(fieldsWithComment, field.Names[0].Name) + } + } + } + } + } + } + } + } + } + return f.Name.Name, fieldsWithComment +} diff --git a/cmd/server_params_runtime/params.go b/cmd/server_params_runtime/params.go new file mode 100644 index 00000000..06ab7d0f --- /dev/null +++ b/cmd/server_params_runtime/params.go @@ -0,0 +1 @@ +package main diff --git a/cmd/server_params_runtime/server_params_prepare_for_runtime.go b/cmd/server_params_runtime/server_params_prepare_for_runtime.go new file mode 100644 index 00000000..977942af --- /dev/null +++ b/cmd/server_params_runtime/server_params_prepare_for_runtime.go @@ -0,0 +1,82 @@ +package main + +import ( + "errors" +) + +const ( + FuncDoNotSendDisabledFields = "prepareForRuntimeDoNotSendDisabledFields" + FuncDoNotSendEnabledFields = "prepareForRuntimeDoNotSendEnabledFields" + FuncPrepareFieldsForRuntimeAddServer = "PrepareFieldsForRuntimeAddServer" +) + +var ServerParamsPrepareForRuntimeMap = map[string]string{ //nolint:gochecknoglobals + "AgentCheck": FuncDoNotSendDisabledFields, + "Backup": FuncDoNotSendDisabledFields, + "Check": FuncDoNotSendDisabledFields, + "CheckSendProxy": FuncDoNotSendDisabledFields, + "CheckSsl": FuncDoNotSendDisabledFields, + "CheckViaSocks4": FuncDoNotSendDisabledFields, + "ForceSslv3": FuncDoNotSendDisabledFields, + "ForceTlsv10": FuncDoNotSendDisabledFields, + "ForceTlsv11": FuncDoNotSendDisabledFields, + "ForceTlsv12": FuncDoNotSendDisabledFields, + "ForceTlsv13": FuncDoNotSendDisabledFields, + "Maintenance": FuncDoNotSendDisabledFields, + "NoSslv3": FuncDoNotSendEnabledFields, + "NoTlsv10": FuncDoNotSendEnabledFields, + "NoTlsv11": FuncDoNotSendEnabledFields, + "NoTlsv12": FuncDoNotSendEnabledFields, + "NoTlsv13": FuncDoNotSendEnabledFields, + "NoVerifyhost": FuncDoNotSendEnabledFields, + "SendProxy": FuncDoNotSendDisabledFields, + "SendProxyV2": FuncDoNotSendDisabledFields, + "SendProxyV2Ssl": FuncDoNotSendDisabledFields, + "SendProxyV2SslCn": FuncDoNotSendDisabledFields, + "Ssl": FuncDoNotSendDisabledFields, + "SslReuse": FuncDoNotSendDisabledFields, + "Stick": FuncDoNotSendDisabledFields, + "Tfo": FuncDoNotSendDisabledFields, + "TLSTickets": FuncDoNotSendDisabledFields, +} + +func checkMissingEnumFields(allFields []string) ([]string, error) { + missingFields := []string{} + for _, field := range allFields { + // check that all enum + // Enum: [enabled disabled]" + // fields have an entry in the ServerParamsPrepareForRuntimeMap + f, ok := ServerParamsPrepareForRuntimeMap[field] + if !ok || (f != FuncDoNotSendEnabledFields && f != FuncDoNotSendDisabledFields) { + missingFields = append(missingFields, field) + } + } + if len(missingFields) > 0 { + return missingFields, errors.New("missing enum fields") + } + return missingFields, nil +} + +func listEmptyDisabledFields(allFields []string) []string { + var emptyDisabledFields []string + for _, field := range allFields { + if f, ok := ServerParamsPrepareForRuntimeMap[field]; ok { + if f == FuncDoNotSendDisabledFields { + emptyDisabledFields = append(emptyDisabledFields, field) + } + } + } + return emptyDisabledFields +} + +func listEmtpyEnabledFields(allFields []string) []string { + var emptyEnabledFields []string + for _, field := range allFields { + if f, ok := ServerParamsPrepareForRuntimeMap[field]; ok { + if f == FuncDoNotSendEnabledFields { + emptyEnabledFields = append(emptyEnabledFields, field) + } + } + } + return emptyEnabledFields +} diff --git a/cmd/specification/build.go b/cmd/specification/build.go index 16af1448..95715678 100644 --- a/cmd/specification/build.go +++ b/cmd/specification/build.go @@ -12,12 +12,12 @@ import ( "sort" "strings" - "github.com/go-openapi/swag" + "github.com/go-openapi/swag/mangling" "github.com/haproxytech/client-native/v6/configuration/parents" "gopkg.in/yaml.v3" ) -var cache map[string]interface{} //nolint:gochecknoglobals +var cache map[string]any //nolint:gochecknoglobals func errorExit(msg string) { fmt.Fprintf(os.Stderr, "ERROR: %v\n", msg) @@ -39,7 +39,7 @@ func expandRef(refValue string, absPath string, prefix string) string { filePath := path.Join(absPath, words[0]) keyPath := words[1] - m, ok := cache[filePath].(map[string]interface{}) + m, ok := cache[filePath].(map[string]any) if !ok { fileHandle, err := os.Open(filePath) if err != nil { @@ -48,11 +48,12 @@ func expandRef(refValue string, absPath string, prefix string) string { defer fileHandle.Close() fileScanner := bufio.NewScanner(fileHandle) - value := "" + sb := strings.Builder{} for fileScanner.Scan() { - value += fileScanner.Text() + "\n" + sb.WriteString(fileScanner.Text()) + sb.WriteString("\n") } - + value := sb.String() err = yaml.Unmarshal([]byte(value), &m) if err != nil { fmt.Println(refValue) //nolint:forbidigo @@ -61,9 +62,9 @@ func expandRef(refValue string, absPath string, prefix string) string { } cache[filePath] = m } - retVal := make(map[string]interface{}) + retVal := make(map[string]any) if m[keyPath[1:]] != nil { - retVal = m[keyPath[1:]].(map[string]interface{}) + retVal = m[keyPath[1:]].(map[string]any) } else { fmt.Println(refValue) //nolint:forbidigo fmt.Println(keyPath) //nolint:forbidigo @@ -81,19 +82,20 @@ func expandRef(refValue string, absPath string, prefix string) string { } retValStr := buf.String() - indentedRetValStr := "" - indentedLine := "" - for _, line := range strings.Split(retValStr, "\n") { + var indentedRetValStr string + var indentedLine string + for line := range strings.SplitSeq(retValStr, "\n") { if strings.TrimSpace(line) != "" { indentedLine = prefix + "" + line + "\n" - indentedRetValStr += indentedLine + indentedRetValStr += indentedLine //nolint: perfsprint } } return indentedRetValStr[:len(indentedRetValStr)-1] } -func main() { //nolint:gocognit +//nolint:gocognit,modernize,perfsprint +func main() { inputFilePtr := flag.String("file", "", "Source file") flag.Parse() @@ -106,7 +108,7 @@ func main() { //nolint:gocognit errorExit("File " + *inputFilePtr + " does not exist") } - cache = make(map[string]interface{}) + cache = make(map[string]any) absPath := filepath.Dir(*inputFilePtr) fileHandle, err := os.Open(*inputFilePtr) @@ -166,7 +168,7 @@ func main() { //nolint:gocognit b, _ := yaml.Marshal(&ts) - for _, line := range strings.Split(strings.TrimRight(string(b), "\n"), "\n") { + for line := range strings.SplitSeq(strings.TrimRight(string(b), "\n"), "\n") { result.WriteString(" " + line + "\n") } result.WriteString("security:") @@ -196,7 +198,7 @@ func main() { //nolint:gocognit func expandChildren(src string) bytes.Buffer { funcMap := template.FuncMap{ "parents": parents.Parents, - "toGoName": swag.ToGoName, + "toGoName": mangling.NameMangler.ToGoName, } tmpl := template.Must(template.New("").Funcs(funcMap).Parse(src)) diff --git a/cmd/struct_equal_generator/args.go b/cmd/struct_equal_generator/args.go index 8f964203..e76edd12 100644 --- a/cmd/struct_equal_generator/args.go +++ b/cmd/struct_equal_generator/args.go @@ -2,6 +2,7 @@ package main import ( _ "embed" + "errors" "fmt" "io/fs" "log" @@ -12,9 +13,9 @@ import ( ) type Args struct { - Licence string + License string Directory string - LicencePath string + LicensePath string Selector string Files []string } @@ -29,20 +30,20 @@ func (a *Args) Parse() error { //nolint:gocognit switch { case val == "-l": if i+1 >= len(os.Args) { - return fmt.Errorf("missing licence file after -l") + return errors.New("missing licence file after -l") } - a.LicencePath = os.Args[i+1] + a.LicensePath = os.Args[i+1] i++ case strings.HasPrefix(val, "--licence="): - a.LicencePath = strings.TrimPrefix(val, "--licence=") + a.LicensePath = strings.TrimPrefix(val, "--licence=") default: selector = val } } - if a.LicencePath != "" { + if a.LicensePath != "" { var licence []byte - licence, err = os.ReadFile(a.LicencePath) + licence, err = os.ReadFile(a.LicensePath) if err != nil { return err } @@ -53,7 +54,7 @@ func (a *Args) Parse() error { //nolint:gocognit s.WriteString(line) s.WriteString("\n") } - a.Licence = s.String() + a.License = s.String() } isDirectory := false file, err := os.Open(selector) diff --git a/cmd/struct_equal_generator/generate.go b/cmd/struct_equal_generator/generate.go index 7f8ca405..aafefd83 100644 --- a/cmd/struct_equal_generator/generate.go +++ b/cmd/struct_equal_generator/generate.go @@ -19,7 +19,7 @@ func generateEqualAndDiff(opt generateEqualAndDiffOptions) error { return err } - data := map[string]interface{}{ + data := map[string]any{ "Mode": opt.Mode, "Name": opt.Name, "Type": opt.Type, @@ -32,13 +32,13 @@ func generateEqualAndDiff(opt generateEqualAndDiffOptions) error { "IsPointer": opt.IsPointer, } - functions := map[string]interface{}{ - "Functions": []interface{}{ - map[string]interface{}{ + functions := map[string]any{ + "Functions": []any{ + map[string]any{ "Name": "Equal", "Data": data, }, - map[string]interface{}{ + map[string]any{ "Name": "Diff", "Data": data, }, @@ -53,6 +53,16 @@ func generateEqualAndDiff(opt generateEqualAndDiffOptions) error { } func generateCompareTests(opt generateEqualAndDiffOptions) error { + var metadataIndex int + for i, f := range opt.Fields { + if f.Name == "Metadata" { + metadataIndex = i + break + } + } + if metadataIndex > 0 { + opt.Fields = append(opt.Fields[:metadataIndex], opt.Fields[metadataIndex+1:]...) + } if opt.Mode == "array" { return nil } @@ -72,7 +82,7 @@ func generateCompareTests(opt generateEqualAndDiffOptions) error { break } } - err = tmpl.Execute(opt.FileTest, map[string]interface{}{ + err = tmpl.Execute(opt.FileTest, map[string]any{ "TestType": []string{"Equal", "Diff"}, "Name": opt.Name, "HasIndex": hasIndex, diff --git a/cmd/struct_equal_generator/generate.tmpl b/cmd/struct_equal_generator/generate.tmpl index 6d36a874..eefad007 100644 --- a/cmd/struct_equal_generator/generate.tmpl +++ b/cmd/struct_equal_generator/generate.tmpl @@ -1,4 +1,3 @@ - {{- range .Functions}} {{- $topLevel := . }} // {{.Name}} checks if two structs of type {{.Data.Name}} are equal @@ -103,7 +102,11 @@ func (s {{.Data.Name}}) {{.Name}}(t {{.Data.Name}}, opts ...Options) {{- if eq $ } for k,v := range s.{{.Name}} { + {{- if eq .Name "Metadata" }} + if !reflect.DeepEqual(t.{{.Name}}[k], v) { + {{- else }} if !t.{{.Name}}[k].Equal(v, opt) { + {{- end }} {{- if eq $topLevel.Name "Equal" }} return false {{- else if eq $topLevel.Name "Diff" }} @@ -181,7 +184,7 @@ func (s {{.Data.Name}}) {{.Name}}(t {{.Data.Name}}, opts ...Options) {{- if eq $ } {{- else }} {{- if HasPrefix .SubType.Type "*" }} - if !equalPointers(s.{{.Name}}, t.{{.Name}}) { + if !equalPointers(s.{{.Name}}[i], t.{{.Name}}[i]) { {{- if eq $topLevel.Name "Equal" }} return false {{- else if eq $topLevel.Name "Diff" }} diff --git a/cmd/struct_equal_generator/header.tmpl b/cmd/struct_equal_generator/header.tmpl index c7f12877..d8fdca12 100644 --- a/cmd/struct_equal_generator/header.tmpl +++ b/cmd/struct_equal_generator/header.tmpl @@ -1,6 +1,6 @@ // Code generated with struct_equal_generator; DO NOT EDIT. -{{ .Licence }} +{{ .License }} package {{ .Package }} @@ -16,6 +16,7 @@ import ( "encoding/gob" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" "github.com/go-openapi/strfmt" jsoniter "github.com/json-iterator/go" diff --git a/cmd/struct_equal_generator/main.go b/cmd/struct_equal_generator/main.go index 5ece73e9..92373bd7 100644 --- a/cmd/struct_equal_generator/main.go +++ b/cmd/struct_equal_generator/main.go @@ -110,9 +110,9 @@ func generate(fileName string, args Args) (string, error) { //nolint:gocognit,ma return packageName, err } - err = tmpl.Execute(file, map[string]interface{}{ + err = tmpl.Execute(file, map[string]any{ "Package": node.Name.String(), - "Licence": args.Licence, + "License": args.License, }) if err != nil { return packageName, err @@ -125,13 +125,17 @@ func generate(fileName string, args Args) (string, error) { //nolint:gocognit,ma return packageName, err } - err = tmpl2.Execute(fileTest, map[string]interface{}{ + err = tmpl2.Execute(fileTest, map[string]any{ "Package": node.Name.String(), - "Licence": args.Licence, + "License": args.License, }) if err != nil { return packageName, err } + _, err = fileTest.WriteString("//go:build equal\n") + if err != nil { + return packageName, err + } packageName = node.Name.String() imports := map[string]string{} @@ -162,9 +166,7 @@ func generate(fileName string, args Args) (string, error) { //nolint:gocognit,ma switch currType := currSpecType.Type.(type) { case *ast.StructType: var fields []Field - needsOptions := false - needsOptionsIndex := false - fields, needsOptions, needsOptionsIndex = getFields(fields, currType, imports) + fields, needsOptions, needsOptionsIndex := getFields(fields, currType, imports) for _, f := range fields { if strings.HasPrefix(f.Type, "*") && (f.HasEqualOpt || f.HasEqual) { needsOptions = true @@ -271,7 +273,9 @@ func generate(fileName string, args Args) (string, error) { //nolint:gocognit,ma return packageName, nil } -func getFields(fields []Field, node *ast.StructType, imports map[string]string) (fieldsResult []Field, needsOptions, needsOptionsIndex bool) { //nolint:gocognit +func getFields(fields []Field, node *ast.StructType, imports map[string]string) ([]Field, bool, bool) { //nolint:gocognit + var needsOptions bool + var needsOptionsIndex bool for _, field := range node.Fields.List { if len(field.Names) > 0 { res := getTypeString(field.Type, imports) diff --git a/cmd/struct_equal_generator/misc.go b/cmd/struct_equal_generator/misc.go index a026e866..d1800ce8 100644 --- a/cmd/struct_equal_generator/misc.go +++ b/cmd/struct_equal_generator/misc.go @@ -60,13 +60,12 @@ func toJSON(x any) string { func toCamelCase(s string) string { caser := cases.Title(language.Und) - var result string - words := strings.Split(s, "_") - - for _, word := range words { - result += caser.String(word) + words := strings.SplitSeq(s, "_") + sb := strings.Builder{} + for word := range words { + sb.WriteString(caser.String(word)) } - + result := sb.String() result = strings.ToLower(result[:1]) + result[1:] return result @@ -74,13 +73,12 @@ func toCamelCase(s string) string { func toLowerCase(s string) string { caser := cases.Lower(language.Und) - var result string - words := strings.Split(s, "_") - - for _, word := range words { - result += caser.String(word) + words := strings.SplitSeq(s, "_") + sb := strings.Builder{} + for word := range words { + sb.WriteString(caser.String(word)) } - + result := sb.String() result = strings.ToLower(result[:1]) + result[1:] return result diff --git a/cmd/struct_equal_generator/test.tmpl b/cmd/struct_equal_generator/test.tmpl index 7b975174..e691c233 100644 --- a/cmd/struct_equal_generator/test.tmpl +++ b/cmd/struct_equal_generator/test.tmpl @@ -1,4 +1,3 @@ - {{ range .TestType}} func Test{{$.Name}}{{.}}(t *testing.T) { samples := []struct { @@ -7,17 +6,17 @@ func Test{{$.Name}}{{.}}(t *testing.T) { for i := 0; i < 2; i++ { var sample {{$.Name}} var result {{$.Name}} - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -36,11 +35,11 @@ func Test{{$.Name}}{{.}}(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } {{- if eq . "Equal" }} t.Errorf("Expected {{$.Name}} to be equal, but it is not %s %s", a, b) @@ -62,13 +61,13 @@ func Test{{$.Name}}{{.}}False(t *testing.T) { for i := 0; i < 2; i++ { var sample {{$.Name}} var result {{$.Name}} - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } {{- range $.Fields}} {{- if (eq .Type "bool") }} @@ -123,11 +122,11 @@ func Test{{$.Name}}{{.}}False(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } {{- if eq . "Equal" }} t.Errorf("Expected {{$.Name}} to be different, but it is not %s %s", a, b) diff --git a/cmd/struct_equal_generator/utils.go b/cmd/struct_equal_generator/utils.go index 8961f706..08ebbb3c 100644 --- a/cmd/struct_equal_generator/utils.go +++ b/cmd/struct_equal_generator/utils.go @@ -26,9 +26,9 @@ func createUtilsFile(packageName string, args Args) error { return err } - err = tmpl.Execute(file, map[string]interface{}{ + err = tmpl.Execute(file, map[string]any{ "Package": packageName, - "Licence": args.Licence, + "License": args.License, }) if err != nil { return err @@ -39,7 +39,7 @@ func createUtilsFile(packageName string, args Args) error { if err != nil { return err } - err = tmpl.Execute(file, map[string]interface{}{}) + err = tmpl.Execute(file, map[string]any{}) if err != nil { return err } diff --git a/cmd/struct_tags_checker/main.go b/cmd/struct_tags_checker/main.go index 0bc22c8d..a8719101 100644 --- a/cmd/struct_tags_checker/main.go +++ b/cmd/struct_tags_checker/main.go @@ -26,7 +26,7 @@ func main() { } } -func generate(fileName string) error { //nolint:gocognit,unparam +func generate(fileName string) error { //nolint:gocognit f, err := decorator.ParseFile(token.NewFileSet(), fileName, nil, 0) if err != nil { log.Fatal(err) diff --git a/config-parser/common/common.go b/config-parser/common/common.go index 11191242..2c01382c 100644 --- a/config-parser/common/common.go +++ b/config-parser/common/common.go @@ -17,19 +17,14 @@ limitations under the License. package common import ( + "slices" "strings" ) // StringSplitIgnoreEmpty while spliting, removes empty items func StringSplitIgnoreEmpty(s string, separators ...rune) []string { f := func(c rune) bool { - willSplit := false - for _, sep := range separators { - if c == sep { - willSplit = true - break - } - } + willSplit := slices.Contains(separators, c) return willSplit } return strings.FieldsFunc(s, f) diff --git a/config-parser/common/parser-data.go b/config-parser/common/parser-data.go index 98cd797b..1a504203 100644 --- a/config-parser/common/parser-data.go +++ b/config-parser/common/parser-data.go @@ -16,4 +16,4 @@ limitations under the License. package common -type ParserData interface{} +type ParserData any diff --git a/config-parser/fetch.go b/config-parser/fetch.go index 5a5a8ed1..6433d4eb 100644 --- a/config-parser/fetch.go +++ b/config-parser/fetch.go @@ -45,11 +45,7 @@ func (p *configParser) Get(sectionType Section, sectionName string, attribute st if !ok { return nil, errors.ErrSectionMissing } - createNew := false - if len(createIfNotExist) > 0 && createIfNotExist[0] { - createNew = true - } - return section.Get(attribute, createNew) + return section.Get(attribute, len(createIfNotExist) > 0 && createIfNotExist[0]) } // GetResult get attribute lines from section @@ -203,7 +199,8 @@ func (p *configParser) SectionsDefaultsFromSet(sectionType Section, sectionName, // for defaults we need to check for circular dependencies // and whether that section exists or not due to sorting method sections := p.Parsers[Defaults] - listDefaults := []sorter.Section{} + listDefaults := make([]sorter.Section, len(sections)) + i := 0 for k, v := range sections { s := sorter.Section{ Name: k, @@ -212,7 +209,8 @@ func (p *configParser) SectionsDefaultsFromSet(sectionType Section, sectionName, if s.Name == sectionName { s.From = defaultsSection } - listDefaults = append(listDefaults, s) + listDefaults[i] = s + i++ } err := sorter.Sort(listDefaults) if err != nil { diff --git a/config-parser/generate/config-file.go b/config-parser/generate/config-file.go index 0b9420ac..ca0a7504 100644 --- a/config-parser/generate/config-file.go +++ b/config-parser/generate/config-file.go @@ -43,7 +43,7 @@ type TableTestData struct { Table string } -type Data struct { //nolint:maligned +type Data struct { ParserMultiple bool ParserSections []string ParserName string @@ -111,7 +111,7 @@ func (c *ConfigFile) AddParserData(parser Data) { //nolint:gocognit // line = testOK[0] if parser.ParserMultiple { lines = testOK - //nolint:gosimple + //nolint:staticcheck for _, line := range testOK { c.Section[section] = append(c.Section[section], line) } @@ -130,7 +130,7 @@ func (c *ConfigFile) AddParserData(parser Data) { //nolint:gocognit if section == "defaults" { if parser.ParserMultiple { linesDefaults = testOKDefaults - //nolint:gosimple + //nolint:staticcheck for _, line := range testOKDefaults { c.Section[section] = append(c.Section[section], line) } @@ -143,7 +143,7 @@ func (c *ConfigFile) AddParserData(parser Data) { //nolint:gocognit if section == "frontend" { if parser.ParserMultiple { linesFrontend = testOKFrontend - //nolint:gosimple + //nolint:staticcheck for _, line := range testOKFrontend { c.Section[section] = append(c.Section[section], line) } @@ -156,7 +156,7 @@ func (c *ConfigFile) AddParserData(parser Data) { //nolint:gocognit if section == "backend" { if parser.ParserMultiple { linesBackend = testOKBackend - //nolint:gosimple + //nolint:staticcheck for _, line := range testOKBackend { c.Section[section] = append(c.Section[section], line) } @@ -168,7 +168,7 @@ func (c *ConfigFile) AddParserData(parser Data) { //nolint:gocognit } if parser.ParserMultiple { lines2 = TestOKEscaped - //nolint:gosimple + //nolint:staticcheck for _, line := range TestOKEscaped { c.Section[section] = append(c.Section[section], line) } @@ -256,7 +256,7 @@ func (c *ConfigFile) StringFiles(baseFolder string) { header := license + "\npackage integration_test\n\n" - sectionTypes := make([]string, len(c.SectionAll)-1) + sectionTypes := make([]string, len(c.SectionAll)-1) //nolint: prealloc index := 0 for sectionName := range c.SectionAll { if sectionName == "global" { @@ -285,7 +285,7 @@ func (c *ConfigFile) StringFiles(baseFolder string) { } usedNiceNames[niceName] = struct{}{} sectionName := " test" - if sectionType == "global" { + if sectionType == "global" || sectionType == "dynamic-update" { sectionName = "" } oneTest := "const " + niceName + " = `\n" + sectionType + sectionName + "\n" + " " + line + "\n`" + "\n" @@ -308,8 +308,9 @@ func (c *ConfigFile) StringFiles(baseFolder string) { testName := cases.Title(language.Und, cases.NoLower).String(getNiceName(sectionName)) testFile.WriteString(strings.Replace(testHeader, "TestWholeConfigsSections", "TestWholeConfigsSections"+testName, 1)) sortedNames := []string{} + sectionNameWithoutDash := strings.ReplaceAll(sectionName, "-", "") for name := range usedNiceNames { - if strings.HasPrefix(name, sectionName) { + if strings.HasPrefix(name, sectionNameWithoutDash) { sortedNames = append(sortedNames, name) } } @@ -355,7 +356,7 @@ var testFooter = ` } buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -365,7 +366,7 @@ var testFooter = ` } t.Error("======== RESULT ===========") t.Error(result) t.Error("===========================") - t.Fatalf("configurations does not match") + t.Fatal("configurations does not match") } }) } diff --git a/config-parser/generate/misc.go b/config-parser/generate/misc.go index 17039ae2..6b66eb37 100644 --- a/config-parser/generate/misc.go +++ b/config-parser/generate/misc.go @@ -123,10 +123,7 @@ func getNiceName(str string) string { } } strRes := res.String() - size := len(strRes) - if size > 32 { - size = 32 - } + size := min(len(strRes), 32) strRes = strRes[0:size] return strRes } diff --git a/config-parser/generate/test.tmpl b/config-parser/generate/test.tmpl index 0f75f0db..9d7f05f7 100644 --- a/config-parser/generate/test.tmpl +++ b/config-parser/generate/test.tmpl @@ -58,12 +58,12 @@ func Test{{ $StructName }}{{ .Dir }}(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -73,15 +73,15 @@ func Test{{ $StructName }}{{ .Dir }}(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) @@ -104,12 +104,12 @@ func Test{{ $StructName }}{{ .Dir }}(t *testing.T) { err = ProcessLine(line, parser) } if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -119,7 +119,7 @@ func Test{{ $StructName }}{{ .Dir }}(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if expected != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, expected)) + t.Errorf("error: has [%s] expects [%s]", returnLine, expected) } }) } @@ -156,12 +156,12 @@ func TestAlias{{ $StructName }}{{ .Dir }}(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -171,15 +171,15 @@ func TestAlias{{ $StructName }}{{ .Dir }}(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/params/balance-params.go b/config-parser/params/balance-params.go index d38ea774..4e6ceea0 100644 --- a/config-parser/params/balance-params.go +++ b/config-parser/params/balance-params.go @@ -42,7 +42,6 @@ func (b *BalanceURI) String() string { func (b *BalanceURI) Parse(parts []string) (BalanceParams, error) { var err error if len(parts) > 0 { - for i := 0; i < len(parts); i++ { arg := parts[i] @@ -98,7 +97,6 @@ func (u *BalanceURLParam) String() string { func (u *BalanceURLParam) Parse(parts []string) (BalanceParams, error) { var err error if len(parts) > 0 { - for index := 1; index < len(parts); index++ { arg := parts[index] diff --git a/config-parser/params/bind-errors.go b/config-parser/params/bind-errors.go index cbf9be1e..c55d4634 100644 --- a/config-parser/params/bind-errors.go +++ b/config-parser/params/bind-errors.go @@ -18,11 +18,11 @@ package params import "fmt" -type ErrParseBindOption interface { +type ErrParseBindOption interface { //nolint:iface Error() string } -type ErrParseServerOption interface { +type ErrParseServerOption interface { //nolint:iface Error() string } diff --git a/config-parser/params/bind-options.go b/config-parser/params/bind-options.go index 07d73847..405a43c2 100644 --- a/config-parser/params/bind-options.go +++ b/config-parser/params/bind-options.go @@ -23,7 +23,7 @@ import ( ) // BindOption ... -type BindOption interface { +type BindOption interface { //nolint:iface Parse(options []string, currentIndex int) (int, error) Valid() bool String() string diff --git a/config-parser/params/dgram-bind-options.go b/config-parser/params/dgram-bind-options.go index 51c89560..6c148d78 100644 --- a/config-parser/params/dgram-bind-options.go +++ b/config-parser/params/dgram-bind-options.go @@ -21,7 +21,7 @@ import ( ) // DgramBindOption ... -type DgramBindOption interface { +type DgramBindOption interface { //nolint:iface Parse(options []string, currentIndex int) (int, error) Valid() bool String() string diff --git a/config-parser/params/server-options.go b/config-parser/params/server-options.go index 99fa7f83..e1f95407 100644 --- a/config-parser/params/server-options.go +++ b/config-parser/params/server-options.go @@ -22,7 +22,7 @@ import ( ) // ServerOption ... -type ServerOption interface { +type ServerOption interface { //nolint:iface Parse(options []string, currentIndex int) (int, error) Valid() bool String() string @@ -127,7 +127,7 @@ type ServerOptionIDValue struct { // Parse ... func (b *ServerOptionIDValue) Parse(options []string, currentIndex int) (int, error) { if currentIndex+1 < len(options) { - if strings.HasPrefix(options[currentIndex], fmt.Sprintf("%s(", b.Name)) { + if strings.HasPrefix(options[currentIndex], b.Name+"(") { words := strings.Split(options[currentIndex], "(") if len(words) != 2 { return 0, &NotEnoughParamsError{} @@ -157,119 +157,127 @@ func (b *ServerOptionIDValue) String() string { return fmt.Sprintf("%s(%s) %s", b.Name, b.ID, b.Value) } -func getServerOptions() []ServerOption { - return []ServerOption{ - &ServerOptionWord{Name: "agent-check"}, - &ServerOptionWord{Name: "allow-0rtt"}, - &ServerOptionWord{Name: "backup"}, - &ServerOptionWord{Name: "check"}, - &ServerOptionWord{Name: "check-send-proxy"}, - &ServerOptionWord{Name: "check-ssl"}, - &ServerOptionWord{Name: "check-via-socks4"}, - &ServerOptionWord{Name: "disabled"}, - &ServerOptionWord{Name: "enabled"}, - &ServerOptionWord{Name: "force-sslv3"}, - &ServerOptionWord{Name: "force-tlsv10"}, - &ServerOptionWord{Name: "force-tlsv11"}, - &ServerOptionWord{Name: "force-tlsv12"}, - &ServerOptionWord{Name: "force-tlsv13"}, - &ServerOptionWord{Name: "no-agent-check"}, - &ServerOptionWord{Name: "no-backup"}, - &ServerOptionWord{Name: "no-check"}, - &ServerOptionWord{Name: "no-check-ssl"}, - &ServerOptionWord{Name: "no-send-proxy"}, - &ServerOptionWord{Name: "no-send-proxy-v2"}, - &ServerOptionWord{Name: "no-send-proxy-v2-ssl"}, - &ServerOptionWord{Name: "no-send-proxy-v2-ssl-cn"}, - &ServerOptionWord{Name: "no-ssl"}, - &ServerOptionWord{Name: "no-ssl-reuse"}, - &ServerOptionWord{Name: "no-sslv3"}, - &ServerOptionWord{Name: "no-tls-tickets"}, - &ServerOptionWord{Name: "no-tlsv10"}, - &ServerOptionWord{Name: "no-tlsv11"}, - &ServerOptionWord{Name: "no-tlsv12"}, - &ServerOptionWord{Name: "no-tlsv13"}, - &ServerOptionWord{Name: "no-verifyhost"}, - &ServerOptionWord{Name: "no-tfo"}, - &ServerOptionWord{Name: "non-stick"}, - &ServerOptionWord{Name: "send-proxy"}, - &ServerOptionWord{Name: "send-proxy-v2"}, - &ServerOptionWord{Name: "send-proxy-v2-ssl"}, - &ServerOptionWord{Name: "send-proxy-v2-ssl-cn"}, - &ServerOptionWord{Name: "ssl"}, - &ServerOptionWord{Name: "ssl-reuse"}, - &ServerOptionWord{Name: "stick"}, - &ServerOptionWord{Name: "tfo"}, - &ServerOptionWord{Name: "tls-tickets"}, - &ServerOptionValue{Name: "addr"}, - &ServerOptionValue{Name: "agent-send"}, - &ServerOptionValue{Name: "agent-inter"}, - &ServerOptionValue{Name: "agent-addr"}, - &ServerOptionValue{Name: "agent-port"}, - &ServerOptionValue{Name: "alpn"}, - &ServerOptionValue{Name: "ca-file"}, - &ServerOptionValue{Name: "check-alpn"}, - &ServerOptionValue{Name: "check-proto"}, - &ServerOptionValue{Name: "check-sni"}, - &ServerOptionValue{Name: "ciphers"}, - &ServerOptionValue{Name: "ciphersuites"}, - &ServerOptionValue{Name: "client-sigalgs"}, - &ServerOptionValue{Name: "cookie"}, - &ServerOptionValue{Name: "crl-file"}, - &ServerOptionValue{Name: "crt"}, - &ServerOptionValue{Name: "curves"}, - &ServerOptionValue{Name: "error-limit"}, - &ServerOptionValue{Name: "fall"}, - &ServerOptionValue{Name: "id"}, - &ServerOptionValue{Name: "init-addr"}, - &ServerOptionValue{Name: "inter"}, - &ServerOptionValue{Name: "fastinter"}, - &ServerOptionValue{Name: "downinter"}, - &ServerOptionValue{Name: "log-proto"}, - &ServerOptionValue{Name: "maxconn"}, - &ServerOptionValue{Name: "maxqueue"}, - &ServerOptionValue{Name: "max-reuse"}, - &ServerOptionValue{Name: "minconn"}, - &ServerOptionValue{Name: "namespace"}, - &ServerOptionValue{Name: "npn"}, - &ServerOptionValue{Name: "observe"}, - &ServerOptionValue{Name: "on-error"}, - &ServerOptionValue{Name: "on-marked-down"}, - &ServerOptionValue{Name: "on-marked-up"}, - &ServerOptionValue{Name: "pool-max-conn"}, - &ServerOptionValue{Name: "pool-purge-delay"}, - &ServerOptionValue{Name: "port"}, - &ServerOptionValue{Name: "proto"}, - &ServerOptionValue{Name: "redir"}, - &ServerOptionValue{Name: "rise"}, - &ServerOptionValue{Name: "resolve-opts"}, - &ServerOptionValue{Name: "resolve-prefer"}, - &ServerOptionValue{Name: "resolve-net"}, - &ServerOptionValue{Name: "resolvers"}, - &ServerOptionValue{Name: "proxy-v2-options"}, - &ServerOptionValue{Name: "shard"}, - &ServerOptionValue{Name: "sigalgs"}, - &ServerOptionValue{Name: "slowstart"}, - &ServerOptionValue{Name: "sni"}, - &ServerOptionValue{Name: "source"}, - &ServerOptionValue{Name: "usesrc"}, - &ServerOptionValue{Name: "interface"}, - &ServerOptionValue{Name: "ssl-max-ver"}, - &ServerOptionValue{Name: "ssl-min-ver"}, - &ServerOptionValue{Name: "socks4"}, - &ServerOptionValue{Name: "tcp-ut"}, - &ServerOptionValue{Name: "track"}, - &ServerOptionValue{Name: "verify"}, - &ServerOptionValue{Name: "verifyhost"}, - &ServerOptionValue{Name: "weight"}, - &ServerOptionValue{Name: "pool-low-conn"}, - &ServerOptionValue{Name: "ws"}, - &ServerOptionValue{Name: "log-bufsize"}, - &ServerOptionValue{Name: "guid"}, - &ServerOptionIDValue{Name: "set-proxy-v2-tlv-fmt"}, - &ServerOptionValue{Name: "pool-conn-name"}, - &ServerOptionValue{Name: "hash-key"}, +var serverOptionFactoryMethods = map[string]func() ServerOption{ //nolint:gochecknoglobals + "agent-check": func() ServerOption { return &ServerOptionWord{Name: "agent-check"} }, + "allow-0rtt": func() ServerOption { return &ServerOptionWord{Name: "allow-0rtt"} }, + "backup": func() ServerOption { return &ServerOptionWord{Name: "backup"} }, + "check": func() ServerOption { return &ServerOptionWord{Name: "check"} }, + "check-send-proxy": func() ServerOption { return &ServerOptionWord{Name: "check-send-proxy"} }, + "check-ssl": func() ServerOption { return &ServerOptionWord{Name: "check-ssl"} }, + "check-via-socks4": func() ServerOption { return &ServerOptionWord{Name: "check-via-socks4"} }, + "disabled": func() ServerOption { return &ServerOptionWord{Name: "disabled"} }, + "enabled": func() ServerOption { return &ServerOptionWord{Name: "enabled"} }, + "force-sslv3": func() ServerOption { return &ServerOptionWord{Name: "force-sslv3"} }, + "force-tlsv10": func() ServerOption { return &ServerOptionWord{Name: "force-tlsv10"} }, + "force-tlsv11": func() ServerOption { return &ServerOptionWord{Name: "force-tlsv11"} }, + "force-tlsv12": func() ServerOption { return &ServerOptionWord{Name: "force-tlsv12"} }, + "force-tlsv13": func() ServerOption { return &ServerOptionWord{Name: "force-tlsv13"} }, + "no-agent-check": func() ServerOption { return &ServerOptionWord{Name: "no-agent-check"} }, + "no-backup": func() ServerOption { return &ServerOptionWord{Name: "no-backup"} }, + "no-check": func() ServerOption { return &ServerOptionWord{Name: "no-check"} }, + "no-check-send-proxy": func() ServerOption { return &ServerOptionWord{Name: "no-check-send-proxy"} }, + "no-check-ssl": func() ServerOption { return &ServerOptionWord{Name: "no-check-ssl"} }, + "no-send-proxy": func() ServerOption { return &ServerOptionWord{Name: "no-send-proxy"} }, + "no-send-proxy-v2": func() ServerOption { return &ServerOptionWord{Name: "no-send-proxy-v2"} }, + "no-send-proxy-v2-ssl": func() ServerOption { return &ServerOptionWord{Name: "no-send-proxy-v2-ssl"} }, + "no-send-proxy-v2-ssl-cn": func() ServerOption { return &ServerOptionWord{Name: "no-send-proxy-v2-ssl-cn"} }, + "no-ssl": func() ServerOption { return &ServerOptionWord{Name: "no-ssl"} }, + "no-ssl-reuse": func() ServerOption { return &ServerOptionWord{Name: "no-ssl-reuse"} }, + "no-sslv3": func() ServerOption { return &ServerOptionWord{Name: "no-sslv3"} }, + "no-tls-tickets": func() ServerOption { return &ServerOptionWord{Name: "no-tls-tickets"} }, + "no-tlsv10": func() ServerOption { return &ServerOptionWord{Name: "no-tlsv10"} }, + "no-tlsv11": func() ServerOption { return &ServerOptionWord{Name: "no-tlsv11"} }, + "no-tlsv12": func() ServerOption { return &ServerOptionWord{Name: "no-tlsv12"} }, + "no-tlsv13": func() ServerOption { return &ServerOptionWord{Name: "no-tlsv13"} }, + "no-verifyhost": func() ServerOption { return &ServerOptionWord{Name: "no-verifyhost"} }, + "no-tfo": func() ServerOption { return &ServerOptionWord{Name: "no-tfo"} }, + "non-stick": func() ServerOption { return &ServerOptionWord{Name: "non-stick"} }, + "send-proxy": func() ServerOption { return &ServerOptionWord{Name: "send-proxy"} }, + "send-proxy-v2": func() ServerOption { return &ServerOptionWord{Name: "send-proxy-v2"} }, + "send-proxy-v2-ssl": func() ServerOption { return &ServerOptionWord{Name: "send-proxy-v2-ssl"} }, + "send-proxy-v2-ssl-cn": func() ServerOption { return &ServerOptionWord{Name: "send-proxy-v2-ssl-cn"} }, + "ssl": func() ServerOption { return &ServerOptionWord{Name: "ssl"} }, + "ssl-reuse": func() ServerOption { return &ServerOptionWord{Name: "ssl-reuse"} }, + "stick": func() ServerOption { return &ServerOptionWord{Name: "stick"} }, + "tfo": func() ServerOption { return &ServerOptionWord{Name: "tfo"} }, + "tls-tickets": func() ServerOption { return &ServerOptionWord{Name: "tls-tickets"} }, + "addr": func() ServerOption { return &ServerOptionValue{Name: "addr"} }, + "agent-send": func() ServerOption { return &ServerOptionValue{Name: "agent-send"} }, + "agent-inter": func() ServerOption { return &ServerOptionValue{Name: "agent-inter"} }, + "agent-addr": func() ServerOption { return &ServerOptionValue{Name: "agent-addr"} }, + "agent-port": func() ServerOption { return &ServerOptionValue{Name: "agent-port"} }, + "alpn": func() ServerOption { return &ServerOptionValue{Name: "alpn"} }, + "ca-file": func() ServerOption { return &ServerOptionValue{Name: "ca-file"} }, + "check-alpn": func() ServerOption { return &ServerOptionValue{Name: "check-alpn"} }, + "check-proto": func() ServerOption { return &ServerOptionValue{Name: "check-proto"} }, + "check-sni": func() ServerOption { return &ServerOptionValue{Name: "check-sni"} }, + "ciphers": func() ServerOption { return &ServerOptionValue{Name: "ciphers"} }, + "ciphersuites": func() ServerOption { return &ServerOptionValue{Name: "ciphersuites"} }, + "client-sigalgs": func() ServerOption { return &ServerOptionValue{Name: "client-sigalgs"} }, + "cookie": func() ServerOption { return &ServerOptionValue{Name: "cookie"} }, + "crl-file": func() ServerOption { return &ServerOptionValue{Name: "crl-file"} }, + "crt": func() ServerOption { return &ServerOptionValue{Name: "crt"} }, + "curves": func() ServerOption { return &ServerOptionValue{Name: "curves"} }, + "error-limit": func() ServerOption { return &ServerOptionValue{Name: "error-limit"} }, + "fall": func() ServerOption { return &ServerOptionValue{Name: "fall"} }, + "id": func() ServerOption { return &ServerOptionValue{Name: "id"} }, + "init-addr": func() ServerOption { return &ServerOptionValue{Name: "init-addr"} }, + "inter": func() ServerOption { return &ServerOptionValue{Name: "inter"} }, + "fastinter": func() ServerOption { return &ServerOptionValue{Name: "fastinter"} }, + "downinter": func() ServerOption { return &ServerOptionValue{Name: "downinter"} }, + "log-proto": func() ServerOption { return &ServerOptionValue{Name: "log-proto"} }, + "maxconn": func() ServerOption { return &ServerOptionValue{Name: "maxconn"} }, + "maxqueue": func() ServerOption { return &ServerOptionValue{Name: "maxqueue"} }, + "max-reuse": func() ServerOption { return &ServerOptionValue{Name: "max-reuse"} }, + "minconn": func() ServerOption { return &ServerOptionValue{Name: "minconn"} }, + "namespace": func() ServerOption { return &ServerOptionValue{Name: "namespace"} }, + "npn": func() ServerOption { return &ServerOptionValue{Name: "npn"} }, + "observe": func() ServerOption { return &ServerOptionValue{Name: "observe"} }, + "on-error": func() ServerOption { return &ServerOptionValue{Name: "on-error"} }, + "on-marked-down": func() ServerOption { return &ServerOptionValue{Name: "on-marked-down"} }, + "on-marked-up": func() ServerOption { return &ServerOptionValue{Name: "on-marked-up"} }, + "pool-max-conn": func() ServerOption { return &ServerOptionValue{Name: "pool-max-conn"} }, + "pool-purge-delay": func() ServerOption { return &ServerOptionValue{Name: "pool-purge-delay"} }, + "port": func() ServerOption { return &ServerOptionValue{Name: "port"} }, + "proto": func() ServerOption { return &ServerOptionValue{Name: "proto"} }, + "redir": func() ServerOption { return &ServerOptionValue{Name: "redir"} }, + "rise": func() ServerOption { return &ServerOptionValue{Name: "rise"} }, + "resolve-opts": func() ServerOption { return &ServerOptionValue{Name: "resolve-opts"} }, + "resolve-prefer": func() ServerOption { return &ServerOptionValue{Name: "resolve-prefer"} }, + "resolve-net": func() ServerOption { return &ServerOptionValue{Name: "resolve-net"} }, + "resolvers": func() ServerOption { return &ServerOptionValue{Name: "resolvers"} }, + "proxy-v2-options": func() ServerOption { return &ServerOptionValue{Name: "proxy-v2-options"} }, + "shard": func() ServerOption { return &ServerOptionValue{Name: "shard"} }, + "sigalgs": func() ServerOption { return &ServerOptionValue{Name: "sigalgs"} }, + "slowstart": func() ServerOption { return &ServerOptionValue{Name: "slowstart"} }, + "sni": func() ServerOption { return &ServerOptionValue{Name: "sni"} }, + "source": func() ServerOption { return &ServerOptionValue{Name: "source"} }, + "usesrc": func() ServerOption { return &ServerOptionValue{Name: "usesrc"} }, + "interface": func() ServerOption { return &ServerOptionValue{Name: "interface"} }, + "ssl-max-ver": func() ServerOption { return &ServerOptionValue{Name: "ssl-max-ver"} }, + "ssl-min-ver": func() ServerOption { return &ServerOptionValue{Name: "ssl-min-ver"} }, + "socks4": func() ServerOption { return &ServerOptionValue{Name: "socks4"} }, + "tcp-ut": func() ServerOption { return &ServerOptionValue{Name: "tcp-ut"} }, + "track": func() ServerOption { return &ServerOptionValue{Name: "track"} }, + "verify": func() ServerOption { return &ServerOptionValue{Name: "verify"} }, + "verifyhost": func() ServerOption { return &ServerOptionValue{Name: "verifyhost"} }, + "weight": func() ServerOption { return &ServerOptionValue{Name: "weight"} }, + "pool-low-conn": func() ServerOption { return &ServerOptionValue{Name: "pool-low-conn"} }, + "ws": func() ServerOption { return &ServerOptionValue{Name: "ws"} }, + "log-bufsize": func() ServerOption { return &ServerOptionValue{Name: "log-bufsize"} }, + "set-proxy-v2-tlv-fmt": func() ServerOption { return &ServerOptionIDValue{Name: "set-proxy-v2-tlv-fmt"} }, + "guid": func() ServerOption { return &ServerOptionValue{Name: "guid"} }, + "pool-conn-name": func() ServerOption { return &ServerOptionValue{Name: "pool-conn-name"} }, + "hash-key": func() ServerOption { return &ServerOptionValue{Name: "hash-key"} }, +} + +func getServerOption(option string) ServerOption { + option = strings.Split(option, "(")[0] + + if factoryMethod, found := serverOptionFactoryMethods[option]; found { + return factoryMethod() } + return nil } // Parse ... @@ -277,16 +285,14 @@ func ParseServerOptions(options []string) []ServerOption { result := []ServerOption{} currentIndex := 0 for currentIndex < len(options) { - found := false - for _, parser := range getServerOptions() { - if size, err := parser.Parse(options, currentIndex); err == nil { - result = append(result, parser) - found = true - currentIndex += size - } - } - if !found { + serverOption := getServerOption(options[currentIndex]) + if serverOption == nil { currentIndex++ + continue + } + if size, err := serverOption.Parse(options, currentIndex); err == nil { + result = append(result, serverOption) + currentIndex += size } } return result diff --git a/config-parser/parser-type.go b/config-parser/parser-type.go index e536fb87..5b27ad4d 100644 --- a/config-parser/parser-type.go +++ b/config-parser/parser-type.go @@ -45,12 +45,8 @@ type Parsers struct { } func (p *Parsers) Get(attribute string, createIfNotExist ...bool) (common.ParserData, error) { - createNew := false - if len(createIfNotExist) > 0 && createIfNotExist[0] { - createNew = true - } if parser, ok := p.Parsers[attribute]; ok { - return parser.Get(createNew) + return parser.Get(len(createIfNotExist) > 0 && createIfNotExist[0]) } return nil, errors.ErrParserMissing diff --git a/config-parser/parsers/actions/check-connect.go b/config-parser/parsers/actions/check-connect.go index 6d50442e..a4cb3cb5 100644 --- a/config-parser/parsers/actions/check-connect.go +++ b/config-parser/parsers/actions/check-connect.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -50,7 +50,7 @@ func (c *CheckConnect) Parse(parts []string, parserType types.ParserType, commen // Note: "tcp/http-check connect" with no further params is allowed by HAProxy if len(parts) < 2 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } for i := 2; i < len(parts); i++ { diff --git a/config-parser/parsers/actions/check-expect.go b/config-parser/parsers/actions/check-expect.go index a6254577..a2011d1e 100644 --- a/config-parser/parsers/actions/check-expect.go +++ b/config-parser/parsers/actions/check-expect.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strconv" "strings" @@ -52,7 +52,7 @@ func (c *CheckExpect) Parse(parts []string, parserType types.ParserType, comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var i int diff --git a/config-parser/parsers/actions/check-set-var-fmt.go b/config-parser/parsers/actions/check-set-var-fmt.go index e832806d..bf5cbdd1 100644 --- a/config-parser/parsers/actions/check-set-var-fmt.go +++ b/config-parser/parsers/actions/check-set-var-fmt.go @@ -18,6 +18,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -38,7 +39,7 @@ func (f *SetVarFmtCheck) Parse(parts []string, parserType types.ParserType, comm f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var data string var command []string @@ -56,11 +57,11 @@ func (f *SetVarFmtCheck) Parse(parts []string, parserType types.ParserType, comm format := common.Expression{} err := format.Parse(command) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Format = format } else { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } if len(condition) > 1 { return errors.ErrInvalidData diff --git a/config-parser/parsers/actions/do-resolve.go b/config-parser/parsers/actions/do-resolve.go index 09133143..dac38c9a 100644 --- a/config-parser/parsers/actions/do-resolve.go +++ b/config-parser/parsers/actions/do-resolve.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -39,7 +40,7 @@ func (f *DoResolve) Parse(parts []string, parserType types.ParserType, comment s f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var data string var command []string @@ -56,7 +57,7 @@ func (f *DoResolve) Parse(parts []string, parserType types.ParserType, comment s d := strings.SplitN(data, ",", 3) if len(d) < 2 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Var = d[0] @@ -70,7 +71,7 @@ func (f *DoResolve) Parse(parts []string, parserType types.ParserType, comment s expr := common.Expression{} err := expr.Parse(command) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr } diff --git a/config-parser/parsers/actions/lua.go b/config-parser/parsers/actions/lua.go index b9214746..a2bcdbfa 100644 --- a/config-parser/parsers/actions/lua.go +++ b/config-parser/parsers/actions/lua.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -38,7 +38,7 @@ func (f *Lua) Parse(parts []string, parserType types.ParserType, comment string) f.Comment = comment } if len(parts) < 2 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var data string var command []string diff --git a/config-parser/parsers/actions/reject.go b/config-parser/parsers/actions/reject.go index 4cfcf634..795044b3 100644 --- a/config-parser/parsers/actions/reject.go +++ b/config-parser/parsers/actions/reject.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -50,7 +51,7 @@ func (f *Reject) Parse(parts []string, parserType types.ParserType, comment stri return nil } if len(parts) < requiredLen { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } _, condition := common.SplitRequest(command) if len(condition) > 1 { diff --git a/config-parser/parsers/actions/sc-inc-gpc0.go b/config-parser/parsers/actions/sc-inc-gpc0.go index 6a6bdddc..bf7a5b4d 100644 --- a/config-parser/parsers/actions/sc-inc-gpc0.go +++ b/config-parser/parsers/actions/sc-inc-gpc0.go @@ -18,7 +18,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -57,7 +57,7 @@ func (f *ScIncGpc0) Parse(parts []string, parserType types.ParserType, comment s return nil } if len(parts) < requiredLen { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } _, condition := common.SplitRequest(command) if len(condition) > 1 { diff --git a/config-parser/parsers/actions/sc-inc-gpc1.go b/config-parser/parsers/actions/sc-inc-gpc1.go index a75299fc..13f486e0 100644 --- a/config-parser/parsers/actions/sc-inc-gpc1.go +++ b/config-parser/parsers/actions/sc-inc-gpc1.go @@ -18,7 +18,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -57,7 +57,7 @@ func (f *ScIncGpc1) Parse(parts []string, parserType types.ParserType, comment s return nil } if len(parts) < requiredLen { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } _, condition := common.SplitRequest(command) if len(condition) > 1 { diff --git a/config-parser/parsers/actions/sc-set-gpt.go b/config-parser/parsers/actions/sc-set-gpt.go index f1a5ac52..e3f46299 100644 --- a/config-parser/parsers/actions/sc-set-gpt.go +++ b/config-parser/parsers/actions/sc-set-gpt.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strconv" "strings" @@ -41,7 +42,7 @@ func (f *ScSetGpt) Parse(parts []string, parserType types.ParserType, comment st f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var data string var command []string @@ -59,7 +60,7 @@ func (f *ScSetGpt) Parse(parts []string, parserType types.ParserType, comment st end := len(data) - 1 // ignore ")" idIdx := strings.Split(data[start:end], ",") if len(idIdx) != 2 { - return fmt.Errorf("missing sc-id and/or idx") + return stderrors.New("missing sc-id and/or idx") } var err error f.ScID = idIdx[0] @@ -80,7 +81,7 @@ func (f *ScSetGpt) Parse(parts []string, parserType types.ParserType, comment st expr := common.Expression{} err := expr.Parse(command) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr } diff --git a/config-parser/parsers/actions/sc-set-gpt0.go b/config-parser/parsers/actions/sc-set-gpt0.go index b59b5085..0b267ccd 100644 --- a/config-parser/parsers/actions/sc-set-gpt0.go +++ b/config-parser/parsers/actions/sc-set-gpt0.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strconv" "strings" @@ -40,7 +40,7 @@ func (f *ScSetGpt0) Parse(parts []string, parserType types.ParserType, comment s f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var data string var command []string @@ -65,7 +65,7 @@ func (f *ScSetGpt0) Parse(parts []string, parserType types.ParserType, comment s expr := common.Expression{} err := expr.Parse(command) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr } diff --git a/config-parser/parsers/actions/sc_add_gpc.go b/config-parser/parsers/actions/sc_add_gpc.go index 987ec470..4c936515 100644 --- a/config-parser/parsers/actions/sc_add_gpc.go +++ b/config-parser/parsers/actions/sc_add_gpc.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strconv" "strings" @@ -58,7 +58,7 @@ func (f *ScAddGpc) Parse(parts []string, parserType types.ParserType, comment st idIdxValues := strings.SplitN(idIdx, ",", 2) f.Idx, f.ID = idIdxValues[0], idIdxValues[1] if len(parts) < minLen { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } command, condition := common.SplitRequest(command) if len(command) < 1 { @@ -71,7 +71,7 @@ func (f *ScAddGpc) Parse(parts []string, parserType types.ParserType, comment st expr := common.Expression{} err := expr.Parse(command) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr } diff --git a/config-parser/parsers/actions/sc_inc_gpc.go b/config-parser/parsers/actions/sc_inc_gpc.go index 81e4f3ce..2fae6fe9 100644 --- a/config-parser/parsers/actions/sc_inc_gpc.go +++ b/config-parser/parsers/actions/sc_inc_gpc.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -59,7 +59,7 @@ func (f *ScIncGpc) Parse(parts []string, parserType types.ParserType, comment st return nil } if len(parts) < requiredLen { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } _, condition := common.SplitRequest(command) if len(condition) > 1 { diff --git a/config-parser/parsers/actions/send-spoe-group.go b/config-parser/parsers/actions/send-spoe-group.go index 24748429..6a7cfcb7 100644 --- a/config-parser/parsers/actions/send-spoe-group.go +++ b/config-parser/parsers/actions/send-spoe-group.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -38,7 +39,7 @@ func (f *SendSpoeGroup) Parse(parts []string, parserType types.ParserType, comme f.Comment = comment } if len(parts) < 4 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var command []string switch parserType { diff --git a/config-parser/parsers/actions/set-bandwidth-limit.go b/config-parser/parsers/actions/set-bandwidth-limit.go index 06b314d9..c8c1fec5 100644 --- a/config-parser/parsers/actions/set-bandwidth-limit.go +++ b/config-parser/parsers/actions/set-bandwidth-limit.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -42,12 +43,12 @@ func (f *SetBandwidthLimit) Parse(parts []string, parserType types.ParserType, c switch parserType { case types.HTTP: if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } command = parts[2:] case types.TCP: if len(parts) < 4 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } command = parts[3:] } @@ -57,20 +58,20 @@ func (f *SetBandwidthLimit) Parse(parts []string, parserType types.ParserType, c for i := 1; i < len(command); i++ { var expr []string if len(command) < i+2 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } el := command[i] switch el { case "limit": expr, i = f.parseExpr(command, i+1, "period") if len(expr) == 0 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Limit.Expr = expr case "period": expr, i = f.parseExpr(command, i+1, "limit") if len(expr) == 0 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Period.Expr = expr default: diff --git a/config-parser/parsers/actions/set-bc-mark.go b/config-parser/parsers/actions/set-bc-mark.go index 8843d88e..7d4c5a3c 100644 --- a/config-parser/parsers/actions/set-bc-mark.go +++ b/config-parser/parsers/actions/set-bc-mark.go @@ -18,6 +18,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "math" "strings" @@ -38,7 +39,7 @@ func (f *SetBcMark) Parse(parts []string, parserType types.ParserType, comment s f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var command []string switch parserType { @@ -56,7 +57,7 @@ func (f *SetBcMark) Parse(parts []string, parserType types.ParserType, comment s expr := common.Expression{} err := expr.Parse(command) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr } diff --git a/config-parser/parsers/actions/set-bc-tos.go b/config-parser/parsers/actions/set-bc-tos.go index cc52ad09..94c7329b 100644 --- a/config-parser/parsers/actions/set-bc-tos.go +++ b/config-parser/parsers/actions/set-bc-tos.go @@ -18,6 +18,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "math" "strings" @@ -38,7 +39,7 @@ func (f *SetBcTos) Parse(parts []string, parserType types.ParserType, comment st f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var command []string switch parserType { @@ -56,7 +57,7 @@ func (f *SetBcTos) Parse(parts []string, parserType types.ParserType, comment st expr := common.Expression{} err := expr.Parse(command) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr } diff --git a/config-parser/parsers/actions/set-dst-port.go b/config-parser/parsers/actions/set-dst-port.go index 70adf044..22d24a69 100644 --- a/config-parser/parsers/actions/set-dst-port.go +++ b/config-parser/parsers/actions/set-dst-port.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -36,7 +37,7 @@ func (f *SetDstPort) Parse(parts []string, parserType types.ParserType, comment f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var command []string switch parserType { @@ -51,7 +52,7 @@ func (f *SetDstPort) Parse(parts []string, parserType types.ParserType, comment expr := common.Expression{} err := expr.Parse(command) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr } @@ -64,7 +65,7 @@ func (f *SetDstPort) Parse(parts []string, parserType types.ParserType, comment func (f *SetDstPort) String() string { if f.Cond == "" { - return fmt.Sprintf("set-dst-port %s", f.Expr.String()) + return "set-dst-port " + f.Expr.String() } return fmt.Sprintf("set-dst-port %s %s %s", f.Expr.String(), f.Cond, f.CondTest) } diff --git a/config-parser/parsers/actions/set-dst.go b/config-parser/parsers/actions/set-dst.go index e14d0c7b..3f4f009b 100644 --- a/config-parser/parsers/actions/set-dst.go +++ b/config-parser/parsers/actions/set-dst.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -36,7 +37,7 @@ func (f *SetDst) Parse(parts []string, parserType types.ParserType, comment stri f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var command []string switch parserType { @@ -48,12 +49,12 @@ func (f *SetDst) Parse(parts []string, parserType types.ParserType, comment stri command, condition := common.SplitRequest(command) if len(command) == 0 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } expr := common.Expression{} if err := expr.Parse(command); err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr if len(condition) > 1 { @@ -65,7 +66,7 @@ func (f *SetDst) Parse(parts []string, parserType types.ParserType, comment stri func (f *SetDst) String() string { if f.Cond == "" { - return fmt.Sprintf("set-dst %s", f.Expr.String()) + return "set-dst " + f.Expr.String() } return fmt.Sprintf("set-dst %s %s %s", f.Expr.String(), f.Cond, f.CondTest) } diff --git a/config-parser/parsers/actions/set-fc-mark.go b/config-parser/parsers/actions/set-fc-mark.go index 35c2b1d0..1254da07 100644 --- a/config-parser/parsers/actions/set-fc-mark.go +++ b/config-parser/parsers/actions/set-fc-mark.go @@ -18,6 +18,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "math" "strings" @@ -38,7 +39,7 @@ func (f *SetFcMark) Parse(parts []string, parserType types.ParserType, comment s f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var command []string switch parserType { @@ -56,7 +57,7 @@ func (f *SetFcMark) Parse(parts []string, parserType types.ParserType, comment s expr := common.Expression{} err := expr.Parse(command) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr } diff --git a/config-parser/parsers/actions/set-fc-tos.go b/config-parser/parsers/actions/set-fc-tos.go index b42c0984..a7960b29 100644 --- a/config-parser/parsers/actions/set-fc-tos.go +++ b/config-parser/parsers/actions/set-fc-tos.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "math" "strconv" @@ -38,7 +39,7 @@ func (f *SetFcTos) Parse(parts []string, parserType types.ParserType, comment st f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var command []string switch parserType { @@ -56,7 +57,7 @@ func (f *SetFcTos) Parse(parts []string, parserType types.ParserType, comment st expr := common.Expression{} err := expr.Parse(command) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr } @@ -78,7 +79,7 @@ func (f *SetFcTos) GetComment() string { // Test if the given string is an unsigned integer between zero and "max". // The number can be in decimal or hexadecimal (0x). // If the parsing failed, assume the string was an Expr and return true. -func validateUnsignedNumber(text string, max int64) bool { +func validateUnsignedNumber(text string, maximum int64) bool { var n int64 var err error if strings.HasPrefix(text, "0x") { @@ -90,5 +91,5 @@ func validateUnsignedNumber(text string, max int64) bool { // Assume it was an expression, not a number. return true } - return n >= 0 && n <= max + return n >= 0 && n <= maximum } diff --git a/config-parser/parsers/actions/set-log-level.go b/config-parser/parsers/actions/set-log-level.go index 6fbff6b1..8f94149a 100644 --- a/config-parser/parsers/actions/set-log-level.go +++ b/config-parser/parsers/actions/set-log-level.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -58,7 +59,7 @@ func (f *SetLogLevel) Parse(parts []string, parserType types.ParserType, comment } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *SetLogLevel) String() string { diff --git a/config-parser/parsers/actions/set-mark.go b/config-parser/parsers/actions/set-mark.go index 50df61bd..56dd7e5a 100644 --- a/config-parser/parsers/actions/set-mark.go +++ b/config-parser/parsers/actions/set-mark.go @@ -18,7 +18,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -59,7 +59,7 @@ func (f *SetMark) Parse(parts []string, parserType types.ParserType, comment str } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *SetMark) String() string { diff --git a/config-parser/parsers/actions/set-nice.go b/config-parser/parsers/actions/set-nice.go index f75e6183..4a1883e4 100644 --- a/config-parser/parsers/actions/set-nice.go +++ b/config-parser/parsers/actions/set-nice.go @@ -18,7 +18,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -59,7 +59,7 @@ func (f *SetNice) Parse(parts []string, parserType types.ParserType, comment str } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *SetNice) String() string { diff --git a/config-parser/parsers/actions/set-priority-class.go b/config-parser/parsers/actions/set-priority-class.go index 872df94a..7ca78c0e 100644 --- a/config-parser/parsers/actions/set-priority-class.go +++ b/config-parser/parsers/actions/set-priority-class.go @@ -18,7 +18,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -38,7 +38,7 @@ func (f *SetPriorityClass) Parse(parts []string, parserType types.ParserType, co f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var command []string switch parserType { @@ -53,7 +53,7 @@ func (f *SetPriorityClass) Parse(parts []string, parserType types.ParserType, co } expr := common.Expression{} if expr.Parse(command) != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr if len(condition) > 1 { diff --git a/config-parser/parsers/actions/set-priority-offset.go b/config-parser/parsers/actions/set-priority-offset.go index 59aabaa2..ab59391c 100644 --- a/config-parser/parsers/actions/set-priority-offset.go +++ b/config-parser/parsers/actions/set-priority-offset.go @@ -18,7 +18,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -38,7 +38,7 @@ func (f *SetPriorityOffset) Parse(parts []string, parserType types.ParserType, c f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var command []string switch parserType { @@ -53,7 +53,7 @@ func (f *SetPriorityOffset) Parse(parts []string, parserType types.ParserType, c } expr := common.Expression{} if expr.Parse(command) != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr if len(condition) > 1 { diff --git a/config-parser/parsers/actions/set-src-port.go b/config-parser/parsers/actions/set-src-port.go index bef7756d..4496801b 100644 --- a/config-parser/parsers/actions/set-src-port.go +++ b/config-parser/parsers/actions/set-src-port.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -54,7 +54,7 @@ func (f *SetSrcPort) Parse(parts []string, parserType types.ParserType, comment expr := common.Expression{} err := expr.Parse(command) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr if len(condition) > 1 { @@ -63,7 +63,7 @@ func (f *SetSrcPort) Parse(parts []string, parserType types.ParserType, comment } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *SetSrcPort) String() string { diff --git a/config-parser/parsers/actions/set-tos.go b/config-parser/parsers/actions/set-tos.go index b8fcd53d..aaa8da8e 100644 --- a/config-parser/parsers/actions/set-tos.go +++ b/config-parser/parsers/actions/set-tos.go @@ -18,7 +18,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -58,7 +58,7 @@ func (f *SetTos) Parse(parts []string, parserType types.ParserType, comment stri } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *SetTos) String() string { diff --git a/config-parser/parsers/actions/set-var-check.go b/config-parser/parsers/actions/set-var-check.go index c8f6beae..bf02e9f9 100644 --- a/config-parser/parsers/actions/set-var-check.go +++ b/config-parser/parsers/actions/set-var-check.go @@ -18,6 +18,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -38,7 +39,7 @@ func (f *SetVarCheck) Parse(parts []string, parserType types.ParserType, comment f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var data string var command []string @@ -56,11 +57,11 @@ func (f *SetVarCheck) Parse(parts []string, parserType types.ParserType, comment expr := common.Expression{} err := expr.Parse(command) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr } else { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } if len(condition) > 1 { return errors.ErrInvalidData diff --git a/config-parser/parsers/actions/set-var-fmt.go b/config-parser/parsers/actions/set-var-fmt.go index fee9d07d..c2f5176c 100644 --- a/config-parser/parsers/actions/set-var-fmt.go +++ b/config-parser/parsers/actions/set-var-fmt.go @@ -18,6 +18,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -39,7 +40,7 @@ func (f *SetVarFmt) Parse(parts []string, parserType types.ParserType, comment s f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var data string var command []string @@ -61,7 +62,7 @@ func (f *SetVarFmt) Parse(parts []string, parserType types.ParserType, comment s expr := common.Expression{} err := expr.Parse(command) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Fmt = expr } diff --git a/config-parser/parsers/actions/set-var.go b/config-parser/parsers/actions/set-var.go index e262c4e8..d76ddcb0 100644 --- a/config-parser/parsers/actions/set-var.go +++ b/config-parser/parsers/actions/set-var.go @@ -18,6 +18,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -39,7 +40,7 @@ func (f *SetVar) Parse(parts []string, parserType types.ParserType, comment stri f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var data string var command []string @@ -61,7 +62,7 @@ func (f *SetVar) Parse(parts []string, parserType types.ParserType, comment stri expr := common.Expression{} err := expr.Parse(command) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr } diff --git a/config-parser/parsers/actions/silent-drop.go b/config-parser/parsers/actions/silent-drop.go index fbd85283..289ea3e1 100644 --- a/config-parser/parsers/actions/silent-drop.go +++ b/config-parser/parsers/actions/silent-drop.go @@ -17,14 +17,17 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" + "strconv" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" + "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" ) type SilentDrop struct { + RstTTL int64 Cond string CondTest string Comment string @@ -35,7 +38,7 @@ func (f *SilentDrop) Parse(parts []string, parserType types.ParserType, comment f.Comment = comment } if len(parts) < 2 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var command []string switch parserType { @@ -44,17 +47,31 @@ func (f *SilentDrop) Parse(parts []string, parserType types.ParserType, comment case types.TCP: command = parts[3:] } - _, condition := common.SplitRequest(command) + command, condition := common.SplitRequest(command) if len(condition) > 1 { f.Cond = condition[0] f.CondTest = strings.Join(condition[1:], " ") } + if len(command) > 0 && command[0] == "rst-ttl" { + if len(command) <= 1 { + return stderrors.New("missing rst-ttl value") + } + rstTTL, err := strconv.ParseInt(command[1], 10, 64) + if err != nil { + return &errors.ParseError{Parser: "SilentDrop", Message: err.Error()} + } + f.RstTTL = rstTTL + } return nil } func (f *SilentDrop) String() string { var result strings.Builder result.WriteString("silent-drop") + if f.RstTTL > 0 { + result.WriteString(" rst-ttl ") + result.WriteString(strconv.FormatInt(f.RstTTL, 10)) + } if f.Cond != "" { result.WriteString(" ") result.WriteString(f.Cond) diff --git a/config-parser/parsers/actions/track-sc.go b/config-parser/parsers/actions/track-sc.go index d5f46bc8..81cb9951 100644 --- a/config-parser/parsers/actions/track-sc.go +++ b/config-parser/parsers/actions/track-sc.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strconv" "strings" @@ -50,13 +50,13 @@ func (f *TrackSc) Parse(parts []string, parserType types.ParserType, comment str switch parserType { case types.HTTP: if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } data = parts[1] command = parts[2:] case types.TCP: if len(parts) < 4 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } data = parts[2] command = parts[3:] @@ -66,7 +66,7 @@ func (f *TrackSc) Parse(parts []string, parserType types.ParserType, comment str counterS := strings.TrimPrefix(data, string(TrackScType)) counter, err := strconv.ParseInt(counterS, 10, 64) if err != nil { - return fmt.Errorf("failed to parse stick-counter") + return stderrors.New("failed to parse stick-counter") } f.StickCounter = counter @@ -81,12 +81,12 @@ func (f *TrackSc) parseCommand(command []string) error { } if len(command) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } command, condition := common.SplitRequest(command) if len(command) > 1 && command[1] == "table" { if len(command) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Key = command[0] f.Table = command[2] diff --git a/config-parser/parsers/actions/unset-var-check.go b/config-parser/parsers/actions/unset-var-check.go index 42d1f6b6..416dcde0 100644 --- a/config-parser/parsers/actions/unset-var-check.go +++ b/config-parser/parsers/actions/unset-var-check.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -36,7 +36,7 @@ func (f *UnsetVarCheck) Parse(parts []string, parserType types.ParserType, comme f.Comment = comment } if len(parts) < 2 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var data string var command []string diff --git a/config-parser/parsers/actions/unset-var.go b/config-parser/parsers/actions/unset-var.go index f4d129c6..ae2032d6 100644 --- a/config-parser/parsers/actions/unset-var.go +++ b/config-parser/parsers/actions/unset-var.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -38,7 +38,7 @@ func (f *UnsetVar) Parse(parts []string, parserType types.ParserType, comment st f.Comment = comment } if len(parts) < 2 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var data string var command []string diff --git a/config-parser/parsers/actions/use-service.go b/config-parser/parsers/actions/use-service.go index beb95935..4eb87e45 100644 --- a/config-parser/parsers/actions/use-service.go +++ b/config-parser/parsers/actions/use-service.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + "errors" "fmt" "strings" @@ -37,7 +38,7 @@ func (us *UseService) Parse(parts []string, parserType types.ParserType, comment us.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return errors.New("not enough params") } var data string var command []string diff --git a/config-parser/parsers/bind-process.go b/config-parser/parsers/bind-process.go index 328e6b4e..35bedb41 100644 --- a/config-parser/parsers/bind-process.go +++ b/config-parser/parsers/bind-process.go @@ -17,7 +17,6 @@ limitations under the License. package parsers import ( - "fmt" "strconv" "strings" @@ -79,7 +78,7 @@ func (p *BindProcess) Result() ([]common.ReturnResultLine, error) { return []common.ReturnResultLine{ { - Data: fmt.Sprintf("bind-process %s", p.data.Process), + Data: "bind-process " + p.data.Process, Comment: p.data.Comment, }, }, nil diff --git a/config-parser/parsers/command.go b/config-parser/parsers/command.go index f672d38d..7e8fcf31 100644 --- a/config-parser/parsers/command.go +++ b/config-parser/parsers/command.go @@ -17,7 +17,6 @@ limitations under the License. package parsers import ( - "fmt" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -36,7 +35,7 @@ func (p *Command) Parse(line string, parts []string, comment string) (string, er } if parts[0] != "command" { - return "", &errors.ParseError{Parser: "Command", Line: line, Message: fmt.Sprintf("expected command, got %s", parts[0])} + return "", &errors.ParseError{Parser: "Command", Line: line, Message: "expected command, got " + parts[0]} } p.data = &types.Command{ diff --git a/config-parser/parsers/compression-algo-req.go b/config-parser/parsers/compression-algo-req.go index 53260dbd..b36fb455 100644 --- a/config-parser/parsers/compression-algo-req.go +++ b/config-parser/parsers/compression-algo-req.go @@ -17,8 +17,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -46,7 +44,7 @@ func (c *CompressionAlgoReq) Result() ([]common.ReturnResultLine, error) { } return []common.ReturnResultLine{ { - Data: fmt.Sprintf("compression algo-req %s", c.data.Value), + Data: "compression algo-req " + c.data.Value, Comment: c.data.Comment, }, }, nil diff --git a/config-parser/parsers/compression-direction.go b/config-parser/parsers/compression-direction.go index e968475e..6ab16a05 100644 --- a/config-parser/parsers/compression-direction.go +++ b/config-parser/parsers/compression-direction.go @@ -17,8 +17,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -46,7 +44,7 @@ func (c *CompressionDirection) Result() ([]common.ReturnResultLine, error) { } return []common.ReturnResultLine{ { - Data: fmt.Sprintf("compression direction %s", c.data.Value), + Data: "compression direction " + c.data.Value, Comment: c.data.Comment, }, }, nil diff --git a/config-parser/parsers/default-backend.go b/config-parser/parsers/default-backend.go index d95050ab..ae12a016 100644 --- a/config-parser/parsers/default-backend.go +++ b/config-parser/parsers/default-backend.go @@ -17,8 +17,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -49,7 +47,7 @@ func (s *DefaultBackend) Result() ([]common.ReturnResultLine, error) { } return []common.ReturnResultLine{ { - Data: fmt.Sprintf("default_backend %s", s.data.Value), + Data: "default_backend " + s.data.Value, Comment: s.data.Comment, }, }, nil diff --git a/config-parser/parsers/default-server.go b/config-parser/parsers/default-server.go index 48f76327..446d77b5 100644 --- a/config-parser/parsers/default-server.go +++ b/config-parser/parsers/default-server.go @@ -17,8 +17,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/params" @@ -48,7 +46,7 @@ func (h *DefaultServer) Result() ([]common.ReturnResultLine, error) { result := make([]common.ReturnResultLine, len(h.data)) for index, req := range h.data { result[index] = common.ReturnResultLine{ - Data: fmt.Sprintf("default-server %s", params.ServerOptionsString(req.Params)), + Data: "default-server " + params.ServerOptionsString(req.Params), Comment: req.Comment, } } diff --git a/config-parser/parsers/errorfiles.go b/config-parser/parsers/errorfiles.go index 99d12ee6..109f1c3b 100644 --- a/config-parser/parsers/errorfiles.go +++ b/config-parser/parsers/errorfiles.go @@ -66,9 +66,8 @@ func (e *ErrorFiles) Result() ([]common.ReturnResultLine, error) { } result := make([]common.ReturnResultLine, len(e.data)) for index, data := range e.data { - result[index] = common.ReturnResultLine{ - Data: fmt.Sprintf("errorfiles %s", data.Name), + Data: "errorfiles " + data.Name, Comment: data.Comment, } if len(data.Codes) > 0 { diff --git a/config-parser/parsers/external-check-command.go b/config-parser/parsers/external-check-command.go index 28569fb0..a2c64865 100644 --- a/config-parser/parsers/external-check-command.go +++ b/config-parser/parsers/external-check-command.go @@ -17,8 +17,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -49,7 +47,7 @@ func (s *ExternalCheckCommand) Result() ([]common.ReturnResultLine, error) { } var data string if s.data.Command != "" { - data = fmt.Sprintf("external-check command %s", s.data.Command) + data = "external-check command " + s.data.Command } return []common.ReturnResultLine{ { diff --git a/config-parser/parsers/external-check-path.go b/config-parser/parsers/external-check-path.go index 2fe38339..24e9e07d 100644 --- a/config-parser/parsers/external-check-path.go +++ b/config-parser/parsers/external-check-path.go @@ -17,8 +17,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -49,7 +47,7 @@ func (s *ExternalCheckPath) Result() ([]common.ReturnResultLine, error) { } var data string if s.data.Path != "" { - data = fmt.Sprintf("external-check path %s", s.data.Path) + data = "external-check path " + s.data.Path } return []common.ReturnResultLine{ { diff --git a/config-parser/parsers/extra/config-hash.go b/config-parser/parsers/extra/config-hash.go index 1c183397..72acd72c 100644 --- a/config-parser/parsers/extra/config-hash.go +++ b/config-parser/parsers/extra/config-hash.go @@ -16,7 +16,7 @@ limitations under the License. package extra import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -45,7 +45,7 @@ func (h *ConfigHash) Get(createIfNotExist bool) (common.ParserData, error) { } return h.data, nil } - return nil, fmt.Errorf("no data") + return nil, stderrors.New("no data") } // Parse see if we have version, since it is not haproxy keyword, it's in comments diff --git a/config-parser/parsers/extra/config-version.go b/config-parser/parsers/extra/config-version.go index f52675f3..10b8caa2 100644 --- a/config-parser/parsers/extra/config-version.go +++ b/config-parser/parsers/extra/config-version.go @@ -17,6 +17,7 @@ limitations under the License. package extra import ( + stderrors "errors" "fmt" "strconv" "strings" @@ -46,7 +47,7 @@ func (p *ConfigVersion) Get(createIfNotExist bool) (common.ParserData, error) { } return p.data, nil } - return nil, fmt.Errorf("no data") + return nil, stderrors.New("no data") } // Parse see if we have version, since it is not haproxy keyword, it's in comments @@ -56,6 +57,11 @@ func (p *ConfigVersion) Parse(line string, parts []string, comment string) (stri if len(data) < 2 { return "", &errors.ParseError{Parser: "ConfigVersion", Line: line} } + + if p.data != nil { + return "", &errors.ParseError{Parser: "ConfigVersion", Line: line} + } + if version, err := strconv.ParseInt(data[1], 10, 64); err == nil { p.data = &types.ConfigVersion{ Value: version, diff --git a/config-parser/parsers/extra/section.go b/config-parser/parsers/extra/section.go index f869a7b5..d5d47900 100644 --- a/config-parser/parsers/extra/section.go +++ b/config-parser/parsers/extra/section.go @@ -17,7 +17,7 @@ limitations under the License. package extra import ( - "fmt" + stderrors "errors" "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" @@ -49,5 +49,5 @@ func (s *Section) Parse(line string, parts []string, comment string) (string, er } func (s *Section) Result() ([]common.ReturnResultLine, error) { - return nil, fmt.Errorf("not valid") + return nil, stderrors.New("not valid") } diff --git a/config-parser/parsers/filters/filter-cache.go b/config-parser/parsers/filters/filter-cache.go index c5f5997d..095eaf5a 100644 --- a/config-parser/parsers/filters/filter-cache.go +++ b/config-parser/parsers/filters/filter-cache.go @@ -17,7 +17,7 @@ limitations under the License. package filters import ( - "fmt" + "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -35,7 +35,7 @@ func (f *Cache) Parse(parts []string, comment string) error { if len(parts) > 2 { f.Name = parts[2] } else { - return fmt.Errorf("no cache name") + return errors.New("no cache name") } return nil } diff --git a/config-parser/parsers/filters/filter-fcgi-app.go b/config-parser/parsers/filters/filter-fcgi-app.go index 8ac21906..d2b4e055 100644 --- a/config-parser/parsers/filters/filter-fcgi-app.go +++ b/config-parser/parsers/filters/filter-fcgi-app.go @@ -17,6 +17,7 @@ limitations under the License. package filters import ( + "errors" "fmt" "strings" @@ -35,7 +36,7 @@ func (f *FcgiApp) Parse(parts []string, comment string) error { case 3: f.Name = parts[2] case 2: - return fmt.Errorf("no FastCGI application name") + return errors.New("no FastCGI application name") default: return fmt.Errorf("unsupported extra options: %s", strings.Join(parts[2:], " ")) } diff --git a/config-parser/parsers/filters/filter-opentracing.go b/config-parser/parsers/filters/filter-opentracing.go index db97447e..b00db4b3 100644 --- a/config-parser/parsers/filters/filter-opentracing.go +++ b/config-parser/parsers/filters/filter-opentracing.go @@ -17,6 +17,7 @@ limitations under the License. package filters import ( + "errors" "fmt" "strings" @@ -33,7 +34,7 @@ func (o *Opentracing) Parse(parts []string, comment string) error { o.Comment = comment if len(parts) < 3 || len(parts)%2 == 1 { - return fmt.Errorf("missing required options") + return errors.New("missing required options") } for index, part := range parts { diff --git a/config-parser/parsers/filters/filters-bwlim.go b/config-parser/parsers/filters/filters-bwlim.go index 2df5cac9..1d72b520 100644 --- a/config-parser/parsers/filters/filters-bwlim.go +++ b/config-parser/parsers/filters/filters-bwlim.go @@ -17,6 +17,7 @@ limitations under the License. package filters import ( + "errors" "fmt" "strings" @@ -40,9 +41,9 @@ func (b *BandwidthLimit) Parse(parts []string, comment string) error { switch { case len(parts) < 7 || len(parts[1:])%2 == 1: - return fmt.Errorf("missing required options") + return errors.New("missing required options") case len(parts) > 11: - return fmt.Errorf("unsupported extra options") + return errors.New("unsupported extra options") } for index, part := range parts { @@ -64,9 +65,9 @@ func (b *BandwidthLimit) Parse(parts []string, comment string) error { switch { case len(b.Limit) > 0 && len(b.Key) == 0: - return fmt.Errorf("missing required key options") + return errors.New("missing required key options") case len(b.Key) > 0 && len(b.Limit) == 0: - return fmt.Errorf("missing required key limit") + return errors.New("missing required key limit") } return nil diff --git a/config-parser/parsers/http-reuse.go b/config-parser/parsers/http-reuse.go index a33c2a4e..62096957 100644 --- a/config-parser/parsers/http-reuse.go +++ b/config-parser/parsers/http-reuse.go @@ -17,8 +17,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -48,7 +46,7 @@ func (p *HTTPReuse) Result() ([]common.ReturnResultLine, error) { } return []common.ReturnResultLine{ { - Data: fmt.Sprintf("http-reuse %s", p.data.ShareType), + Data: "http-reuse " + p.data.ShareType, Comment: p.data.Comment, }, }, nil diff --git a/config-parser/parsers/http/actions/add-acl.go b/config-parser/parsers/http/actions/add-acl.go index f2491d50..709eadbd 100644 --- a/config-parser/parsers/http/actions/add-acl.go +++ b/config-parser/parsers/http/actions/add-acl.go @@ -18,6 +18,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -51,7 +52,7 @@ func (f *AddACL) Parse(parts []string, parserType types.ParserType, comment stri } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *AddACL) String() string { diff --git a/config-parser/parsers/http/actions/add-header.go b/config-parser/parsers/http/actions/add-header.go index 9597ea7d..d79c002c 100644 --- a/config-parser/parsers/http/actions/add-header.go +++ b/config-parser/parsers/http/actions/add-header.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -46,7 +47,7 @@ func (f *AddHeader) Parse(parts []string, parserType types.ParserType, comment s } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *AddHeader) String() string { diff --git a/config-parser/parsers/http/actions/allow.go b/config-parser/parsers/http/actions/allow.go index a313883b..506324c0 100644 --- a/config-parser/parsers/http/actions/allow.go +++ b/config-parser/parsers/http/actions/allow.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -45,7 +46,7 @@ func (f *Allow) Parse(parts []string, parserType types.ParserType, comment strin } else if len(parts) == 2 { return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *Allow) String() string { @@ -53,7 +54,7 @@ func (f *Allow) String() string { if f.Cond != "" { condition = fmt.Sprintf(" %s %s", f.Cond, f.CondTest) } - return fmt.Sprintf("allow%s", condition) + return "allow" + condition } func (f *Allow) GetComment() string { diff --git a/config-parser/parsers/http/actions/auth.go b/config-parser/parsers/http/actions/auth.go index 7537b3dc..551849c3 100644 --- a/config-parser/parsers/http/actions/auth.go +++ b/config-parser/parsers/http/actions/auth.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -48,7 +48,7 @@ func (f *Auth) Parse(parts []string, parserType types.ParserType, comment string } else if len(parts) == 2 { return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *Auth) String() string { diff --git a/config-parser/parsers/http/actions/cache-store.go b/config-parser/parsers/http/actions/cache-store.go index 532dac8f..a1471fc7 100644 --- a/config-parser/parsers/http/actions/cache-store.go +++ b/config-parser/parsers/http/actions/cache-store.go @@ -18,7 +18,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -49,7 +49,7 @@ func (f *CacheStore) Parse(parts []string, parserType types.ParserType, comment } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *CacheStore) String() string { diff --git a/config-parser/parsers/http/actions/cache-use.go b/config-parser/parsers/http/actions/cache-use.go index 0a5ab260..c0755809 100644 --- a/config-parser/parsers/http/actions/cache-use.go +++ b/config-parser/parsers/http/actions/cache-use.go @@ -18,7 +18,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -49,7 +49,7 @@ func (f *CacheUse) Parse(parts []string, parserType types.ParserType, comment st } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *CacheUse) String() string { diff --git a/config-parser/parsers/http/actions/capture.go b/config-parser/parsers/http/actions/capture.go index 0d48c358..9399ea00 100644 --- a/config-parser/parsers/http/actions/capture.go +++ b/config-parser/parsers/http/actions/capture.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strconv" "strings" @@ -67,7 +67,7 @@ func (f *Capture) Parse(parts []string, parserType types.ParserType, comment str } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *Capture) String() string { diff --git a/config-parser/parsers/http/actions/check-comment.go b/config-parser/parsers/http/actions/check-comment.go index d954f533..888558bc 100644 --- a/config-parser/parsers/http/actions/check-comment.go +++ b/config-parser/parsers/http/actions/check-comment.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "github.com/haproxytech/client-native/v6/config-parser/types" ) @@ -34,7 +34,7 @@ func (c *CheckComment) Parse(parts []string, parserType types.ParserType, commen } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } c.LogMessage = parts[2] diff --git a/config-parser/parsers/http/actions/check-disable-on-404.go b/config-parser/parsers/http/actions/check-disable-on-404.go index 1795d5e8..8fe5af57 100644 --- a/config-parser/parsers/http/actions/check-disable-on-404.go +++ b/config-parser/parsers/http/actions/check-disable-on-404.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "github.com/haproxytech/client-native/v6/config-parser/types" ) @@ -33,7 +33,7 @@ func (c *CheckDisableOn404) Parse(parts []string, parserType types.ParserType, c } if len(parts) > 2 { - return fmt.Errorf("too many params") + return stderrors.New("too many params") } return nil diff --git a/config-parser/parsers/http/actions/check-send-state.go b/config-parser/parsers/http/actions/check-send-state.go index 1e23d548..ac9bb3b6 100644 --- a/config-parser/parsers/http/actions/check-send-state.go +++ b/config-parser/parsers/http/actions/check-send-state.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "github.com/haproxytech/client-native/v6/config-parser/types" ) @@ -33,7 +33,7 @@ func (c *CheckSendState) Parse(parts []string, parserType types.ParserType, comm } if len(parts) > 2 { - return fmt.Errorf("too many params") + return stderrors.New("too many params") } return nil diff --git a/config-parser/parsers/http/actions/check-send.go b/config-parser/parsers/http/actions/check-send.go index 65702ebd..e7c714ae 100644 --- a/config-parser/parsers/http/actions/check-send.go +++ b/config-parser/parsers/http/actions/check-send.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/parsers/actions" @@ -51,7 +51,7 @@ func (c *CheckSend) Parse(parts []string, parserType types.ParserType, comment s } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } for i := 2; i < len(parts); i++ { diff --git a/config-parser/parsers/http/actions/del-acl.go b/config-parser/parsers/http/actions/del-acl.go index c0c232d7..43e4a825 100644 --- a/config-parser/parsers/http/actions/del-acl.go +++ b/config-parser/parsers/http/actions/del-acl.go @@ -18,6 +18,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -51,7 +52,7 @@ func (f *DelACL) Parse(parts []string, parserType types.ParserType, comment stri } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *DelACL) String() string { diff --git a/config-parser/parsers/http/actions/del-header.go b/config-parser/parsers/http/actions/del-header.go index 42251991..f91d8f6c 100644 --- a/config-parser/parsers/http/actions/del-header.go +++ b/config-parser/parsers/http/actions/del-header.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -44,7 +45,7 @@ func (f *DelHeader) Parse(parts []string, parserType types.ParserType, comment s if len(command) > 1 && command[0] == "-m" { f.Method = command[1] } else if len(command) > 0 { - return fmt.Errorf("unknown params after name") + return stderrors.New("unknown params after name") } if len(condition) > 1 { f.Cond = condition[0] @@ -52,7 +53,7 @@ func (f *DelHeader) Parse(parts []string, parserType types.ParserType, comment s } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *DelHeader) String() string { @@ -61,10 +62,10 @@ func (f *DelHeader) String() string { sb.WriteString("del-header ") sb.WriteString(f.Name) if f.Method != "" { - sb.WriteString(fmt.Sprintf(" -m %s", f.Method)) + sb.WriteString(" -m " + f.Method) } if f.Cond != "" { - sb.WriteString(fmt.Sprintf(" %s %s", f.Cond, f.CondTest)) + fmt.Fprintf(sb, " %s %s", f.Cond, f.CondTest) } return sb.String() } diff --git a/config-parser/parsers/http/actions/del-map.go b/config-parser/parsers/http/actions/del-map.go index 0952bdc0..9334d920 100644 --- a/config-parser/parsers/http/actions/del-map.go +++ b/config-parser/parsers/http/actions/del-map.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -41,7 +42,7 @@ func (f *DelMap) Parse(parts []string, parserType types.ParserType, comment stri if len(parts) >= 3 { command, condition := common.SplitRequest(parts[2:]) if len(command) == 0 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.KeyFmt = command[0] if len(condition) > 1 { @@ -50,7 +51,7 @@ func (f *DelMap) Parse(parts []string, parserType types.ParserType, comment stri } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *DelMap) String() string { diff --git a/config-parser/parsers/http/actions/deny.go b/config-parser/parsers/http/actions/deny.go index a12bdd43..9e720339 100644 --- a/config-parser/parsers/http/actions/deny.go +++ b/config-parser/parsers/http/actions/deny.go @@ -18,7 +18,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strconv" "strings" @@ -51,7 +51,7 @@ func (f *Deny) Parse(parts []string, parserType types.ParserType, comment string i++ code, err := strconv.ParseInt(command[i], 10, 64) if err != nil { - return fmt.Errorf("failed to parse status code") + return stderrors.New("failed to parse status code") } f.Status = &code case "content-type": @@ -66,7 +66,7 @@ func (f *Deny) Parse(parts []string, parserType types.ParserType, comment string case "hdr": hdr := Hdr{} if len(command) < i+3 { - return fmt.Errorf("failed to parse return hdr") + return stderrors.New("failed to parse return hdr") } i++ hdr.Name = command[i] @@ -74,7 +74,7 @@ func (f *Deny) Parse(parts []string, parserType types.ParserType, comment string hdr.Fmt = command[i] f.Hdrs = append(f.Hdrs, &hdr) default: - return fmt.Errorf("failed to parse hdr") + return stderrors.New("failed to parse hdr") } } } @@ -86,7 +86,7 @@ func (f *Deny) Parse(parts []string, parserType types.ParserType, comment string } else if len(parts) == 2 { return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *Deny) String() string { diff --git a/config-parser/parsers/http/actions/disable-l7-retry.go b/config-parser/parsers/http/actions/disable-l7-retry.go index 7e12528c..3ab4e46a 100644 --- a/config-parser/parsers/http/actions/disable-l7-retry.go +++ b/config-parser/parsers/http/actions/disable-l7-retry.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -43,7 +43,7 @@ func (f *DisableL7Retry) Parse(parts []string, parserType types.ParserType, comm } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *DisableL7Retry) String() string { diff --git a/config-parser/parsers/http/actions/early-hint.go b/config-parser/parsers/http/actions/early-hint.go index c8b54594..66e57f4b 100644 --- a/config-parser/parsers/http/actions/early-hint.go +++ b/config-parser/parsers/http/actions/early-hint.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -50,7 +50,7 @@ func (f *EarlyHint) Parse(parts []string, parserType types.ParserType, comment s } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *EarlyHint) String() string { diff --git a/config-parser/parsers/http/actions/normalize.go b/config-parser/parsers/http/actions/normalize.go index bf94257e..bb32393c 100644 --- a/config-parser/parsers/http/actions/normalize.go +++ b/config-parser/parsers/http/actions/normalize.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -67,7 +68,7 @@ func (f *NormalizeURI) Parse(parts []string, parserType types.ParserType, commen } } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *NormalizeURI) String() string { diff --git a/config-parser/parsers/http/actions/redirect.go b/config-parser/parsers/http/actions/redirect.go index eeba367a..431d860d 100644 --- a/config-parser/parsers/http/actions/redirect.go +++ b/config-parser/parsers/http/actions/redirect.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -66,7 +67,7 @@ func (f *Redirect) Parse(parts []string, parserType types.ParserType, comment st } } if index != len(command) { - return fmt.Errorf("extra params not processed") + return stderrors.New("extra params not processed") } if len(condition) > 1 { @@ -76,7 +77,7 @@ func (f *Redirect) Parse(parts []string, parserType types.ParserType, comment st return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *Redirect) String() string { diff --git a/config-parser/parsers/http/actions/return.go b/config-parser/parsers/http/actions/return.go index 586c498f..cf958dab 100644 --- a/config-parser/parsers/http/actions/return.go +++ b/config-parser/parsers/http/actions/return.go @@ -18,7 +18,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strconv" "strings" @@ -94,7 +94,7 @@ func (f *Return) Parse(parts []string, parserType types.ParserType, comment stri i++ code, err := strconv.ParseInt(command[i], 10, 64) if err != nil { - return fmt.Errorf("failed to parse status code") + return stderrors.New("failed to parse status code") } f.Status = &code case "content-type": @@ -109,7 +109,7 @@ func (f *Return) Parse(parts []string, parserType types.ParserType, comment stri case "hdr": hdr := Hdr{} if len(command) < i+3 { - return fmt.Errorf("failed to parse return hdr") + return stderrors.New("failed to parse return hdr") } i++ hdr.Name = command[i] @@ -117,7 +117,7 @@ func (f *Return) Parse(parts []string, parserType types.ParserType, comment stri hdr.Fmt = command[i] f.Hdrs = append(f.Hdrs, &hdr) default: - return fmt.Errorf("failed to parse hdr") + return stderrors.New("failed to parse hdr") } } } @@ -129,7 +129,7 @@ func (f *Return) Parse(parts []string, parserType types.ParserType, comment stri } else if len(parts) == 2 { return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *Return) String() string { diff --git a/config-parser/parsers/http/actions/set-header.go b/config-parser/parsers/http/actions/set-header.go index 62217244..172ebd92 100644 --- a/config-parser/parsers/http/actions/set-header.go +++ b/config-parser/parsers/http/actions/set-header.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -46,7 +47,7 @@ func (f *SetHeader) Parse(parts []string, parserType types.ParserType, comment s } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *SetHeader) String() string { diff --git a/config-parser/parsers/http/actions/set-map.go b/config-parser/parsers/http/actions/set-map.go index 2f859109..0f582384 100644 --- a/config-parser/parsers/http/actions/set-map.go +++ b/config-parser/parsers/http/actions/set-map.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -42,7 +43,7 @@ func (f *SetMap) Parse(parts []string, parserType types.ParserType, comment stri if len(parts) >= 4 { command, condition := common.SplitRequest(parts[2:]) if len(command) < 2 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.KeyFmt = command[0] f.ValueFmt = command[1] @@ -52,7 +53,7 @@ func (f *SetMap) Parse(parts []string, parserType types.ParserType, comment stri } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *SetMap) String() string { diff --git a/config-parser/parsers/http/actions/set-method.go b/config-parser/parsers/http/actions/set-method.go index c67bf857..6a7cd168 100644 --- a/config-parser/parsers/http/actions/set-method.go +++ b/config-parser/parsers/http/actions/set-method.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -51,7 +51,7 @@ func (f *SetMethod) Parse(parts []string, parserType types.ParserType, comment s return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *SetMethod) String() string { diff --git a/config-parser/parsers/http/actions/set-path.go b/config-parser/parsers/http/actions/set-path.go index 421613cb..20e07f81 100644 --- a/config-parser/parsers/http/actions/set-path.go +++ b/config-parser/parsers/http/actions/set-path.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -48,7 +49,7 @@ func (f *SetPath) Parse(parts []string, parserType types.ParserType, comment str return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *SetPath) String() string { diff --git a/config-parser/parsers/http/actions/set-pathq.go b/config-parser/parsers/http/actions/set-pathq.go index 8c111f46..f4bc5fcf 100644 --- a/config-parser/parsers/http/actions/set-pathq.go +++ b/config-parser/parsers/http/actions/set-pathq.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -48,7 +49,7 @@ func (f *SetPathQ) Parse(parts []string, parserType types.ParserType, comment st return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *SetPathQ) String() string { diff --git a/config-parser/parsers/http/actions/set-query.go b/config-parser/parsers/http/actions/set-query.go index 9ab95fd8..6e63b475 100644 --- a/config-parser/parsers/http/actions/set-query.go +++ b/config-parser/parsers/http/actions/set-query.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -47,7 +48,7 @@ func (f *SetQuery) Parse(parts []string, parserType types.ParserType, comment st return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *SetQuery) String() string { diff --git a/config-parser/parsers/http/actions/set-src.go b/config-parser/parsers/http/actions/set-src.go index b323083e..132200c1 100644 --- a/config-parser/parsers/http/actions/set-src.go +++ b/config-parser/parsers/http/actions/set-src.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -44,7 +44,7 @@ func (f *SetSrc) Parse(parts []string, parserType types.ParserType, comment stri expr := common.Expression{} err := expr.Parse(command) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr if len(condition) > 1 { @@ -53,7 +53,7 @@ func (f *SetSrc) Parse(parts []string, parserType types.ParserType, comment stri } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *SetSrc) String() string { diff --git a/config-parser/parsers/http/actions/set-status.go b/config-parser/parsers/http/actions/set-status.go index 772cc58e..33a86df2 100644 --- a/config-parser/parsers/http/actions/set-status.go +++ b/config-parser/parsers/http/actions/set-status.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strconv" "strings" @@ -61,7 +62,7 @@ func (f *SetStatus) Parse(parts []string, parserType types.ParserType, comment s } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *SetStatus) String() string { diff --git a/config-parser/parsers/http/actions/set-timeout.go b/config-parser/parsers/http/actions/set-timeout.go index 5afd3633..2ce03b77 100644 --- a/config-parser/parsers/http/actions/set-timeout.go +++ b/config-parser/parsers/http/actions/set-timeout.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -52,9 +53,8 @@ func (f *SetTimeout) Parse(parts []string, parserType types.ParserType, comment f.CondTest = strings.Join(condition[1:], " ") } return nil - } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *SetTimeout) String() string { diff --git a/config-parser/parsers/http/actions/set-uri.go b/config-parser/parsers/http/actions/set-uri.go index 0c83f769..df536562 100644 --- a/config-parser/parsers/http/actions/set-uri.go +++ b/config-parser/parsers/http/actions/set-uri.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -47,7 +48,7 @@ func (f *SetURI) Parse(parts []string, parserType types.ParserType, comment stri return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *SetURI) String() string { diff --git a/config-parser/parsers/http/actions/status.go b/config-parser/parsers/http/actions/status.go index b2d624ab..b107546f 100644 --- a/config-parser/parsers/http/actions/status.go +++ b/config-parser/parsers/http/actions/status.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strconv" "strings" @@ -67,7 +68,7 @@ func (f *Status) Parse(parts []string, parserType types.ParserType, comment stri // Parsing specific to http-error status directive. if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } if parts[0] != "http-error" { return fmt.Errorf("unexpected keyword %s", parts[0]) @@ -77,7 +78,7 @@ func (f *Status) Parse(parts []string, parserType types.ParserType, comment stri } code, err := strconv.ParseInt(parts[2], 10, 64) if err != nil { - return fmt.Errorf("failed to parse status code") + return stderrors.New("failed to parse status code") } if !AllowedErrorStatusCode(code) { return fmt.Errorf("unsupported status code %d", code) @@ -100,7 +101,7 @@ func (f *Status) Parse(parts []string, parserType types.ParserType, comment stri case "hdr": hdr := Hdr{} if len(command) < i+3 { - return fmt.Errorf("failed to parse return hdr") + return stderrors.New("failed to parse return hdr") } i++ hdr.Name = command[i] diff --git a/config-parser/parsers/http/actions/strict-mode.go b/config-parser/parsers/http/actions/strict-mode.go index 99dd65e5..b5f50787 100644 --- a/config-parser/parsers/http/actions/strict-mode.go +++ b/config-parser/parsers/http/actions/strict-mode.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -53,7 +54,7 @@ func (f *StrictMode) Parse(parts []string, parserType types.ParserType, comment } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *StrictMode) String() string { diff --git a/config-parser/parsers/http/actions/tarpit.go b/config-parser/parsers/http/actions/tarpit.go index d9506873..32567e04 100644 --- a/config-parser/parsers/http/actions/tarpit.go +++ b/config-parser/parsers/http/actions/tarpit.go @@ -18,10 +18,11 @@ limitations under the License. package actions import ( - "fmt" "strconv" "strings" + stderrors "errors" + "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/types" ) @@ -51,7 +52,7 @@ func (f *Tarpit) Parse(parts []string, parserType types.ParserType, comment stri i++ code, err := strconv.ParseInt(command[i], 10, 64) if err != nil { - return fmt.Errorf("failed to parse status code") + return stderrors.New("failed to parse status code") } f.Status = &code case "content-type": @@ -66,7 +67,7 @@ func (f *Tarpit) Parse(parts []string, parserType types.ParserType, comment stri case "hdr": hdr := Hdr{} if len(command) < i+3 { - return fmt.Errorf("failed to parse return hdr") + return stderrors.New("failed to parse return hdr") } i++ hdr.Name = command[i] @@ -74,7 +75,7 @@ func (f *Tarpit) Parse(parts []string, parserType types.ParserType, comment stri hdr.Fmt = command[i] f.Hdrs = append(f.Hdrs, &hdr) default: - return fmt.Errorf("failed to parse hdr") + return stderrors.New("failed to parse hdr") } } } @@ -86,7 +87,7 @@ func (f *Tarpit) Parse(parts []string, parserType types.ParserType, comment stri } else if len(parts) == 2 { return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *Tarpit) String() string { //nolint:dupl diff --git a/config-parser/parsers/http/actions/wait-for-body.go b/config-parser/parsers/http/actions/wait-for-body.go index 6335d48b..093bafa0 100644 --- a/config-parser/parsers/http/actions/wait-for-body.go +++ b/config-parser/parsers/http/actions/wait-for-body.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -43,7 +44,7 @@ func (f *WaitForBody) Parse(parts []string, parserType types.ParserType, comment } command, condition := common.SplitRequest(parts[3:]) if len(command) < 1 || len(command) == 2 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Time = command[0] if len(command) > 2 { @@ -59,7 +60,7 @@ func (f *WaitForBody) Parse(parts []string, parserType types.ParserType, comment } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *WaitForBody) String() string { diff --git a/config-parser/parsers/http/actions/wait-for-handshake.go b/config-parser/parsers/http/actions/wait-for-handshake.go index 5825e5ea..cc9acef3 100644 --- a/config-parser/parsers/http/actions/wait-for-handshake.go +++ b/config-parser/parsers/http/actions/wait-for-handshake.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -42,7 +42,7 @@ func (f *WaitForHandshake) Parse(parts []string, parserType types.ParserType, co } return nil } - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } func (f *WaitForHandshake) String() string { diff --git a/config-parser/parsers/httpclient.resolvers.prefer.go b/config-parser/parsers/httpclient.resolvers.prefer.go index 1b82183e..9f5c7cf2 100644 --- a/config-parser/parsers/httpclient.resolvers.prefer.go +++ b/config-parser/parsers/httpclient.resolvers.prefer.go @@ -1,8 +1,6 @@ package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -31,7 +29,7 @@ func (p *HTTPClientResolversPrefer) Result() ([]common.ReturnResultLine, error) if p.data == nil || len(p.data.Type) == 0 { return nil, errors.ErrFetch } - data := fmt.Sprintf("httpclient.resolvers.prefer %s", p.data.Type) + data := "httpclient.resolvers.prefer " + p.data.Type return []common.ReturnResultLine{ { Data: data, diff --git a/config-parser/parsers/httpclient.ssl.verify.go b/config-parser/parsers/httpclient.ssl.verify.go index 9243fbbc..6bde3619 100644 --- a/config-parser/parsers/httpclient.ssl.verify.go +++ b/config-parser/parsers/httpclient.ssl.verify.go @@ -1,8 +1,6 @@ package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -41,7 +39,7 @@ func (p *HTTPClientSSLVerify) Result() ([]common.ReturnResultLine, error) { } data := "httpclient.ssl.verify" if len(p.data.Type) > 0 { - data = fmt.Sprintf("httpclient.ssl.verify %s", p.data.Type) + data = "httpclient.ssl.verify " + p.data.Type } return []common.ReturnResultLine{ { diff --git a/config-parser/parsers/load-server-state-from-file.go b/config-parser/parsers/load-server-state-from-file.go index c8d4287b..325ac456 100644 --- a/config-parser/parsers/load-server-state-from-file.go +++ b/config-parser/parsers/load-server-state-from-file.go @@ -16,8 +16,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -53,7 +51,7 @@ func (p *LoadServerStateFromFile) Result() ([]common.ReturnResultLine, error) { } return []common.ReturnResultLine{ { - Data: fmt.Sprintf("load-server-state-from-file %s", p.data.Argument), + Data: "load-server-state-from-file " + p.data.Argument, }, }, nil } diff --git a/config-parser/parsers/log-sterr.go b/config-parser/parsers/log-sterr.go index 34fe96ce..bf7d4178 100644 --- a/config-parser/parsers/log-sterr.go +++ b/config-parser/parsers/log-sterr.go @@ -17,7 +17,7 @@ limitations under the License. package parsers import ( - "fmt" + stderrors "errors" "strconv" "strings" @@ -41,14 +41,14 @@ func (p *LogStdErr) parse(parts []string) (*types.LogStdErr, error) { getValue := func(part []string, index *int) (string, error) { var value string if *index+1 == len(parts) { - return "", fmt.Errorf("missing attribute value") + return "", stderrors.New("missing attribute value") } value = part[*index+1] _, ok := protectedKeywords[value] if ok { - return "", fmt.Errorf("missing value for attribute") + return "", stderrors.New("missing value for attribute") } defer func() { @@ -73,13 +73,13 @@ func (p *LogStdErr) parse(parts []string) (*types.LogStdErr, error) { sampleData := strings.Split(v, ":") if len(sampleData) != 2 || sampleData[0] == "" { - return nil, fmt.Errorf("sample size is malformed") + return nil, stderrors.New("sample size is malformed") } data.SampleRange = sampleData[0] if data.SampleSize, err = strconv.ParseInt(sampleData[1], 10, 64); err != nil { - return nil, fmt.Errorf("expected integer value") + return nil, stderrors.New("expected integer value") } case part == "format": v, err := getValue(parts, &index) @@ -95,7 +95,7 @@ func (p *LogStdErr) parse(parts []string) (*types.LogStdErr, error) { } if data.Length, err = strconv.ParseInt(v, 10, 64); err != nil { - return nil, fmt.Errorf("expected integer value") + return nil, stderrors.New("expected integer value") } case index == len(parts)-3: // data.Facility = part diff --git a/config-parser/parsers/log_send_hostname.go b/config-parser/parsers/log_send_hostname.go index 61e7c165..dc34be3b 100644 --- a/config-parser/parsers/log_send_hostname.go +++ b/config-parser/parsers/log_send_hostname.go @@ -17,8 +17,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -48,7 +46,7 @@ func (p *LogSendHostName) Result() ([]common.ReturnResultLine, error) { } data := "log-send-hostname" if p.data.Value != "" { - data = fmt.Sprintf("log-send-hostname %s", p.data.Value) + data = "log-send-hostname " + p.data.Value } return []common.ReturnResultLine{ { diff --git a/config-parser/parsers/lua-load.go b/config-parser/parsers/lua-load.go index e418621d..32b23de8 100644 --- a/config-parser/parsers/lua-load.go +++ b/config-parser/parsers/lua-load.go @@ -17,8 +17,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -47,7 +45,7 @@ func (l *LuaLoad) Result() ([]common.ReturnResultLine, error) { result := make([]common.ReturnResultLine, len(l.data)) for index, data := range l.data { result[index] = common.ReturnResultLine{ - Data: fmt.Sprintf("lua-load %s", data.File), + Data: "lua-load " + data.File, Comment: data.Comment, } } diff --git a/config-parser/parsers/lua-prepend-path.go b/config-parser/parsers/lua-prepend-path.go index 4b26a3a1..9d064ad0 100644 --- a/config-parser/parsers/lua-prepend-path.go +++ b/config-parser/parsers/lua-prepend-path.go @@ -51,7 +51,7 @@ func (l *LuaPrependPath) Result() ([]common.ReturnResultLine, error) { for index, data := range l.data { typ := "" if data.Type != "" { - typ = fmt.Sprintf(" %s", data.Type) + typ = " " + data.Type } result[index] = common.ReturnResultLine{ Data: fmt.Sprintf("lua-prepend-path %s%s", data.Path, typ), diff --git a/config-parser/parsers/mode.go b/config-parser/parsers/mode.go index f48bd4ed..13e607fd 100644 --- a/config-parser/parsers/mode.go +++ b/config-parser/parsers/mode.go @@ -17,8 +17,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -52,7 +50,7 @@ func (p *Mode) Result() ([]common.ReturnResultLine, error) { } return []common.ReturnResultLine{ { - Data: fmt.Sprintf("mode %s", p.data.Value), + Data: "mode " + p.data.Value, Comment: p.data.Comment, }, }, nil diff --git a/config-parser/parsers/monitor-uri.go b/config-parser/parsers/monitor-uri.go index 2c071276..7687c8a8 100644 --- a/config-parser/parsers/monitor-uri.go +++ b/config-parser/parsers/monitor-uri.go @@ -16,7 +16,6 @@ limitations under the License. package parsers import ( - "fmt" "net/url" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -46,7 +45,7 @@ func (p *MonitorURI) Result() ([]common.ReturnResultLine, error) { } return []common.ReturnResultLine{ { - Data: fmt.Sprintf("monitor-uri %s", p.data.URI), + Data: "monitor-uri " + p.data.URI, }, }, nil } diff --git a/config-parser/parsers/option-http-restrict-req-hdr-names.go b/config-parser/parsers/option-http-restrict-req-hdr-names.go index 37e189b8..be15ebc2 100644 --- a/config-parser/parsers/option-http-restrict-req-hdr-names.go +++ b/config-parser/parsers/option-http-restrict-req-hdr-names.go @@ -17,8 +17,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -49,7 +47,7 @@ func (o *OptionHTTPRestrictReqHdrNames) Result() ([]common.ReturnResultLine, err } return []common.ReturnResultLine{ { - Data: fmt.Sprintf("option http-restrict-req-hdr-names %s", o.data.Policy), + Data: "option http-restrict-req-hdr-names " + o.data.Policy, Comment: o.data.Comment, }, }, nil diff --git a/config-parser/parsers/quic-socket-owner.go b/config-parser/parsers/quic-socket-owner.go index 0af76d71..aec44bde 100644 --- a/config-parser/parsers/quic-socket-owner.go +++ b/config-parser/parsers/quic-socket-owner.go @@ -17,8 +17,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -47,7 +45,7 @@ func (p *QuicSocketOwner) Result() ([]common.ReturnResultLine, error) { if p.data == nil || len(p.data.Owner) == 0 { return nil, errors.ErrFetch } - data := fmt.Sprintf("tune.quic.socket-owner %s", p.data.Owner) + data := "tune.quic.socket-owner " + p.data.Owner return []common.ReturnResultLine{ { Data: data, diff --git a/config-parser/parsers/set-var.go b/config-parser/parsers/set-var.go index 22c1cb5d..4b5c43f0 100644 --- a/config-parser/parsers/set-var.go +++ b/config-parser/parsers/set-var.go @@ -17,7 +17,7 @@ limitations under the License. package parsers import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -36,7 +36,7 @@ func (p *SetVar) parse(line string, parts []string, comment string) (*types.SetV } expr := common.Expression{} if expr.Parse(parts[2:]) != nil { - return nil, fmt.Errorf("not enough params") + return nil, stderrors.New("not enough params") } data := &types.SetVar{ Name: parts[1], diff --git a/config-parser/parsers/simple/simple-option.go b/config-parser/parsers/simple/simple-option.go index bd99334e..e1e74370 100644 --- a/config-parser/parsers/simple/simple-option.go +++ b/config-parser/parsers/simple/simple-option.go @@ -35,7 +35,7 @@ type Option struct { func (o *Option) Init() { if !strings.HasPrefix(o.Name, "option") { o.name = o.Name - o.Name = fmt.Sprintf("option %s", o.Name) + o.Name = "option " + o.Name } o.data = nil o.preComments = nil @@ -55,7 +55,7 @@ func (o *Option) Parse(line string, parts []string, comment string) (string, err } return "", nil } - return "", &errors.ParseError{Parser: fmt.Sprintf("option %s", o.name), Line: line} + return "", &errors.ParseError{Parser: "option " + o.name, Line: line} } func (o *Option) Result() ([]common.ReturnResultLine, error) { diff --git a/config-parser/parsers/simple/simple-timeout.go b/config-parser/parsers/simple/simple-timeout.go index 279d44d8..157102bb 100644 --- a/config-parser/parsers/simple/simple-timeout.go +++ b/config-parser/parsers/simple/simple-timeout.go @@ -35,7 +35,7 @@ type Timeout struct { func (t *Timeout) Init() { if !strings.HasPrefix(t.Name, "timeout") { t.name = t.Name - t.Name = fmt.Sprintf("timeout %s", t.Name) + t.Name = "timeout " + t.Name } t.data = nil t.preComments = []string{} @@ -49,7 +49,7 @@ func (t *Timeout) Parse(line string, parts []string, comment string) (string, er } return "", nil } - return "", &errors.ParseError{Parser: fmt.Sprintf("timeout %s", t.name), Line: line} + return "", &errors.ParseError{Parser: "timeout " + t.name, Line: line} } func (t *Timeout) Result() ([]common.ReturnResultLine, error) { diff --git a/config-parser/parsers/ssl-engine.go b/config-parser/parsers/ssl-engine.go index e8e09d80..84e573a7 100644 --- a/config-parser/parsers/ssl-engine.go +++ b/config-parser/parsers/ssl-engine.go @@ -53,7 +53,6 @@ func (s *SslEngine) Result() ([]common.ReturnResultLine, error) { result := make([]common.ReturnResultLine, len(s.data)) for index, data := range s.data { - var sb strings.Builder sb.WriteString("ssl-engine") sb.WriteString(" ") diff --git a/config-parser/parsers/stats-timeout.go b/config-parser/parsers/stats-timeout.go index a207cabc..b4a8516e 100644 --- a/config-parser/parsers/stats-timeout.go +++ b/config-parser/parsers/stats-timeout.go @@ -17,8 +17,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -49,7 +47,7 @@ func (s *StatsTimeout) Result() ([]common.ReturnResultLine, error) { } return []common.ReturnResultLine{ { - Data: fmt.Sprintf("stats timeout %s", s.data.Value), + Data: "stats timeout " + s.data.Value, Comment: s.data.Comment, }, }, nil diff --git a/config-parser/parsers/stats/settings/admin.go b/config-parser/parsers/stats/settings/admin.go index ec679a44..89f150b7 100644 --- a/config-parser/parsers/stats/settings/admin.go +++ b/config-parser/parsers/stats/settings/admin.go @@ -17,6 +17,7 @@ limitations under the License. package stats import ( + "errors" "fmt" "strings" @@ -31,7 +32,7 @@ type Admin struct { func (a *Admin) Parse(parts []string, comment string) error { if len(parts) < 4 { - return fmt.Errorf("not enough params") + return errors.New("not enough params") } if comment != "" { diff --git a/config-parser/parsers/stats/settings/auth.go b/config-parser/parsers/stats/settings/auth.go index 28edb9b8..b9b373e1 100644 --- a/config-parser/parsers/stats/settings/auth.go +++ b/config-parser/parsers/stats/settings/auth.go @@ -17,6 +17,7 @@ limitations under the License. package stats import ( + "errors" "fmt" "strings" @@ -31,7 +32,7 @@ type Auth struct { func (a *Auth) Parse(parts []string, comment string) error { if len(parts) < 3 { - return fmt.Errorf("not enough params") + return errors.New("not enough params") } if comment != "" { @@ -39,7 +40,7 @@ func (a *Auth) Parse(parts []string, comment string) error { } split := common.StringSplitIgnoreEmpty(strings.Join(parts[2:], " "), ':') if len(split) < 2 { - return fmt.Errorf("wrong format for user & password") + return errors.New("wrong format for user & password") } a.User = split[0] a.Password = split[1] diff --git a/config-parser/parsers/stats/settings/bind-process.go b/config-parser/parsers/stats/settings/bind-process.go index b9999b00..2bad37f6 100644 --- a/config-parser/parsers/stats/settings/bind-process.go +++ b/config-parser/parsers/stats/settings/bind-process.go @@ -17,7 +17,7 @@ limitations under the License. package stats import ( - "fmt" + "errors" parsers "github.com/haproxytech/client-native/v6/config-parser/parsers" ) @@ -28,13 +28,13 @@ type BindProcess struct { func (m *BindProcess) Parse(parts []string, comment string) error { if len(parts) < 3 { - return fmt.Errorf("not enough params") + return errors.New("not enough params") } m.BindProcess = &parsers.BindProcess{} _, err := m.BindProcess.Parse("", parts[1:], comment) if err != nil { - return fmt.Errorf("error parsing bind-process") + return errors.New("error parsing bind-process") } return nil } diff --git a/config-parser/parsers/stats/settings/http-request.go b/config-parser/parsers/stats/settings/http-request.go index b38c8d5e..a715de40 100644 --- a/config-parser/parsers/stats/settings/http-request.go +++ b/config-parser/parsers/stats/settings/http-request.go @@ -17,6 +17,7 @@ limitations under the License. package stats import ( + "errors" "fmt" "strings" @@ -32,7 +33,7 @@ type HTTPRequest struct { func (h *HTTPRequest) Parse(parts []string, comment string) error { if len(parts) < 3 { - return fmt.Errorf("not enough params") + return errors.New("not enough params") } if comment != "" { @@ -43,7 +44,7 @@ func (h *HTTPRequest) Parse(parts []string, comment string) error { case "allow", "deny": command, condition := common.SplitRequest(parts[2:]) if len(command) != 1 { - return fmt.Errorf("error parsing http-request") + return errors.New("error parsing http-request") } h.Type = command[0] if len(condition) > 1 { @@ -54,7 +55,7 @@ func (h *HTTPRequest) Parse(parts []string, comment string) error { case "auth": return h.parseAuth(parts) default: - return fmt.Errorf("error parsing http-request") + return errors.New("error parsing http-request") } } @@ -65,11 +66,11 @@ func (h *HTTPRequest) parseAuth(parts []string) error { h.Type = strings.Join(command, " ") case 3: if command[1] != "realm" { - return fmt.Errorf("error parsing http-request") + return errors.New("error parsing http-request") } h.Type = strings.Join(command, " ") default: - return fmt.Errorf("error parsing http-request") + return errors.New("error parsing http-request") } if len(condition) > 1 { h.Cond = condition[0] diff --git a/config-parser/parsers/stats/settings/maxconn.go b/config-parser/parsers/stats/settings/maxconn.go index f635db32..58c69e7f 100644 --- a/config-parser/parsers/stats/settings/maxconn.go +++ b/config-parser/parsers/stats/settings/maxconn.go @@ -17,7 +17,7 @@ limitations under the License. package stats import ( - "fmt" + "errors" parsers "github.com/haproxytech/client-native/v6/config-parser/parsers" ) @@ -28,13 +28,13 @@ type MaxConn struct { func (m *MaxConn) Parse(parts []string, comment string) error { if len(parts) < 3 { - return fmt.Errorf("not enough params") + return errors.New("not enough params") } m.Maxconn = &parsers.MaxConn{} _, err := m.Maxconn.Parse("", parts[1:], comment) if err != nil { - return fmt.Errorf("error parsing maxconn") + return errors.New("error parsing maxconn") } return nil } diff --git a/config-parser/parsers/stats/settings/one-word.go b/config-parser/parsers/stats/settings/one-word.go index deb47618..baefbeb1 100644 --- a/config-parser/parsers/stats/settings/one-word.go +++ b/config-parser/parsers/stats/settings/one-word.go @@ -16,9 +16,7 @@ limitations under the License. package stats -import ( - "fmt" -) +import "errors" type OneWord struct { Name string @@ -27,7 +25,7 @@ type OneWord struct { func (o *OneWord) Parse(parts []string, comment string) error { if len(parts) < 2 { - return fmt.Errorf("not enough params") + return errors.New("not enough params") } o.Name = parts[1] diff --git a/config-parser/parsers/stats/settings/realm.go b/config-parser/parsers/stats/settings/realm.go index 6e30fcdb..04e2d21b 100644 --- a/config-parser/parsers/stats/settings/realm.go +++ b/config-parser/parsers/stats/settings/realm.go @@ -17,6 +17,7 @@ limitations under the License. package stats import ( + "errors" "fmt" "strings" ) @@ -28,7 +29,7 @@ type Realm struct { func (r *Realm) Parse(parts []string, comment string) error { if len(parts) < 3 { - return fmt.Errorf("not enough params") + return errors.New("not enough params") } if comment != "" { diff --git a/config-parser/parsers/stats/settings/refresh.go b/config-parser/parsers/stats/settings/refresh.go index 70b35798..ec52c8a7 100644 --- a/config-parser/parsers/stats/settings/refresh.go +++ b/config-parser/parsers/stats/settings/refresh.go @@ -17,6 +17,7 @@ limitations under the License. package stats import ( + "errors" "fmt" ) @@ -27,7 +28,7 @@ type Refresh struct { func (r *Refresh) Parse(parts []string, comment string) error { if len(parts) < 3 { - return fmt.Errorf("not enough params") + return errors.New("not enough params") } if comment != "" { diff --git a/config-parser/parsers/stats/settings/scope.go b/config-parser/parsers/stats/settings/scope.go index 47101138..cec8683c 100644 --- a/config-parser/parsers/stats/settings/scope.go +++ b/config-parser/parsers/stats/settings/scope.go @@ -17,6 +17,7 @@ limitations under the License. package stats import ( + "errors" "fmt" ) @@ -27,7 +28,7 @@ type Scope struct { func (s *Scope) Parse(parts []string, comment string) error { if len(parts) < 3 { - return fmt.Errorf("not enough params") + return errors.New("not enough params") } if comment != "" { diff --git a/config-parser/parsers/stats/settings/show-desc.go b/config-parser/parsers/stats/settings/show-desc.go index cad03d2b..e6b7cb38 100644 --- a/config-parser/parsers/stats/settings/show-desc.go +++ b/config-parser/parsers/stats/settings/show-desc.go @@ -17,6 +17,7 @@ limitations under the License. package stats import ( + "errors" "fmt" "strings" ) @@ -28,7 +29,7 @@ type ShowDesc struct { func (s *ShowDesc) Parse(parts []string, comment string) error { if len(parts) < 3 { - return fmt.Errorf("not enough params") + return errors.New("not enough params") } if comment != "" { diff --git a/config-parser/parsers/stats/settings/show-node.go b/config-parser/parsers/stats/settings/show-node.go index 53a2e07b..6039761c 100644 --- a/config-parser/parsers/stats/settings/show-node.go +++ b/config-parser/parsers/stats/settings/show-node.go @@ -17,6 +17,7 @@ limitations under the License. package stats import ( + "errors" "fmt" ) @@ -27,7 +28,7 @@ type ShowNode struct { func (s *ShowNode) Parse(parts []string, comment string) error { if len(parts) < 2 { - return fmt.Errorf("not enough params") + return errors.New("not enough params") } if comment != "" { diff --git a/config-parser/parsers/stats/settings/uri.go b/config-parser/parsers/stats/settings/uri.go index 53a9d8b2..bb9a9b2b 100644 --- a/config-parser/parsers/stats/settings/uri.go +++ b/config-parser/parsers/stats/settings/uri.go @@ -17,6 +17,7 @@ limitations under the License. package stats import ( + "errors" "fmt" ) @@ -27,7 +28,7 @@ type URI struct { func (u *URI) Parse(parts []string, comment string) error { if len(parts) < 3 { - return fmt.Errorf("not enough params") + return errors.New("not enough params") } if comment != "" { diff --git a/config-parser/parsers/table.go b/config-parser/parsers/table.go index 72d0b9f3..4c07b8ab 100644 --- a/config-parser/parsers/table.go +++ b/config-parser/parsers/table.go @@ -104,7 +104,6 @@ func (t *Table) Result() ([]common.ReturnResultLine, error) { } result := make([]common.ReturnResultLine, dataLength) for index, table := range t.data { - var data strings.Builder data.WriteString("table ") data.WriteString(table.Name) diff --git a/config-parser/parsers/tcp/actions/attach-srv.go b/config-parser/parsers/tcp/actions/attach-srv.go index 7dd43e1e..43e677ab 100644 --- a/config-parser/parsers/tcp/actions/attach-srv.go +++ b/config-parser/parsers/tcp/actions/attach-srv.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -41,7 +42,7 @@ func (f *AttachSrv) Parse(parts []string, parserType types.ParserType, comment s n := len(parts) if n < 4 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Server = parts[3] @@ -55,7 +56,7 @@ func (f *AttachSrv) Parse(parts []string, parserType types.ParserType, comment s if parts[i] == "name" { if n < 6 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } expr := common.Expression{} err := expr.Parse([]string{parts[i+1]}) diff --git a/config-parser/parsers/tcp/actions/capture.go b/config-parser/parsers/tcp/actions/capture.go index 2272d099..8c7f1ec0 100644 --- a/config-parser/parsers/tcp/actions/capture.go +++ b/config-parser/parsers/tcp/actions/capture.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strconv" "strings" @@ -38,13 +38,13 @@ func (f *Capture) Parse(parts []string, parserType types.ParserType, comment str f.Comment = comment } if len(parts) < 4 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } expr := common.Expression{} err := expr.Parse([]string{parts[3]}) if err != nil { - return fmt.Errorf("invalid expression") + return stderrors.New("invalid expression") } f.Expr = expr @@ -52,7 +52,7 @@ func (f *Capture) Parse(parts []string, parserType types.ParserType, comment str if ln, err := strconv.ParseInt(parts[5], 10, 64); err == nil { f.Len = ln } else { - return fmt.Errorf("invalid value for len") + return stderrors.New("invalid value for len") } _, condition := common.SplitRequest(parts[5:]) if len(condition) > 1 { diff --git a/config-parser/parsers/tcp/actions/check-comment.go b/config-parser/parsers/tcp/actions/check-comment.go index 1a62d962..7481d4ed 100644 --- a/config-parser/parsers/tcp/actions/check-comment.go +++ b/config-parser/parsers/tcp/actions/check-comment.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "github.com/haproxytech/client-native/v6/config-parser/types" ) @@ -33,7 +33,7 @@ func (c *CheckComment) Parse(parts []string, parserType types.ParserType, commen c.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } c.LogMessage = parts[2] return nil diff --git a/config-parser/parsers/tcp/actions/check-send-binary-lf.go b/config-parser/parsers/tcp/actions/check-send-binary-lf.go index 54ba4c85..7835e08e 100644 --- a/config-parser/parsers/tcp/actions/check-send-binary-lf.go +++ b/config-parser/parsers/tcp/actions/check-send-binary-lf.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/parsers/actions" @@ -36,7 +36,7 @@ func (c *CheckSendBinaryLf) Parse(parts []string, parserType types.ParserType, c c.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } c.HexFmt = parts[2] for i := 3; i < len(parts); i++ { diff --git a/config-parser/parsers/tcp/actions/check-send-binary.go b/config-parser/parsers/tcp/actions/check-send-binary.go index 355b0066..83199873 100644 --- a/config-parser/parsers/tcp/actions/check-send-binary.go +++ b/config-parser/parsers/tcp/actions/check-send-binary.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/parsers/actions" @@ -36,7 +36,7 @@ func (c *CheckSendBinary) Parse(parts []string, parserType types.ParserType, com c.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } c.HexString = parts[2] for i := 3; i < len(parts); i++ { diff --git a/config-parser/parsers/tcp/actions/check-send-lf.go b/config-parser/parsers/tcp/actions/check-send-lf.go index 2698e88c..4cc99740 100644 --- a/config-parser/parsers/tcp/actions/check-send-lf.go +++ b/config-parser/parsers/tcp/actions/check-send-lf.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/parsers/actions" @@ -36,7 +36,7 @@ func (c *CheckSendLf) Parse(parts []string, parserType types.ParserType, comment c.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } c.Fmt = parts[2] for i := 3; i < len(parts); i++ { diff --git a/config-parser/parsers/tcp/actions/check-send.go b/config-parser/parsers/tcp/actions/check-send.go index 8e5d220f..738257d2 100644 --- a/config-parser/parsers/tcp/actions/check-send.go +++ b/config-parser/parsers/tcp/actions/check-send.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/parsers/actions" @@ -36,7 +36,7 @@ func (c *CheckSend) Parse(parts []string, parserType types.ParserType, comment s c.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } c.Data = parts[2] for i := 3; i < len(parts); i++ { diff --git a/config-parser/parsers/tcp/actions/set-src.go b/config-parser/parsers/tcp/actions/set-src.go index 3eed3ebc..38d5bacb 100644 --- a/config-parser/parsers/tcp/actions/set-src.go +++ b/config-parser/parsers/tcp/actions/set-src.go @@ -17,7 +17,7 @@ limitations under the License. package actions import ( - "fmt" + stderrors "errors" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -36,13 +36,13 @@ func (f *SetSrc) Parse(parts []string, parserType types.ParserType, comment stri f.Comment = comment } if len(parts) < 4 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } expr := common.Expression{} err := expr.Parse([]string{parts[3]}) if err != nil { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Expr = expr diff --git a/config-parser/parsers/tcp/actions/switch-mode.go b/config-parser/parsers/tcp/actions/switch-mode.go index db8b4ce3..6e868914 100644 --- a/config-parser/parsers/tcp/actions/switch-mode.go +++ b/config-parser/parsers/tcp/actions/switch-mode.go @@ -17,6 +17,7 @@ limitations under the License. package actions import ( + stderrors "errors" "fmt" "strings" @@ -44,7 +45,7 @@ func (f *SwitchMode) Parse(parts []string, parserType types.ParserType, comment } f.Proto = command[5] default: - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } if command[3] != "http" { return fmt.Errorf("invalid param %s", command[3]) diff --git a/config-parser/parsers/tcp/types/connection.go b/config-parser/parsers/tcp/types/connection.go index 6dc60fdb..a419a62f 100644 --- a/config-parser/parsers/tcp/types/connection.go +++ b/config-parser/parsers/tcp/types/connection.go @@ -17,6 +17,7 @@ limitations under the License. package types import ( + stderrors "errors" "fmt" "strings" @@ -45,7 +46,7 @@ func (f *Connection) Parse(parts []string, comment string) error { f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var err error switch parts[2] { diff --git a/config-parser/parsers/tcp/types/content.go b/config-parser/parsers/tcp/types/content.go index 49ec5052..880735a0 100644 --- a/config-parser/parsers/tcp/types/content.go +++ b/config-parser/parsers/tcp/types/content.go @@ -17,6 +17,7 @@ limitations under the License. package types import ( + stderrors "errors" "fmt" "strings" @@ -45,7 +46,7 @@ func (f *Content) Parse(parts []string, comment string) error { f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var err error switch parts[2] { diff --git a/config-parser/parsers/tcp/types/inspect-delay.go b/config-parser/parsers/tcp/types/inspect-delay.go index e6c6f9aa..133da3c0 100644 --- a/config-parser/parsers/tcp/types/inspect-delay.go +++ b/config-parser/parsers/tcp/types/inspect-delay.go @@ -17,7 +17,7 @@ limitations under the License. package types import ( - "fmt" + stderrors "errors" "strings" ) @@ -31,7 +31,7 @@ func (f *InspectDelay) Parse(parts []string, comment string) error { f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } f.Timeout = parts[2] return nil diff --git a/config-parser/parsers/tcp/types/session.go b/config-parser/parsers/tcp/types/session.go index f6761f9d..0169f33d 100644 --- a/config-parser/parsers/tcp/types/session.go +++ b/config-parser/parsers/tcp/types/session.go @@ -17,6 +17,7 @@ limitations under the License. package types import ( + stderrors "errors" "fmt" "strings" @@ -45,7 +46,7 @@ func (f *Session) Parse(parts []string, comment string) error { f.Comment = comment } if len(parts) < 3 { - return fmt.Errorf("not enough params") + return stderrors.New("not enough params") } var err error switch parts[2] { diff --git a/config-parser/parsers/unique-id-format.go b/config-parser/parsers/unique-id-format.go index 130634b4..14a11e0c 100644 --- a/config-parser/parsers/unique-id-format.go +++ b/config-parser/parsers/unique-id-format.go @@ -17,7 +17,6 @@ limitations under the License. package parsers import ( - "fmt" "strings" "github.com/haproxytech/client-native/v6/config-parser/common" @@ -50,7 +49,7 @@ func (p *UniqueIDFormat) Result() ([]common.ReturnResultLine, error) { } return []common.ReturnResultLine{ { - Data: fmt.Sprintf("unique-id-format %s", p.data.LogFormat), + Data: "unique-id-format " + p.data.LogFormat, Comment: p.data.Comment, }, }, nil diff --git a/config-parser/parsers/unique-id-header.go b/config-parser/parsers/unique-id-header.go index 707091cf..03fb8b59 100644 --- a/config-parser/parsers/unique-id-header.go +++ b/config-parser/parsers/unique-id-header.go @@ -17,8 +17,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -49,7 +47,7 @@ func (s *UniqueIDHeader) Result() ([]common.ReturnResultLine, error) { } return []common.ReturnResultLine{ { - Data: fmt.Sprintf("unique-id-header %s", s.data.Name), + Data: "unique-id-header " + s.data.Name, Comment: s.data.Comment, }, }, nil diff --git a/config-parser/parsers/use-fcgi-app.go b/config-parser/parsers/use-fcgi-app.go index 714fe356..a630f50c 100644 --- a/config-parser/parsers/use-fcgi-app.go +++ b/config-parser/parsers/use-fcgi-app.go @@ -17,8 +17,6 @@ limitations under the License. package parsers import ( - "fmt" - "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -49,7 +47,7 @@ func (s *UseFcgiApp) Result() ([]common.ReturnResultLine, error) { } return []common.ReturnResultLine{ { - Data: fmt.Sprintf("use-fcgi-app %s", s.data.Name), + Data: "use-fcgi-app " + s.data.Name, Comment: s.data.Comment, }, }, nil diff --git a/config-parser/parsers/user.go b/config-parser/parsers/user.go index 1b58c14d..29c86537 100644 --- a/config-parser/parsers/user.go +++ b/config-parser/parsers/user.go @@ -66,9 +66,9 @@ func (l *User) Result() ([]common.ReturnResultLine, error) { pwd := "" if user.Password != "" { if user.IsInsecure { - pwd = fmt.Sprintf(" insecure-password %s", user.Password) + pwd = " insecure-password " + user.Password } else { - pwd = fmt.Sprintf(" password %s", user.Password) + pwd = " password " + user.Password } } groups := "" diff --git a/config-parser/section-parsers.go b/config-parser/section-parsers.go index 509d503f..36b846d6 100644 --- a/config-parser/section-parsers.go +++ b/config-parser/section-parsers.go @@ -375,6 +375,7 @@ func (p *configParser) getGlobalParser() *Parsers { //nolint: maintidx addParser(parser, &sequence, &parsers.LogSendHostName{}) addParser(parser, &sequence, &parsers.LuaPrependPath{}) addParser(parser, &sequence, &parsers.LuaLoad{}) + addParser(parser, &sequence, &simple.Word{Name: "stats-file"}) addParser(parser, &sequence, &simple.Word{Name: "server-state-file"}) addParser(parser, &sequence, &simple.Word{Name: "server-state-base"}) addParser(parser, &sequence, &parsers.SslEngine{}) @@ -441,6 +442,8 @@ func (p *configParser) getGlobalParser() *Parsers { //nolint: maintidx addParser(parser, &sequence, &simple.Number{Name: "ocsp-update.mindelay"}) addParser(parser, &sequence, &simple.Number{Name: "ocsp-update.maxdelay"}) addParser(parser, &sequence, &simple.OnOff{Name: "ocsp-update.mode"}) + addParser(parser, &sequence, &simple.Enabled{Name: "h1-accept-payload-with-any-method"}) + addParser(parser, &sequence, &simple.Enabled{Name: "h1-do-not-close-on-insecure-transfer-encoding"}) // the ConfigSnippet must be at the end to parsers load order to ensure // the overloading of any option has been declared previously addParser(parser, &sequence, &parsers.ConfigSnippet{}) diff --git a/config-parser/sorter/sort.go b/config-parser/sorter/sort.go index 3f5711de..99bfa872 100644 --- a/config-parser/sorter/sort.go +++ b/config-parser/sorter/sort.go @@ -93,7 +93,7 @@ func sortByFrom(index int, sections []Section) { return } // we check if from is before, if it is, its ok - for i := 0; i < index; i++ { + for i := range index { if sections[i].Name == sections[index].From { sortByFrom(index+1, sections) return diff --git a/config-parser/spoe/parser-spoe.go b/config-parser/spoe/parser-spoe.go index d055ae22..8bba4d04 100644 --- a/config-parser/spoe/parser-spoe.go +++ b/config-parser/spoe/parser-spoe.go @@ -78,11 +78,7 @@ func (p *Parser) Get(scope string, sectionType parser.Section, sectionName strin if !ok { return nil, errors.ErrSectionMissing } - createNew := false - if len(createIfNotExist) > 0 && createIfNotExist[0] { - createNew = true - } - return section.Get(attribute, createNew) + return section.Get(attribute, len(createIfNotExist) > 0 && createIfNotExist[0]) } // GetOne get attribute from defaults section @@ -299,10 +295,7 @@ func (p *Parser) HasParser(scope string, sectionType parser.Section, attribute s } func (p *Parser) writeParsers(sectionName string, parsersData *parser.Parsers, result io.StringWriter, useIndentation bool) { - sectionNameWritten := false - if sectionName == "" { - sectionNameWritten = true - } + sectionNameWritten := sectionName == "" for _, parserName := range parsersData.ParserSequence { parser := parsersData.Parsers[string(parserName)] lines, _, err := parser.ResultAll() @@ -346,9 +339,11 @@ func (p *Parser) String() string { defer p.unLock() var result strings.Builder - scopes := []string{} + scopes := make([]string, len(p.Parsers)) + i := 0 for scope := range p.Parsers { - scopes = append(scopes, scope) + scopes[i] = scope + i++ } sort.Strings(scopes) firstScope := true diff --git a/config-parser/spoe/parsers/spoe-section.go b/config-parser/spoe/parsers/spoe-section.go index baa305b9..7706bc68 100644 --- a/config-parser/spoe/parsers/spoe-section.go +++ b/config-parser/spoe/parsers/spoe-section.go @@ -17,7 +17,7 @@ limitations under the License. package parsers import ( - "fmt" + stderrors "errors" "github.com/haproxytech/client-native/v6/config-parser/common" "github.com/haproxytech/client-native/v6/config-parser/errors" @@ -51,5 +51,5 @@ func (s *SPOESection) Parse(line string, parts []string, comment string) (string } func (s *SPOESection) Result() ([]common.ReturnResultLine, error) { - return nil, fmt.Errorf("not valid") + return nil, stderrors.New("not valid") } diff --git a/config-parser/spoe/tests/event_generated_test.go b/config-parser/spoe/tests/event_generated_test.go index f6c677af..dab2f4c9 100644 --- a/config-parser/spoe/tests/event_generated_test.go +++ b/config-parser/spoe/tests/event_generated_test.go @@ -52,12 +52,12 @@ func TestEvent(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -67,15 +67,15 @@ func TestEvent(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/spoe/tests/spoe-section_generated_test.go b/config-parser/spoe/tests/spoe-section_generated_test.go index 8170c514..86ea84a4 100644 --- a/config-parser/spoe/tests/spoe-section_generated_test.go +++ b/config-parser/spoe/tests/spoe-section_generated_test.go @@ -49,12 +49,12 @@ func TestSPOESection(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestSPOESection(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/acl_generated_test.go b/config-parser/tests/acl_generated_test.go index 41298a4f..bda7ddc4 100644 --- a/config-parser/tests/acl_generated_test.go +++ b/config-parser/tests/acl_generated_test.go @@ -66,12 +66,12 @@ func TestACL(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -81,15 +81,15 @@ func TestACL(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/array-string-kv_generated_test.go b/config-parser/tests/array-string-kv_generated_test.go index 0f6659e9..1f42aa2c 100644 --- a/config-parser/tests/array-string-kv_generated_test.go +++ b/config-parser/tests/array-string-kv_generated_test.go @@ -49,12 +49,12 @@ func TestArrayKeyValuesimple(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestArrayKeyValuesimple(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/balance_generated_test.go b/config-parser/tests/balance_generated_test.go index 7b7506be..a261869a 100644 --- a/config-parser/tests/balance_generated_test.go +++ b/config-parser/tests/balance_generated_test.go @@ -76,12 +76,12 @@ func TestBalance(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -91,15 +91,15 @@ func TestBalance(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/bind-process_generated_test.go b/config-parser/tests/bind-process_generated_test.go index 1abb8f79..137ebbba 100644 --- a/config-parser/tests/bind-process_generated_test.go +++ b/config-parser/tests/bind-process_generated_test.go @@ -58,12 +58,12 @@ func TestBindProcess(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -73,15 +73,15 @@ func TestBindProcess(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/bind_generated_test.go b/config-parser/tests/bind_generated_test.go index 3b578875..7c121d64 100644 --- a/config-parser/tests/bind_generated_test.go +++ b/config-parser/tests/bind_generated_test.go @@ -176,12 +176,12 @@ func TestBind(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -191,15 +191,15 @@ func TestBind(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/command_generated_test.go b/config-parser/tests/command_generated_test.go index 4b837378..f4d5f3a7 100644 --- a/config-parser/tests/command_generated_test.go +++ b/config-parser/tests/command_generated_test.go @@ -52,12 +52,12 @@ func TestCommand(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -67,15 +67,15 @@ func TestCommand(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/comments_generated_test.go b/config-parser/tests/comments_generated_test.go index bd6d7e0a..bd6e9d30 100644 --- a/config-parser/tests/comments_generated_test.go +++ b/config-parser/tests/comments_generated_test.go @@ -49,12 +49,12 @@ func TestCommentsextra(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestCommentsextra(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/compression-algo-req_generated_test.go b/config-parser/tests/compression-algo-req_generated_test.go index abb44dc5..60be9c77 100644 --- a/config-parser/tests/compression-algo-req_generated_test.go +++ b/config-parser/tests/compression-algo-req_generated_test.go @@ -51,12 +51,12 @@ func TestCompressionAlgoReq(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestCompressionAlgoReq(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/compression-algo-res_generated_test.go b/config-parser/tests/compression-algo-res_generated_test.go index f66508a5..afe61ce4 100644 --- a/config-parser/tests/compression-algo-res_generated_test.go +++ b/config-parser/tests/compression-algo-res_generated_test.go @@ -51,12 +51,12 @@ func TestCompressionAlgoRes(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestCompressionAlgoRes(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/compression-algo_generated_test.go b/config-parser/tests/compression-algo_generated_test.go index bb30e04a..e6250f73 100644 --- a/config-parser/tests/compression-algo_generated_test.go +++ b/config-parser/tests/compression-algo_generated_test.go @@ -52,12 +52,12 @@ func TestCompressionAlgo(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -67,15 +67,15 @@ func TestCompressionAlgo(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/compression-direction_generated_test.go b/config-parser/tests/compression-direction_generated_test.go index 83f61b68..01952c5f 100644 --- a/config-parser/tests/compression-direction_generated_test.go +++ b/config-parser/tests/compression-direction_generated_test.go @@ -51,12 +51,12 @@ func TestCompressionDirection(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestCompressionDirection(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/compression-offload_generated_test.go b/config-parser/tests/compression-offload_generated_test.go index 9ce38ed1..ad8ef6a7 100644 --- a/config-parser/tests/compression-offload_generated_test.go +++ b/config-parser/tests/compression-offload_generated_test.go @@ -51,12 +51,12 @@ func TestCompressionOffload(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestCompressionOffload(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/compression-type-req_generated_test.go b/config-parser/tests/compression-type-req_generated_test.go index 3ccc21f5..5ed92495 100644 --- a/config-parser/tests/compression-type-req_generated_test.go +++ b/config-parser/tests/compression-type-req_generated_test.go @@ -52,12 +52,12 @@ func TestCompressionTypeReq(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -67,15 +67,15 @@ func TestCompressionTypeReq(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/compression-type-res_generated_test.go b/config-parser/tests/compression-type-res_generated_test.go index 8517e693..4f2a99c2 100644 --- a/config-parser/tests/compression-type-res_generated_test.go +++ b/config-parser/tests/compression-type-res_generated_test.go @@ -52,12 +52,12 @@ func TestCompressionTypeRes(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -67,15 +67,15 @@ func TestCompressionTypeRes(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/compression-type_generated_test.go b/config-parser/tests/compression-type_generated_test.go index b2574b6e..95a69181 100644 --- a/config-parser/tests/compression-type_generated_test.go +++ b/config-parser/tests/compression-type_generated_test.go @@ -52,12 +52,12 @@ func TestCompressionType(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -67,15 +67,15 @@ func TestCompressionType(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/config-hash_generated_test.go b/config-parser/tests/config-hash_generated_test.go index ca6d7ac2..f5c488c0 100644 --- a/config-parser/tests/config-hash_generated_test.go +++ b/config-parser/tests/config-hash_generated_test.go @@ -49,12 +49,12 @@ func TestConfigHashextra(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestConfigHashextra(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/config-snippet_generated_test.go b/config-parser/tests/config-snippet_generated_test.go index 52cf69d8..ce3db16c 100644 --- a/config-parser/tests/config-snippet_generated_test.go +++ b/config-parser/tests/config-snippet_generated_test.go @@ -51,12 +51,12 @@ func TestConfigSnippet(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestConfigSnippet(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/config-version_generated_test.go b/config-parser/tests/config-version_generated_test.go index c4720ba6..78d095bb 100644 --- a/config-parser/tests/config-version_generated_test.go +++ b/config-parser/tests/config-version_generated_test.go @@ -49,12 +49,12 @@ func TestConfigVersionextra(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestConfigVersionextra(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/configs/haproxy_generated.cfg.go b/config-parser/tests/configs/haproxy_generated.cfg.go index 0a821b5b..25975f84 100644 --- a/config-parser/tests/configs/haproxy_generated.cfg.go +++ b/config-parser/tests/configs/haproxy_generated.cfg.go @@ -413,8 +413,8 @@ backend test stick match src table pop if !localhost stick store-request src table pop if !localhost use-fcgi-app application - use-server www if { req_ssl_sni -i www.example.com } - use-server www if { req_ssl_sni -i www.example.com } # comment + use-server www if { req.ssl_sni -i www.example.com } + use-server www if { req.ssl_sni -i www.example.com } # comment load-server-state-from-file global server-template srv 1-3 google.com:80 check server-template srv 3 google.com:80 check @@ -543,6 +543,8 @@ backend test http-request set-var-fmt(req.my_var) req.fhdr(user-agent),lower http-request silent-drop http-request silent-drop if FALSE + http-request silent-drop rst-ttl 1 + http-request silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } http-request strict-mode on http-request strict-mode on if FALSE http-request tarpit @@ -682,6 +684,8 @@ backend test http-response set-var-fmt(req.my_var) res.fhdr(user-agent),lower http-response silent-drop http-response silent-drop if FALSE + http-response silent-drop rst-ttl 1 + http-response silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } http-response unset-var(req.my_var) http-response unset-var(req.my_var) if FALSE http-response track-sc0 src if FALSE @@ -883,6 +887,8 @@ backend test tcp-request content unset-var(sess.dn) tcp-request content silent-drop tcp-request content silent-drop if !HTTP + tcp-request content silent-drop rst-ttl 1 + tcp-request content silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } tcp-request content send-spoe-group engine group tcp-request content use-service lua.deny tcp-request content use-service lua.deny if !HTTP @@ -930,6 +936,8 @@ backend test tcp-request connection set-src hdr(x-forwarded-for) if some_check tcp-request connection silent-drop tcp-request connection silent-drop if !HTTP + tcp-request connection silent-drop rst-ttl 1 + tcp-request connection silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } tcp-request connection lua.foo tcp-request connection lua.foo param if !HTTP tcp-request connection lua.foo param param1 @@ -972,6 +980,8 @@ backend test tcp-request session unset-var(sess.dn) tcp-request session silent-drop tcp-request session silent-drop if !HTTP + tcp-request session silent-drop rst-ttl 1 + tcp-request session silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } tcp-request session attach-srv srv1 tcp-request session attach-srv srv1 name example.com tcp-request session attach-srv srv1 name example.com if exceeds_limit @@ -1391,6 +1401,8 @@ defaults test http-request set-var-fmt(req.my_var) req.fhdr(user-agent),lower http-request silent-drop http-request silent-drop if FALSE + http-request silent-drop rst-ttl 1 + http-request silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } http-request strict-mode on http-request strict-mode on if FALSE http-request tarpit @@ -1530,6 +1542,8 @@ defaults test http-response set-var-fmt(req.my_var) res.fhdr(user-agent),lower http-response silent-drop http-response silent-drop if FALSE + http-response silent-drop rst-ttl 1 + http-response silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } http-response unset-var(req.my_var) http-response unset-var(req.my_var) if FALSE http-response track-sc0 src if FALSE @@ -1731,6 +1745,8 @@ defaults test tcp-request content unset-var(sess.dn) tcp-request content silent-drop tcp-request content silent-drop if !HTTP + tcp-request content silent-drop rst-ttl 1 + tcp-request content silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } tcp-request content send-spoe-group engine group tcp-request content use-service lua.deny tcp-request content use-service lua.deny if !HTTP @@ -1778,6 +1794,8 @@ defaults test tcp-request connection set-src hdr(x-forwarded-for) if some_check tcp-request connection silent-drop tcp-request connection silent-drop if !HTTP + tcp-request connection silent-drop rst-ttl 1 + tcp-request connection silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } tcp-request connection lua.foo tcp-request connection lua.foo param if !HTTP tcp-request connection lua.foo param param1 @@ -1820,6 +1838,8 @@ defaults test tcp-request session unset-var(sess.dn) tcp-request session silent-drop tcp-request session silent-drop if !HTTP + tcp-request session silent-drop rst-ttl 1 + tcp-request session silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } tcp-request session attach-srv srv1 tcp-request session attach-srv srv1 name example.com tcp-request session attach-srv srv1 name example.com if exceeds_limit @@ -2186,6 +2206,8 @@ frontend test http-request set-var-fmt(req.my_var) req.fhdr(user-agent),lower http-request silent-drop http-request silent-drop if FALSE + http-request silent-drop rst-ttl 1 + http-request silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } http-request strict-mode on http-request strict-mode on if FALSE http-request tarpit @@ -2245,6 +2267,7 @@ frontend test http-request set-fc-mark 0 http-request set-fc-tos 0xff if TRUE http-request capture req.cook_cnt(FirstVisit),bool len 10 + http-request capture str("DNS resolution failure") len 32 unless dns_successful http-request add-header Authorization Basic\ eC1oYXByb3h5LXJlY3J1aXRzOlBlb3BsZSB3aG8gZGVjb2RlIG1lc3NhZ2VzIG9mdGVuIGxvdmUgd29ya2luZyBhdCBIQVByb3h5LiBEbyBub3QgYmUgc2h5LCBjb250YWN0IHVz http-request add-header Authorisation "Basic eC1oYXByb3h5LXJlY3J1aXRzOlBlb3BsZSB3aG8gZGVjb2RlIG1lc3NhZ2VzIG9mdGVuIGxvdmUgd29ya2luZyBhdCBIQVByb3h5LiBEbyBub3QgYmUgc2h5LCBjb250YWN0IHVz" http-request return status 200 content-type "text/plain" string "My content" if { var(txn.myip) -m found } @@ -2326,6 +2349,8 @@ frontend test http-response set-var-fmt(req.my_var) res.fhdr(user-agent),lower http-response silent-drop http-response silent-drop if FALSE + http-response silent-drop rst-ttl 1 + http-response silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } http-response unset-var(req.my_var) http-response unset-var(req.my_var) if FALSE http-response track-sc0 src if FALSE @@ -2466,6 +2491,8 @@ frontend test tcp-request content unset-var(sess.dn) tcp-request content silent-drop tcp-request content silent-drop if !HTTP + tcp-request content silent-drop rst-ttl 1 + tcp-request content silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } tcp-request content send-spoe-group engine group tcp-request content use-service lua.deny tcp-request content use-service lua.deny if !HTTP @@ -2513,6 +2540,8 @@ frontend test tcp-request connection set-src hdr(x-forwarded-for) if some_check tcp-request connection silent-drop tcp-request connection silent-drop if !HTTP + tcp-request connection silent-drop rst-ttl 1 + tcp-request connection silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } tcp-request connection lua.foo tcp-request connection lua.foo param if !HTTP tcp-request connection lua.foo param param1 @@ -2555,6 +2584,8 @@ frontend test tcp-request session unset-var(sess.dn) tcp-request session silent-drop tcp-request session silent-drop if !HTTP + tcp-request session silent-drop rst-ttl 1 + tcp-request session silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } tcp-request session attach-srv srv1 tcp-request session attach-srv srv1 name example.com tcp-request session attach-srv srv1 name example.com if exceeds_limit @@ -2590,6 +2621,7 @@ frontend test tcp-request content set-bc-tos 0xff if some_check tcp-request content set-fc-mark 0xffffffff tcp-request content set-fc-tos 100 + tcp-request content capture str("DNS resolution failure") len 32 unless dns_successful tcp-response content lua.foo tcp-response content lua.foo param if !HTTP tcp-response content lua.foo param param1 @@ -3870,9 +3902,9 @@ var configTests = []configTest{{` command spoa-mirror --runtime 0 --mirror-url `, 2}, {` use-fcgi-app application `, 1}, - {` use-server www if { req_ssl_sni -i www.example.com } + {` use-server www if { req.ssl_sni -i www.example.com } `, 1}, - {` use-server www if { req_ssl_sni -i www.example.com } # comment + {` use-server www if { req.ssl_sni -i www.example.com } # comment `, 1}, {` lua-prepend-path /usr/share/haproxy-lua/?/init.lua `, 1}, @@ -4221,6 +4253,10 @@ var configTests = []configTest{{` command spoa-mirror --runtime 0 --mirror-url {` http-request silent-drop `, 3}, {` http-request silent-drop if FALSE +`, 3}, + {` http-request silent-drop rst-ttl 1 +`, 3}, + {` http-request silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } `, 3}, {` http-request strict-mode on `, 3}, @@ -4339,6 +4375,8 @@ var configTests = []configTest{{` command spoa-mirror --runtime 0 --mirror-url {` http-request set-fc-tos 0xff if TRUE `, 3}, {` http-request capture req.cook_cnt(FirstVisit),bool len 10 +`, 1}, + {` http-request capture str("DNS resolution failure") len 32 unless dns_successful `, 1}, {` http-response set-map(map.lst) %[src] %[res.hdr(X-Value)] if value `, 3}, @@ -4475,6 +4513,10 @@ var configTests = []configTest{{` command spoa-mirror --runtime 0 --mirror-url {` http-response silent-drop `, 3}, {` http-response silent-drop if FALSE +`, 3}, + {` http-response silent-drop rst-ttl 1 +`, 3}, + {` http-response silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } `, 3}, {` http-response unset-var(req.my_var) `, 3}, @@ -4821,6 +4863,10 @@ var configTests = []configTest{{` command spoa-mirror --runtime 0 --mirror-url {` tcp-request content silent-drop `, 3}, {` tcp-request content silent-drop if !HTTP +`, 3}, + {` tcp-request content silent-drop rst-ttl 1 +`, 3}, + {` tcp-request content silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } `, 3}, {` tcp-request content send-spoe-group engine group `, 3}, @@ -4915,6 +4961,10 @@ var configTests = []configTest{{` command spoa-mirror --runtime 0 --mirror-url {` tcp-request connection silent-drop `, 3}, {` tcp-request connection silent-drop if !HTTP +`, 3}, + {` tcp-request connection silent-drop rst-ttl 1 +`, 3}, + {` tcp-request connection silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } `, 3}, {` tcp-request connection lua.foo `, 3}, @@ -4999,6 +5049,10 @@ var configTests = []configTest{{` command spoa-mirror --runtime 0 --mirror-url {` tcp-request session silent-drop `, 3}, {` tcp-request session silent-drop if !HTTP +`, 3}, + {` tcp-request session silent-drop rst-ttl 1 +`, 3}, + {` tcp-request session silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } `, 3}, {` tcp-request session attach-srv srv1 `, 3}, @@ -5070,6 +5124,8 @@ var configTests = []configTest{{` command spoa-mirror --runtime 0 --mirror-url `, 3}, {` tcp-request content set-fc-tos 100 `, 3}, + {` tcp-request content capture str("DNS resolution failure") len 32 unless dns_successful +`, 1}, {` tcp-response content lua.foo `, 2}, {` tcp-response content lua.foo param if !HTTP diff --git a/config-parser/tests/configs/parse_check_new_line_test.go b/config-parser/tests/configs/parse_check_new_line_test.go index 0a4d5b55..f8084b98 100644 --- a/config-parser/tests/configs/parse_check_new_line_test.go +++ b/config-parser/tests/configs/parse_check_new_line_test.go @@ -32,7 +32,7 @@ func TestParseCheckNewLineOnEnd(t *testing.T) { t.Run(config.Name, func(t *testing.T) { p, err := parser.New(options.String(config.Config)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config+"\n" { diff --git a/config-parser/tests/configs/parse_empty_test.go b/config-parser/tests/configs/parse_empty_test.go index 990b8e6d..59622c43 100644 --- a/config-parser/tests/configs/parse_empty_test.go +++ b/config-parser/tests/configs/parse_empty_test.go @@ -32,11 +32,11 @@ func TestEmpty(t *testing.T) { t.Run(config.Name, func(t *testing.T) { p, err := parser.New() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } err = p.Process(strings.NewReader(config.Config)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { diff --git a/config-parser/tests/configs/parse_fetch_comments_test.go b/config-parser/tests/configs/parse_fetch_comments_test.go index 17773478..675c1215 100644 --- a/config-parser/tests/configs/parse_fetch_comments_test.go +++ b/config-parser/tests/configs/parse_fetch_comments_test.go @@ -33,7 +33,7 @@ func TestParseFecthCommentLines(t *testing.T) { //nolint:gocognit t.Run(config.Name, func(t *testing.T) { p, err := parser.New(options.String(config.Config)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -87,7 +87,7 @@ func TestParseFecthCommentLinesWrite(t *testing.T) { t.Run(config.Name, func(t *testing.T) { p, err := parser.New(options.String(config.Config)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() // fmt.Println(config.Config) @@ -131,7 +131,7 @@ func TestParseFetchCommentInline(t *testing.T) { t.Run(config.Name, func(t *testing.T) { p, err := parser.New(options.String(config.Config)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -141,7 +141,7 @@ func TestParseFetchCommentInline(t *testing.T) { rawData, err := p.Get(parser.Frontends, "http", "mode") if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } mode, ok := rawData.(*types.StringC) if !ok { @@ -153,7 +153,7 @@ func TestParseFetchCommentInline(t *testing.T) { rawData, err = p.Get(parser.Frontends, "http", "bind") if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } bindList, ok := rawData.([]types.Bind) if !ok { @@ -180,7 +180,7 @@ func TestParseFirstComments(t *testing.T) { t.Run(config.Name, func(t *testing.T) { p, err := parser.New(options.String(config.Config)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -190,7 +190,7 @@ func TestParseFirstComments(t *testing.T) { comments, err := p.Get(parser.Comments, parser.CommentsSectionName, "#") if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } data, ok := comments.([]types.Comments) if !ok { diff --git a/config-parser/tests/configs/parse_fetch_lines_test.go b/config-parser/tests/configs/parse_fetch_lines_test.go index 156aeede..7a356d67 100644 --- a/config-parser/tests/configs/parse_fetch_lines_test.go +++ b/config-parser/tests/configs/parse_fetch_lines_test.go @@ -32,11 +32,11 @@ func TestParseFecthResultLines(t *testing.T) { //nolint:gocognit t.Run(config.Name, func(t *testing.T) { p, err := parser.New(options.String(config.Config)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } lines, err := p.GetResult(parser.Frontends, "http", "bind") if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } if lines[0].Data != "bind 0.0.0.0:80 name bind_1" { t.Fatalf("Unexpected line: %s", lines[0].Data) diff --git a/config-parser/tests/configs/parse_string_test.go b/config-parser/tests/configs/parse_string_test.go index 44880108..126c5cd1 100644 --- a/config-parser/tests/configs/parse_string_test.go +++ b/config-parser/tests/configs/parse_string_test.go @@ -32,7 +32,7 @@ func TestParseString(t *testing.T) { t.Run(config.Name, func(t *testing.T) { p, err := parser.New(options.String(config.Config)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { diff --git a/config-parser/tests/configs/parser_defaults_getset_test.go b/config-parser/tests/configs/parser_defaults_getset_test.go index 88f56e07..ed68abf0 100644 --- a/config-parser/tests/configs/parser_defaults_getset_test.go +++ b/config-parser/tests/configs/parser_defaults_getset_test.go @@ -35,7 +35,7 @@ func TestDefaultsConfigsGet(t *testing.T) { //nolint:gocognit buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } name, err := p.SectionsDefaultsFromGet(parser.Defaults, "A") if err != nil { @@ -106,7 +106,7 @@ func TestDefaultsConfigsSet(t *testing.T) { //nolint:gocognit buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } err = p.SectionsDefaultsFromSet(parser.Frontends, "http1", "B") diff --git a/config-parser/tests/configs/parser_defaults_nofromflag_test.go b/config-parser/tests/configs/parser_defaults_nofromflag_test.go index ccc3ea8f..ab2ff61c 100644 --- a/config-parser/tests/configs/parser_defaults_nofromflag_test.go +++ b/config-parser/tests/configs/parser_defaults_nofromflag_test.go @@ -38,7 +38,7 @@ func TestDefaultsConfigsNoName(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Result { diff --git a/config-parser/tests/configs/parser_defaults_noname_test.go b/config-parser/tests/configs/parser_defaults_noname_test.go index e4296a82..77342215 100644 --- a/config-parser/tests/configs/parser_defaults_noname_test.go +++ b/config-parser/tests/configs/parser_defaults_noname_test.go @@ -36,7 +36,7 @@ func TestDefaultsConfigsNoFromFlag(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer), options.NoNamedDefaultsFrom) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Result { diff --git a/config-parser/tests/configs/parser_defaults_test.go b/config-parser/tests/configs/parser_defaults_test.go index e435e6ce..659e475c 100644 --- a/config-parser/tests/configs/parser_defaults_test.go +++ b/config-parser/tests/configs/parser_defaults_test.go @@ -41,7 +41,7 @@ func TestDefaultsConfigs(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -65,7 +65,7 @@ func TestDefaultsConfigsSetDef(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } err = p.SectionsDefaultsFromSet(parser.Defaults, "???", "nonexisting") if !errors.Is(err, parserErrors.ErrSectionMissing) { @@ -96,7 +96,7 @@ func TestDefaultsConfigsSetCircular(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } err = p.SectionsDefaultsFromSet(parser.Defaults, "A", "withName") if err != nil { diff --git a/config-parser/tests/configs/parser_setenv_test.go b/config-parser/tests/configs/parser_setenv_test.go index c8986ecb..4396648d 100644 --- a/config-parser/tests/configs/parser_setenv_test.go +++ b/config-parser/tests/configs/parser_setenv_test.go @@ -64,7 +64,7 @@ func TestSetEnv(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() // fmt.Println(result) diff --git a/config-parser/tests/configs/parser_test.go b/config-parser/tests/configs/parser_test.go index 49b5ac62..3a34d76b 100644 --- a/config-parser/tests/configs/parser_test.go +++ b/config-parser/tests/configs/parser_test.go @@ -39,7 +39,7 @@ func TestWholeConfigs(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -65,7 +65,7 @@ func TestWholeConfigsFail(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result == config.Config { @@ -95,7 +95,7 @@ func TestGeneratedConfig(t *testing.T) { buffer.WriteString(generatedConfig) p, err := parser.New(options.DisableUnProcessed, options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() for _, configLine := range configTests { @@ -111,11 +111,11 @@ func TestHashConfig(t *testing.T) { buffer.WriteString(configBasicHash) p, err := parser.New(options.UseMd5Hash, options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result, err := p.StringWithHash() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } if result != configBasicHash { compare(t, configBasicHash, result) @@ -128,7 +128,7 @@ func TestConfigUseV2HTTPCheck(t *testing.T) { buffer.WriteString(configBasicUseV2HTTPCheck) p, err := parser.New(options.UseV2HTTPCheck, options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() //nolint:ifshort if result != configBasicUseV2HTTPCheck { @@ -142,7 +142,7 @@ func TestListenSectionParsers(t *testing.T) { buffer.WriteString(configFull) p, err := parser.New(options.UseListenSectionParsers, options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() //nolint:ifshort diff --git a/config-parser/tests/cookie_generated_test.go b/config-parser/tests/cookie_generated_test.go index 92e9dbe8..8552c325 100644 --- a/config-parser/tests/cookie_generated_test.go +++ b/config-parser/tests/cookie_generated_test.go @@ -61,12 +61,12 @@ func TestCookie(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -76,15 +76,15 @@ func TestCookie(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/cpu-map_generated_test.go b/config-parser/tests/cpu-map_generated_test.go index 4fb45c8d..db2fb32e 100644 --- a/config-parser/tests/cpu-map_generated_test.go +++ b/config-parser/tests/cpu-map_generated_test.go @@ -54,12 +54,12 @@ func TestCPUMap(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -69,15 +69,15 @@ func TestCPUMap(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/daemon_generated_test.go b/config-parser/tests/daemon_generated_test.go index c0bb7fbb..3e61be1b 100644 --- a/config-parser/tests/daemon_generated_test.go +++ b/config-parser/tests/daemon_generated_test.go @@ -51,12 +51,12 @@ func TestDaemon(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestDaemon(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/declare-capture_generated_test.go b/config-parser/tests/declare-capture_generated_test.go index 1e0287e9..3e5cc81a 100644 --- a/config-parser/tests/declare-capture_generated_test.go +++ b/config-parser/tests/declare-capture_generated_test.go @@ -69,12 +69,12 @@ func TestDeclareCapture(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -84,15 +84,15 @@ func TestDeclareCapture(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/default-bind_generated_test.go b/config-parser/tests/default-bind_generated_test.go index f5a582b8..21dcde5b 100644 --- a/config-parser/tests/default-bind_generated_test.go +++ b/config-parser/tests/default-bind_generated_test.go @@ -53,12 +53,12 @@ func TestDefaultBind(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestDefaultBind(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/default-path_generated_test.go b/config-parser/tests/default-path_generated_test.go index eeaf37c9..d70cf235 100644 --- a/config-parser/tests/default-path_generated_test.go +++ b/config-parser/tests/default-path_generated_test.go @@ -59,12 +59,12 @@ func TestDefaultPath(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -74,15 +74,15 @@ func TestDefaultPath(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/default-server_generated_test.go b/config-parser/tests/default-server_generated_test.go index 4fff768d..3eb2602e 100644 --- a/config-parser/tests/default-server_generated_test.go +++ b/config-parser/tests/default-server_generated_test.go @@ -195,12 +195,12 @@ func TestDefaultServer(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -210,15 +210,15 @@ func TestDefaultServer(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/default_backend_generated_test.go b/config-parser/tests/default_backend_generated_test.go index a04f37d9..5ccbc418 100644 --- a/config-parser/tests/default_backend_generated_test.go +++ b/config-parser/tests/default_backend_generated_test.go @@ -51,12 +51,12 @@ func TestDefaultBackend(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestDefaultBackend(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/dgram-bind_generated_test.go b/config-parser/tests/dgram-bind_generated_test.go index 8d3e7ba5..5ad8aa5d 100644 --- a/config-parser/tests/dgram-bind_generated_test.go +++ b/config-parser/tests/dgram-bind_generated_test.go @@ -57,12 +57,12 @@ func TestDgramBind(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -72,15 +72,15 @@ func TestDgramBind(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/email-alert_generated_test.go b/config-parser/tests/email-alert_generated_test.go index ec598411..6eed9273 100644 --- a/config-parser/tests/email-alert_generated_test.go +++ b/config-parser/tests/email-alert_generated_test.go @@ -59,12 +59,12 @@ func TestEmailAlert(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -74,15 +74,15 @@ func TestEmailAlert(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/errorfile_generated_test.go b/config-parser/tests/errorfile_generated_test.go index cc15369e..c310d47e 100644 --- a/config-parser/tests/errorfile_generated_test.go +++ b/config-parser/tests/errorfile_generated_test.go @@ -54,12 +54,12 @@ func TestErrorFile(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -69,15 +69,15 @@ func TestErrorFile(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/errorfiles_generated_test.go b/config-parser/tests/errorfiles_generated_test.go index 15cd7b75..222b4693 100644 --- a/config-parser/tests/errorfiles_generated_test.go +++ b/config-parser/tests/errorfiles_generated_test.go @@ -57,12 +57,12 @@ func TestErrorFiles(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -72,15 +72,15 @@ func TestErrorFiles(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/errorloc302_generated_test.go b/config-parser/tests/errorloc302_generated_test.go index fa28b0f8..d6ed7489 100644 --- a/config-parser/tests/errorloc302_generated_test.go +++ b/config-parser/tests/errorloc302_generated_test.go @@ -56,12 +56,12 @@ func TestErrorLoc302(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -71,15 +71,15 @@ func TestErrorLoc302(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/errorloc303_generated_test.go b/config-parser/tests/errorloc303_generated_test.go index 3f2da6b7..c423edf9 100644 --- a/config-parser/tests/errorloc303_generated_test.go +++ b/config-parser/tests/errorloc303_generated_test.go @@ -56,12 +56,12 @@ func TestErrorLoc303(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -71,15 +71,15 @@ func TestErrorLoc303(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/external-check-command_generated_test.go b/config-parser/tests/external-check-command_generated_test.go index 3f747c27..83e3c0cd 100644 --- a/config-parser/tests/external-check-command_generated_test.go +++ b/config-parser/tests/external-check-command_generated_test.go @@ -50,12 +50,12 @@ func TestExternalCheckCommand(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -65,15 +65,15 @@ func TestExternalCheckCommand(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/external-check-path_generated_test.go b/config-parser/tests/external-check-path_generated_test.go index 3f7b5793..a0b720cd 100644 --- a/config-parser/tests/external-check-path_generated_test.go +++ b/config-parser/tests/external-check-path_generated_test.go @@ -50,12 +50,12 @@ func TestExternalCheckPath(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -65,15 +65,15 @@ func TestExternalCheckPath(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/external-check_generated_test.go b/config-parser/tests/external-check_generated_test.go index e40221b2..3b1abd02 100644 --- a/config-parser/tests/external-check_generated_test.go +++ b/config-parser/tests/external-check_generated_test.go @@ -51,12 +51,12 @@ func TestExternalCheck(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestExternalCheck(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/filter_generated_test.go b/config-parser/tests/filter_generated_test.go index 5f130f47..64b5dcd7 100644 --- a/config-parser/tests/filter_generated_test.go +++ b/config-parser/tests/filter_generated_test.go @@ -105,12 +105,12 @@ func TestFiltersfilters(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -120,15 +120,15 @@ func TestFiltersfilters(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/force-persist_generated_test.go b/config-parser/tests/force-persist_generated_test.go index ac582fba..30491fad 100644 --- a/config-parser/tests/force-persist_generated_test.go +++ b/config-parser/tests/force-persist_generated_test.go @@ -55,12 +55,12 @@ func TestForcePersist(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -70,15 +70,15 @@ func TestForcePersist(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/group_generated_test.go b/config-parser/tests/group_generated_test.go index be8499bc..11067262 100644 --- a/config-parser/tests/group_generated_test.go +++ b/config-parser/tests/group_generated_test.go @@ -52,12 +52,12 @@ func TestGroup(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -67,15 +67,15 @@ func TestGroup(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/h1-case-adjust_generated_test.go b/config-parser/tests/h1-case-adjust_generated_test.go index 1ad6eae1..e324f18e 100644 --- a/config-parser/tests/h1-case-adjust_generated_test.go +++ b/config-parser/tests/h1-case-adjust_generated_test.go @@ -53,12 +53,12 @@ func TestH1CaseAdjust(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestH1CaseAdjust(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/hash-type_generated_test.go b/config-parser/tests/hash-type_generated_test.go index a4094f0a..2dee8b19 100644 --- a/config-parser/tests/hash-type_generated_test.go +++ b/config-parser/tests/hash-type_generated_test.go @@ -72,12 +72,12 @@ func TestHashType(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -87,15 +87,15 @@ func TestHashType(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/http-after-response_generated_test.go b/config-parser/tests/http-after-response_generated_test.go index 08516673..e9ea2e4c 100644 --- a/config-parser/tests/http-after-response_generated_test.go +++ b/config-parser/tests/http-after-response_generated_test.go @@ -118,12 +118,12 @@ func TestAfterResponseshttp(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -133,15 +133,15 @@ func TestAfterResponseshttp(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/http-check_generated_test.go b/config-parser/tests/http-check_generated_test.go index 18887670..1a048a27 100644 --- a/config-parser/tests/http-check_generated_test.go +++ b/config-parser/tests/http-check_generated_test.go @@ -96,12 +96,12 @@ func TestCheckshttp(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -111,15 +111,15 @@ func TestCheckshttp(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/http-err-codes_generated_test.go b/config-parser/tests/http-err-codes_generated_test.go index ce26a752..d56a01fe 100644 --- a/config-parser/tests/http-err-codes_generated_test.go +++ b/config-parser/tests/http-err-codes_generated_test.go @@ -53,12 +53,12 @@ func TestHTTPErrCodes(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestHTTPErrCodes(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/http-error_generated_test.go b/config-parser/tests/http-error_generated_test.go index 1eb64074..72362758 100644 --- a/config-parser/tests/http-error_generated_test.go +++ b/config-parser/tests/http-error_generated_test.go @@ -63,12 +63,12 @@ func TestHTTPErrorshttp(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -78,15 +78,15 @@ func TestHTTPErrorshttp(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/http-fail-codes_generated_test.go b/config-parser/tests/http-fail-codes_generated_test.go index 1ca09b23..ba68fba2 100644 --- a/config-parser/tests/http-fail-codes_generated_test.go +++ b/config-parser/tests/http-fail-codes_generated_test.go @@ -53,12 +53,12 @@ func TestHTTPFailCodes(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestHTTPFailCodes(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/http-request_generated_test.go b/config-parser/tests/http-request_generated_test.go index fd924740..8e2a129b 100644 --- a/config-parser/tests/http-request_generated_test.go +++ b/config-parser/tests/http-request_generated_test.go @@ -27,137 +27,140 @@ import ( func TestRequestshttp(t *testing.T) { tests := map[string]bool{ - `http-request capture req.cook_cnt(FirstVisit),bool len 10`: true, - "http-request set-map(map.lst) %[src] %[req.hdr(X-Value)] if value": true, - "http-request set-map(map.lst) %[src] %[req.hdr(X-Value)]": true, - "http-request add-acl(map.lst) [src]": true, - "http-request add-header X-value value": true, - "http-request cache-use cache-name": true, - "http-request cache-use cache-name if FALSE": true, - "http-request del-acl(map.lst) [src]": true, - "http-request allow": true, - "http-request auth": true, - "http-request del-header X-value": true, - "http-request del-header X-value if TRUE": true, - "http-request del-header X-value -m str if TRUE": true, - "http-request del-map(map.lst) %[src] if ! value": true, - "http-request del-map(map.lst) %[src]": true, - "http-request deny": true, - "http-request deny deny_status 400": true, - "http-request deny if TRUE": true, - "http-request deny deny_status 400 if TRUE": true, - "http-request deny deny_status 400 content-type application/json if TRUE": true, - "http-request deny deny_status 400 content-type application/json": true, - "http-request deny deny_status 400 content-type application/json default-errorfiles": true, - "http-request deny deny_status 400 content-type application/json errorfile errors": true, - "http-request deny deny_status 400 content-type application/json string error if TRUE": true, + `http-request capture req.cook_cnt(FirstVisit),bool len 10`: true, + `http-request capture str("DNS resolution failure") len 32 unless dns_successful`: true, + "http-request set-map(map.lst) %[src] %[req.hdr(X-Value)] if value": true, + "http-request set-map(map.lst) %[src] %[req.hdr(X-Value)]": true, + "http-request add-acl(map.lst) [src]": true, + "http-request add-header X-value value": true, + "http-request cache-use cache-name": true, + "http-request cache-use cache-name if FALSE": true, + "http-request del-acl(map.lst) [src]": true, + "http-request allow": true, + "http-request auth": true, + "http-request del-header X-value": true, + "http-request del-header X-value if TRUE": true, + "http-request del-header X-value -m str if TRUE": true, + "http-request del-map(map.lst) %[src] if ! value": true, + "http-request del-map(map.lst) %[src]": true, + "http-request deny": true, + "http-request deny deny_status 400": true, + "http-request deny if TRUE": true, + "http-request deny deny_status 400 if TRUE": true, + "http-request deny deny_status 400 content-type application/json if TRUE": true, + "http-request deny deny_status 400 content-type application/json": true, + "http-request deny deny_status 400 content-type application/json default-errorfiles": true, + "http-request deny deny_status 400 content-type application/json errorfile errors": true, + "http-request deny deny_status 400 content-type application/json string error if TRUE": true, "http-request deny deny_status 400 content-type application/json lf-string error hdr host google.com if TRUE": true, "http-request deny deny_status 400 content-type application/json file /var/errors.file": true, "http-request deny deny_status 400 content-type application/json lf-file /var/errors.file": true, "http-request deny deny_status 400 content-type application/json string error hdr host google.com if TRUE": true, "http-request deny deny_status 400 content-type application/json string error hdr host google.com hdr x-value bla if TRUE": true, "http-request deny deny_status 400 content-type application/json string error hdr host google.com hdr x-value bla": true, - "http-request disable-l7-retry": true, - "http-request disable-l7-retry if FALSE": true, - "http-request early-hint hint %[src]": true, - "http-request early-hint hint %[src] if FALSE": true, - "http-request early-hint if FALSE": true, - "http-request lua.foo": true, - "http-request lua.foo if FALSE": true, - "http-request lua.foo param": true, - "http-request lua.foo param param2": true, - "http-request normalize-uri fragment-encode": true, - "http-request normalize-uri fragment-encode if TRUE": true, - "http-request normalize-uri fragment-strip": true, - "http-request normalize-uri fragment-strip if TRUE": true, - "http-request normalize-uri path-merge-slashes": true, - "http-request normalize-uri path-merge-slashes if TRUE": true, - "http-request normalize-uri path-strip-dot": true, - "http-request normalize-uri path-strip-dot if TRUE": true, - "http-request normalize-uri path-strip-dotdot": true, - "http-request normalize-uri path-strip-dotdot full": true, - "http-request normalize-uri path-strip-dotdot if TRUE": true, - "http-request normalize-uri path-strip-dotdot full if TRUE": true, - "http-request normalize-uri percent-decode-unreserved": true, - "http-request normalize-uri percent-decode-unreserved if TRUE": true, - "http-request normalize-uri percent-decode-unreserved strict": true, - "http-request normalize-uri percent-decode-unreserved strict if TRUE": true, - "http-request normalize-uri percent-to-uppercase": true, - "http-request normalize-uri percent-to-uppercase if TRUE": true, - "http-request normalize-uri percent-to-uppercase strict": true, - "http-request normalize-uri percent-to-uppercase strict if TRUE": true, - "http-request normalize-uri query-sort-by-name": true, - "http-request normalize-uri query-sort-by-name if TRUE": true, - "http-request redirect prefix https://mysite.com": true, - "http-request reject": true, - "http-request replace-header User-agent curl foo": true, - "http-request replace-path (.*) /foo": true, - "http-request replace-path (.*) /foo if TRUE": true, - "http-request replace-pathq (.*) /foo": true, - "http-request replace-pathq (.*) /foo if TRUE": true, - "http-request replace-uri ^http://(.*) https://1": true, - "http-request replace-uri ^http://(.*) https://1 if FALSE": true, - "http-request replace-value X-Forwarded-For ^192.168.(.*)$ 172.16.1": true, - "http-request sc-add-gpc(1,2) 1": true, - "http-request sc-add-gpc(1,2) 1 if is-error": true, - "http-request sc-inc-gpc(1,2)": true, - "http-request sc-inc-gpc(1,2) if FALSE": true, - "http-request sc-inc-gpc0(1)": true, - "http-request sc-inc-gpc0(1) if FALSE": true, - "http-request sc-inc-gpc1(1)": true, - "http-request sc-inc-gpc1(1) if FALSE": true, - "http-request sc-set-gpt(1,2) hdr(Host),lower if FALSE": true, - "http-request sc-set-gpt0(1) hdr(Host),lower": true, - "http-request sc-set-gpt0(1) 10": true, - "http-request sc-set-gpt0(1) hdr(Host),lower if FALSE": true, - "http-request send-spoe-group engine group": true, - "http-request set-header X-value value": true, - "http-request set-log-level silent": true, - "http-request set-mark 20": true, - "http-request set-mark 0x1Ab": true, - "http-request set-nice 0": true, - "http-request set-nice 0 if FALSE": true, - "http-request set-method POST": true, - "http-request set-method POST if FALSE": true, - "http-request set-path /%[hdr(host)]%[path]": true, - "http-request set-pathq /%[hdr(host)]%[path]": true, - "http-request set-priority-class req.hdr(priority)": true, - "http-request set-priority-class req.hdr(priority) if FALSE": true, - "http-request set-priority-offset req.hdr(offset)": true, - "http-request set-priority-offset req.hdr(offset) if FALSE": true, - "http-request set-query %[query,regsub(%3D,=,g)]": true, - "http-request set-src hdr(src)": true, - "http-request set-src hdr(src) if FALSE": true, - "http-request set-src-port hdr(port)": true, - "http-request set-src-port hdr(port) if FALSE": true, - "http-request set-timeout server 20": true, - "http-request set-timeout tunnel 20": true, - "http-request set-timeout tunnel 20s if TRUE": true, - "http-request set-timeout server 20s if TRUE": true, - "http-request set-timeout client 20": true, - "http-request set-timeout client 20s if TRUE": true, - "http-request set-tos 0 if FALSE": true, - "http-request set-tos 0": true, - "http-request set-uri /%[hdr(host)]%[path]": true, - "http-request set-var(req.my_var) req.fhdr(user-agent),lower": true, - "http-request set-var-fmt(req.my_var) req.fhdr(user-agent),lower": true, - "http-request silent-drop": true, - "http-request silent-drop if FALSE": true, - "http-request strict-mode on": true, - "http-request strict-mode on if FALSE": true, - "http-request tarpit": true, - "http-request tarpit deny_status 400": true, - "http-request tarpit if TRUE": true, - "http-request tarpit deny_status 400 if TRUE": true, - "http-request tarpit deny_status 400 content-type application/json if TRUE": true, - "http-request tarpit deny_status 400 content-type application/json": true, - "http-request tarpit deny_status 400 content-type application/json default-errorfiles": true, - "http-request tarpit deny_status 400 content-type application/json errorfile errors": true, - "http-request tarpit deny_status 400 content-type application/json string error if TRUE": true, - "http-request tarpit deny_status 400 content-type application/json lf-string error hdr host google.com if TRUE": true, - "http-request tarpit deny_status 400 content-type application/json file /var/errors.file": true, - "http-request tarpit deny_status 400 content-type application/json lf-file /var/errors.file": true, - "http-request tarpit deny_status 400 content-type application/json string error hdr host google.com if TRUE": true, + "http-request disable-l7-retry": true, + "http-request disable-l7-retry if FALSE": true, + "http-request early-hint hint %[src]": true, + "http-request early-hint hint %[src] if FALSE": true, + "http-request early-hint if FALSE": true, + "http-request lua.foo": true, + "http-request lua.foo if FALSE": true, + "http-request lua.foo param": true, + "http-request lua.foo param param2": true, + "http-request normalize-uri fragment-encode": true, + "http-request normalize-uri fragment-encode if TRUE": true, + "http-request normalize-uri fragment-strip": true, + "http-request normalize-uri fragment-strip if TRUE": true, + "http-request normalize-uri path-merge-slashes": true, + "http-request normalize-uri path-merge-slashes if TRUE": true, + "http-request normalize-uri path-strip-dot": true, + "http-request normalize-uri path-strip-dot if TRUE": true, + "http-request normalize-uri path-strip-dotdot": true, + "http-request normalize-uri path-strip-dotdot full": true, + "http-request normalize-uri path-strip-dotdot if TRUE": true, + "http-request normalize-uri path-strip-dotdot full if TRUE": true, + "http-request normalize-uri percent-decode-unreserved": true, + "http-request normalize-uri percent-decode-unreserved if TRUE": true, + "http-request normalize-uri percent-decode-unreserved strict": true, + "http-request normalize-uri percent-decode-unreserved strict if TRUE": true, + "http-request normalize-uri percent-to-uppercase": true, + "http-request normalize-uri percent-to-uppercase if TRUE": true, + "http-request normalize-uri percent-to-uppercase strict": true, + "http-request normalize-uri percent-to-uppercase strict if TRUE": true, + "http-request normalize-uri query-sort-by-name": true, + "http-request normalize-uri query-sort-by-name if TRUE": true, + "http-request redirect prefix https://mysite.com": true, + "http-request reject": true, + "http-request replace-header User-agent curl foo": true, + "http-request replace-path (.*) /foo": true, + "http-request replace-path (.*) /foo if TRUE": true, + "http-request replace-pathq (.*) /foo": true, + "http-request replace-pathq (.*) /foo if TRUE": true, + "http-request replace-uri ^http://(.*) https://1": true, + "http-request replace-uri ^http://(.*) https://1 if FALSE": true, + "http-request replace-value X-Forwarded-For ^192.168.(.*)$ 172.16.1": true, + "http-request sc-add-gpc(1,2) 1": true, + "http-request sc-add-gpc(1,2) 1 if is-error": true, + "http-request sc-inc-gpc(1,2)": true, + "http-request sc-inc-gpc(1,2) if FALSE": true, + "http-request sc-inc-gpc0(1)": true, + "http-request sc-inc-gpc0(1) if FALSE": true, + "http-request sc-inc-gpc1(1)": true, + "http-request sc-inc-gpc1(1) if FALSE": true, + "http-request sc-set-gpt(1,2) hdr(Host),lower if FALSE": true, + "http-request sc-set-gpt0(1) hdr(Host),lower": true, + "http-request sc-set-gpt0(1) 10": true, + "http-request sc-set-gpt0(1) hdr(Host),lower if FALSE": true, + "http-request send-spoe-group engine group": true, + "http-request set-header X-value value": true, + "http-request set-log-level silent": true, + "http-request set-mark 20": true, + "http-request set-mark 0x1Ab": true, + "http-request set-nice 0": true, + "http-request set-nice 0 if FALSE": true, + "http-request set-method POST": true, + "http-request set-method POST if FALSE": true, + "http-request set-path /%[hdr(host)]%[path]": true, + "http-request set-pathq /%[hdr(host)]%[path]": true, + "http-request set-priority-class req.hdr(priority)": true, + "http-request set-priority-class req.hdr(priority) if FALSE": true, + "http-request set-priority-offset req.hdr(offset)": true, + "http-request set-priority-offset req.hdr(offset) if FALSE": true, + "http-request set-query %[query,regsub(%3D,=,g)]": true, + "http-request set-src hdr(src)": true, + "http-request set-src hdr(src) if FALSE": true, + "http-request set-src-port hdr(port)": true, + "http-request set-src-port hdr(port) if FALSE": true, + "http-request set-timeout server 20": true, + "http-request set-timeout tunnel 20": true, + "http-request set-timeout tunnel 20s if TRUE": true, + "http-request set-timeout server 20s if TRUE": true, + "http-request set-timeout client 20": true, + "http-request set-timeout client 20s if TRUE": true, + "http-request set-tos 0 if FALSE": true, + "http-request set-tos 0": true, + "http-request set-uri /%[hdr(host)]%[path]": true, + "http-request set-var(req.my_var) req.fhdr(user-agent),lower": true, + "http-request set-var-fmt(req.my_var) req.fhdr(user-agent),lower": true, + "http-request silent-drop": true, + "http-request silent-drop if FALSE": true, + "http-request silent-drop rst-ttl 1": true, + "http-request silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 }": true, + "http-request strict-mode on": true, + "http-request strict-mode on if FALSE": true, + "http-request tarpit": true, + "http-request tarpit deny_status 400": true, + "http-request tarpit if TRUE": true, + "http-request tarpit deny_status 400 if TRUE": true, + "http-request tarpit deny_status 400 content-type application/json if TRUE": true, + "http-request tarpit deny_status 400 content-type application/json": true, + "http-request tarpit deny_status 400 content-type application/json default-errorfiles": true, + "http-request tarpit deny_status 400 content-type application/json errorfile errors": true, + "http-request tarpit deny_status 400 content-type application/json string error if TRUE": true, + "http-request tarpit deny_status 400 content-type application/json lf-string error hdr host google.com if TRUE": true, + "http-request tarpit deny_status 400 content-type application/json file /var/errors.file": true, + "http-request tarpit deny_status 400 content-type application/json lf-file /var/errors.file": true, + "http-request tarpit deny_status 400 content-type application/json string error hdr host google.com if TRUE": true, "http-request tarpit deny_status 400 content-type application/json string error hdr host google.com hdr x-value bla if TRUE": true, "http-request tarpit deny_status 400 content-type application/json string error hdr host google.com hdr x-value bla": true, "http-request track-sc0 src": true, @@ -272,6 +275,7 @@ func TestRequestshttp(t *testing.T) { "http-request set-uri": false, "http-request set-var(req.my_var)": false, "http-request set-var-fmt(req.my_var)": false, + "http-request silent-drop rst-ttl": false, "http-request strict-mode": false, "http-request strict-mode if FALSE": false, "http-request tarpit test test": false, @@ -330,12 +334,12 @@ func TestRequestshttp(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -345,15 +349,15 @@ func TestRequestshttp(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/http-request_test.go b/config-parser/tests/http-request_test.go index c87faafc..b0ebf3b9 100644 --- a/config-parser/tests/http-request_test.go +++ b/config-parser/tests/http-request_test.go @@ -31,12 +31,12 @@ func TestHTTPRequestSetPath(t *testing.T) { err := ProcessLine(line, parser) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) } var returnLine string @@ -48,7 +48,7 @@ func TestHTTPRequestSetPath(t *testing.T) { } if line != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, line)) + t.Errorf("error: has [%s] expects [%s]", returnLine, line) } } @@ -60,12 +60,12 @@ func TestHTTPRequestSetPathFail(t *testing.T) { err := ProcessLine(line, parser) if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, err = parser.Result() if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } @@ -76,12 +76,12 @@ func TestHTTPRequestConnectionTrackSc0(t *testing.T) { err := ProcessLine(line, parser) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) } var returnLine string @@ -93,7 +93,7 @@ func TestHTTPRequestConnectionTrackSc0(t *testing.T) { } if line != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, line)) + t.Errorf("error: has [%s] expects [%s]", returnLine, line) } } @@ -104,12 +104,12 @@ func TestHTTPRequestConnectionTrackSc0WithCondition(t *testing.T) { err := ProcessLine(line, parser) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) } var returnLine string @@ -121,6 +121,6 @@ func TestHTTPRequestConnectionTrackSc0WithCondition(t *testing.T) { } if line != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, line)) + t.Errorf("error: has [%s] expects [%s]", returnLine, line) } } diff --git a/config-parser/tests/http-response_generated_test.go b/config-parser/tests/http-response_generated_test.go index 948d647f..bc8a9662 100644 --- a/config-parser/tests/http-response_generated_test.go +++ b/config-parser/tests/http-response_generated_test.go @@ -96,6 +96,8 @@ func TestResponseshttp(t *testing.T) { "http-response set-var-fmt(req.my_var) res.fhdr(user-agent),lower": true, "http-response silent-drop": true, "http-response silent-drop if FALSE": true, + "http-response silent-drop rst-ttl 1": true, + "http-response silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 }": true, "http-response unset-var(req.my_var)": true, "http-response unset-var(req.my_var) if FALSE": true, "http-response track-sc0 src if FALSE": true, @@ -174,6 +176,7 @@ func TestResponseshttp(t *testing.T) { "http-response set-tos": false, "http-response set-var(req.my_var)": false, "http-response set-var-fmt(req.my_var)": false, + "http-response silent-drop rst-ttl": false, "http-response unset-var(req.)": false, "http-response unset-var(req)": false, "http-response track-sc0": false, @@ -214,12 +217,12 @@ func TestResponseshttp(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -229,15 +232,15 @@ func TestResponseshttp(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/http-reuse_generated_test.go b/config-parser/tests/http-reuse_generated_test.go index 20ddc2d6..cad1d7ec 100644 --- a/config-parser/tests/http-reuse_generated_test.go +++ b/config-parser/tests/http-reuse_generated_test.go @@ -54,12 +54,12 @@ func TestHTTPReuse(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -69,15 +69,15 @@ func TestHTTPReuse(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/http-send-name-header_generated_test.go b/config-parser/tests/http-send-name-header_generated_test.go index 0e2489bc..8cfbb806 100644 --- a/config-parser/tests/http-send-name-header_generated_test.go +++ b/config-parser/tests/http-send-name-header_generated_test.go @@ -51,12 +51,12 @@ func TestHTTPSendNameHeader(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestHTTPSendNameHeader(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/httpclient.resolvers.prefer_generated_test.go b/config-parser/tests/httpclient.resolvers.prefer_generated_test.go index 1574010b..b014cc85 100644 --- a/config-parser/tests/httpclient.resolvers.prefer_generated_test.go +++ b/config-parser/tests/httpclient.resolvers.prefer_generated_test.go @@ -53,12 +53,12 @@ func TestHTTPClientResolversPrefer(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestHTTPClientResolversPrefer(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/httpclient.ssl.verify_generated_test.go b/config-parser/tests/httpclient.ssl.verify_generated_test.go index b15cd536..fb64ceda 100644 --- a/config-parser/tests/httpclient.ssl.verify_generated_test.go +++ b/config-parser/tests/httpclient.ssl.verify_generated_test.go @@ -54,12 +54,12 @@ func TestHTTPClientSSLVerify(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -69,15 +69,15 @@ func TestHTTPClientSSLVerify(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/ignore-persist_generated_test.go b/config-parser/tests/ignore-persist_generated_test.go index e966ff43..efbd2a97 100644 --- a/config-parser/tests/ignore-persist_generated_test.go +++ b/config-parser/tests/ignore-persist_generated_test.go @@ -55,12 +55,12 @@ func TestIgnorePersist(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -70,15 +70,15 @@ func TestIgnorePersist(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/integration/backend_data_test.go b/config-parser/tests/integration/backend_data_test.go index acf8caff..d3fdc306 100644 --- a/config-parser/tests/integration/backend_data_test.go +++ b/config-parser/tests/integration/backend_data_test.go @@ -1763,11 +1763,11 @@ backend test ` const backend_useserverwwwifreqsslsniiwwwexamp = ` backend test - use-server www if { req_ssl_sni -i www.example.com } + use-server www if { req.ssl_sni -i www.example.com } ` const backend_useserverwwwifreqsslsniiwwwexamp_ = ` backend test - use-server www if { req_ssl_sni -i www.example.com } # comment + use-server www if { req.ssl_sni -i www.example.com } # comment ` const backend_loadserverstatefromfileglobal = ` backend test @@ -2361,6 +2361,14 @@ const backend_httprequestsilentdropifFALSE = ` backend test http-request silent-drop if FALSE ` +const backend_httprequestsilentdroprstttl1 = ` +backend test + http-request silent-drop rst-ttl 1 +` +const backend_httprequestsilentdroprstttl1ifsr = ` +backend test + http-request silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +` const backend_httprequeststrictmodeon = ` backend test http-request strict-mode on @@ -2917,6 +2925,14 @@ const backend_httpresponsesilentdropifFALSE = ` backend test http-response silent-drop if FALSE ` +const backend_httpresponsesilentdroprstttl1 = ` +backend test + http-response silent-drop rst-ttl 1 +` +const backend_httpresponsesilentdroprstttl1ifs = ` +backend test + http-response silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +` const backend_httpresponseunsetvarreqmyvar = ` backend test http-response unset-var(req.my_var) @@ -3721,6 +3737,14 @@ const backend_tcprequestcontentsilentdropifHTT = ` backend test tcp-request content silent-drop if !HTTP ` +const backend_tcprequestcontentsilentdroprsttt = ` +backend test + tcp-request content silent-drop rst-ttl 1 +` +const backend_tcprequestcontentsilentdroprsttt_ = ` +backend test + tcp-request content silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +` const backend_tcprequestcontentsendspoegroupen = ` backend test tcp-request content send-spoe-group engine group @@ -3909,6 +3933,14 @@ const backend_tcprequestconnectionsilentdropif = ` backend test tcp-request connection silent-drop if !HTTP ` +const backend_tcprequestconnectionsilentdroprs = ` +backend test + tcp-request connection silent-drop rst-ttl 1 +` +const backend_tcprequestconnectionsilentdroprs_ = ` +backend test + tcp-request connection silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +` const backend_tcprequestconnectionluafoo = ` backend test tcp-request connection lua.foo @@ -4077,6 +4109,14 @@ const backend_tcprequestsessionsilentdropifHTT = ` backend test tcp-request session silent-drop if !HTTP ` +const backend_tcprequestsessionsilentdroprsttt = ` +backend test + tcp-request session silent-drop rst-ttl 1 +` +const backend_tcprequestsessionsilentdroprsttt_ = ` +backend test + tcp-request session silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +` const backend_tcprequestsessionattachsrvsrv1 = ` backend test tcp-request session attach-srv srv1 diff --git a/config-parser/tests/integration/backend_test.go b/config-parser/tests/integration/backend_test.go index 25744d2e..411f6bcc 100644 --- a/config-parser/tests/integration/backend_test.go +++ b/config-parser/tests/integration/backend_test.go @@ -510,6 +510,8 @@ func TestWholeConfigsSectionsBackend(t *testing.T) { {"backend_httprequestsetvarreqmyvarreqfhdr", backend_httprequestsetvarreqmyvarreqfhdr}, {"backend_httprequestsilentdrop", backend_httprequestsilentdrop}, {"backend_httprequestsilentdropifFALSE", backend_httprequestsilentdropifFALSE}, + {"backend_httprequestsilentdroprstttl1", backend_httprequestsilentdroprstttl1}, + {"backend_httprequestsilentdroprstttl1ifsr", backend_httprequestsilentdroprstttl1ifsr}, {"backend_httprequeststrictmodeon", backend_httprequeststrictmodeon}, {"backend_httprequeststrictmodeonifFALSE", backend_httprequeststrictmodeonifFALSE}, {"backend_httprequesttarpit", backend_httprequesttarpit}, @@ -626,6 +628,8 @@ func TestWholeConfigsSectionsBackend(t *testing.T) { {"backend_httpresponsesetvarreqmyvarresfhd", backend_httpresponsesetvarreqmyvarresfhd}, {"backend_httpresponsesilentdrop", backend_httpresponsesilentdrop}, {"backend_httpresponsesilentdropifFALSE", backend_httpresponsesilentdropifFALSE}, + {"backend_httpresponsesilentdroprstttl1", backend_httpresponsesilentdroprstttl1}, + {"backend_httpresponsesilentdroprstttl1ifs", backend_httpresponsesilentdroprstttl1ifs}, {"backend_httpresponsestrictmodeon", backend_httpresponsestrictmodeon}, {"backend_httpresponsestrictmodeonifFALSE", backend_httpresponsestrictmodeonifFALSE}, {"backend_httpresponsetracksc0src", backend_httpresponsetracksc0src}, @@ -966,6 +970,8 @@ func TestWholeConfigsSectionsBackend(t *testing.T) { {"backend_tcprequestconnectionsetvarfmttxn", backend_tcprequestconnectionsetvarfmttxn}, {"backend_tcprequestconnectionsilentdrop", backend_tcprequestconnectionsilentdrop}, {"backend_tcprequestconnectionsilentdropif", backend_tcprequestconnectionsilentdropif}, + {"backend_tcprequestconnectionsilentdroprs", backend_tcprequestconnectionsilentdroprs}, + {"backend_tcprequestconnectionsilentdroprs_", backend_tcprequestconnectionsilentdroprs_}, {"backend_tcprequestconnectiontracksc0src", backend_tcprequestconnectiontracksc0src}, {"backend_tcprequestconnectiontracksc0srci", backend_tcprequestconnectiontracksc0srci}, {"backend_tcprequestconnectiontracksc0srct", backend_tcprequestconnectiontracksc0srct}, @@ -1034,6 +1040,8 @@ func TestWholeConfigsSectionsBackend(t *testing.T) { {"backend_tcprequestcontentsetvarsesssrcsr", backend_tcprequestcontentsetvarsesssrcsr}, {"backend_tcprequestcontentsilentdrop", backend_tcprequestcontentsilentdrop}, {"backend_tcprequestcontentsilentdropifHTT", backend_tcprequestcontentsilentdropifHTT}, + {"backend_tcprequestcontentsilentdroprsttt", backend_tcprequestcontentsilentdroprsttt}, + {"backend_tcprequestcontentsilentdroprsttt_", backend_tcprequestcontentsilentdroprsttt_}, {"backend_tcprequestcontentswitchmodehttp", backend_tcprequestcontentswitchmodehttp}, {"backend_tcprequestcontentswitchmodehttpi", backend_tcprequestcontentswitchmodehttpi}, {"backend_tcprequestcontentswitchmodehttpp", backend_tcprequestcontentswitchmodehttpp}, @@ -1083,6 +1091,8 @@ func TestWholeConfigsSectionsBackend(t *testing.T) { {"backend_tcprequestsessionsetvarsesssrcsr", backend_tcprequestsessionsetvarsesssrcsr}, {"backend_tcprequestsessionsilentdrop", backend_tcprequestsessionsilentdrop}, {"backend_tcprequestsessionsilentdropifHTT", backend_tcprequestsessionsilentdropifHTT}, + {"backend_tcprequestsessionsilentdroprsttt", backend_tcprequestsessionsilentdroprsttt}, + {"backend_tcprequestsessionsilentdroprsttt_", backend_tcprequestsessionsilentdroprsttt_}, {"backend_tcprequestsessiontracksc0src", backend_tcprequestsessiontracksc0src}, {"backend_tcprequestsessiontracksc0srcifso", backend_tcprequestsessiontracksc0srcifso}, {"backend_tcprequestsessiontracksc0srctabl", backend_tcprequestsessiontracksc0srctabl}, @@ -1139,7 +1149,7 @@ func TestWholeConfigsSectionsBackend(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -1149,7 +1159,7 @@ func TestWholeConfigsSectionsBackend(t *testing.T) { t.Error("======== RESULT ===========") t.Error(result) t.Error("===========================") - t.Fatalf("configurations does not match") + t.Fatal("configurations does not match") } }) } diff --git a/config-parser/tests/integration/cache_test.go b/config-parser/tests/integration/cache_test.go index 974177ce..cb6f780d 100644 --- a/config-parser/tests/integration/cache_test.go +++ b/config-parser/tests/integration/cache_test.go @@ -40,7 +40,7 @@ func TestWholeConfigsSectionsCache(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -50,7 +50,7 @@ func TestWholeConfigsSectionsCache(t *testing.T) { t.Error("======== RESULT ===========") t.Error(result) t.Error("===========================") - t.Fatalf("configurations does not match") + t.Fatal("configurations does not match") } }) } diff --git a/config-parser/tests/integration/crt-store_test.go b/config-parser/tests/integration/crt-store_test.go index 8ec67697..831ebf46 100644 --- a/config-parser/tests/integration/crt-store_test.go +++ b/config-parser/tests/integration/crt-store_test.go @@ -30,6 +30,14 @@ func TestWholeConfigsSectionsCrtstore(t *testing.T) { tests := []struct { Name, Config string }{ + {"crtstore_loadcrtfoopem", crtstore_loadcrtfoopem}, + {"crtstore_loadcrtfoopemaliasfoocom", crtstore_loadcrtfoopemaliasfoocom}, + {"crtstore_loadcrtfoopemaliasfoocomkeyfoopr", crtstore_loadcrtfoopemaliasfoocomkeyfoopr}, + {"crtstore_loadcrtfoopemaliasfoocomkeyfoopr_", crtstore_loadcrtfoopemaliasfoocomkeyfoopr_}, + {"crtstore_loadcrtfoopemaliasfoocomkeyfoopr__", crtstore_loadcrtfoopemaliasfoocomkeyfoopr__}, + {"crtstore_loadcrtfoopemaliasfoocomkeyfoopr___", crtstore_loadcrtfoopemaliasfoocomkeyfoopr___}, + {"crtstore_loadcrtfoopemaliasfoocomkeyfoopr____", crtstore_loadcrtfoopemaliasfoocomkeyfoopr____}, + {"crtstore_loadcrtfoopemaliasfoocomkeyfoopr_____", crtstore_loadcrtfoopemaliasfoocomkeyfoopr_____}, } for _, config := range tests { t.Run(config.Name, func(t *testing.T) { @@ -38,7 +46,7 @@ func TestWholeConfigsSectionsCrtstore(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -48,7 +56,7 @@ func TestWholeConfigsSectionsCrtstore(t *testing.T) { t.Error("======== RESULT ===========") t.Error(result) t.Error("===========================") - t.Fatalf("configurations does not match") + t.Fatal("configurations does not match") } }) } diff --git a/config-parser/tests/integration/defaults_data_test.go b/config-parser/tests/integration/defaults_data_test.go index fc6e27ac..929664a4 100644 --- a/config-parser/tests/integration/defaults_data_test.go +++ b/config-parser/tests/integration/defaults_data_test.go @@ -1613,6 +1613,14 @@ const defaults_httprequestsilentdropifFALSE = ` defaults test http-request silent-drop if FALSE ` +const defaults_httprequestsilentdroprstttl1 = ` +defaults test + http-request silent-drop rst-ttl 1 +` +const defaults_httprequestsilentdroprstttl1ifsr = ` +defaults test + http-request silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +` const defaults_httprequeststrictmodeon = ` defaults test http-request strict-mode on @@ -2169,6 +2177,14 @@ const defaults_httpresponsesilentdropifFALSE = ` defaults test http-response silent-drop if FALSE ` +const defaults_httpresponsesilentdroprstttl1 = ` +defaults test + http-response silent-drop rst-ttl 1 +` +const defaults_httpresponsesilentdroprstttl1ifs = ` +defaults test + http-response silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +` const defaults_httpresponseunsetvarreqmyvar = ` defaults test http-response unset-var(req.my_var) @@ -2973,6 +2989,14 @@ const defaults_tcprequestcontentsilentdropifHTT = ` defaults test tcp-request content silent-drop if !HTTP ` +const defaults_tcprequestcontentsilentdroprsttt = ` +defaults test + tcp-request content silent-drop rst-ttl 1 +` +const defaults_tcprequestcontentsilentdroprsttt_ = ` +defaults test + tcp-request content silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +` const defaults_tcprequestcontentsendspoegroupen = ` defaults test tcp-request content send-spoe-group engine group @@ -3161,6 +3185,14 @@ const defaults_tcprequestconnectionsilentdropif = ` defaults test tcp-request connection silent-drop if !HTTP ` +const defaults_tcprequestconnectionsilentdroprs = ` +defaults test + tcp-request connection silent-drop rst-ttl 1 +` +const defaults_tcprequestconnectionsilentdroprs_ = ` +defaults test + tcp-request connection silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +` const defaults_tcprequestconnectionluafoo = ` defaults test tcp-request connection lua.foo @@ -3329,6 +3361,14 @@ const defaults_tcprequestsessionsilentdropifHTT = ` defaults test tcp-request session silent-drop if !HTTP ` +const defaults_tcprequestsessionsilentdroprsttt = ` +defaults test + tcp-request session silent-drop rst-ttl 1 +` +const defaults_tcprequestsessionsilentdroprsttt_ = ` +defaults test + tcp-request session silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +` const defaults_tcprequestsessionattachsrvsrv1 = ` defaults test tcp-request session attach-srv srv1 diff --git a/config-parser/tests/integration/defaults_test.go b/config-parser/tests/integration/defaults_test.go index 7ab1ddeb..7e818a65 100644 --- a/config-parser/tests/integration/defaults_test.go +++ b/config-parser/tests/integration/defaults_test.go @@ -506,6 +506,8 @@ func TestWholeConfigsSectionsDefaults(t *testing.T) { {"defaults_httprequestsetvarreqmyvarreqfhdr", defaults_httprequestsetvarreqmyvarreqfhdr}, {"defaults_httprequestsilentdrop", defaults_httprequestsilentdrop}, {"defaults_httprequestsilentdropifFALSE", defaults_httprequestsilentdropifFALSE}, + {"defaults_httprequestsilentdroprstttl1", defaults_httprequestsilentdroprstttl1}, + {"defaults_httprequestsilentdroprstttl1ifsr", defaults_httprequestsilentdroprstttl1ifsr}, {"defaults_httprequeststrictmodeon", defaults_httprequeststrictmodeon}, {"defaults_httprequeststrictmodeonifFALSE", defaults_httprequeststrictmodeonifFALSE}, {"defaults_httprequesttarpit", defaults_httprequesttarpit}, @@ -622,6 +624,8 @@ func TestWholeConfigsSectionsDefaults(t *testing.T) { {"defaults_httpresponsesetvarreqmyvarresfhd", defaults_httpresponsesetvarreqmyvarresfhd}, {"defaults_httpresponsesilentdrop", defaults_httpresponsesilentdrop}, {"defaults_httpresponsesilentdropifFALSE", defaults_httpresponsesilentdropifFALSE}, + {"defaults_httpresponsesilentdroprstttl1", defaults_httpresponsesilentdroprstttl1}, + {"defaults_httpresponsesilentdroprstttl1ifs", defaults_httpresponsesilentdroprstttl1ifs}, {"defaults_httpresponsestrictmodeon", defaults_httpresponsestrictmodeon}, {"defaults_httpresponsestrictmodeonifFALSE", defaults_httpresponsestrictmodeonifFALSE}, {"defaults_httpresponsetracksc0src", defaults_httpresponsetracksc0src}, @@ -772,6 +776,8 @@ func TestWholeConfigsSectionsDefaults(t *testing.T) { {"defaults_tcprequestconnectionsetvarfmttxn", defaults_tcprequestconnectionsetvarfmttxn}, {"defaults_tcprequestconnectionsilentdrop", defaults_tcprequestconnectionsilentdrop}, {"defaults_tcprequestconnectionsilentdropif", defaults_tcprequestconnectionsilentdropif}, + {"defaults_tcprequestconnectionsilentdroprs", defaults_tcprequestconnectionsilentdroprs}, + {"defaults_tcprequestconnectionsilentdroprs_", defaults_tcprequestconnectionsilentdroprs_}, {"defaults_tcprequestconnectiontracksc0src", defaults_tcprequestconnectiontracksc0src}, {"defaults_tcprequestconnectiontracksc0srci", defaults_tcprequestconnectiontracksc0srci}, {"defaults_tcprequestconnectiontracksc0srct", defaults_tcprequestconnectiontracksc0srct}, @@ -840,6 +846,8 @@ func TestWholeConfigsSectionsDefaults(t *testing.T) { {"defaults_tcprequestcontentsetvarsesssrcsr", defaults_tcprequestcontentsetvarsesssrcsr}, {"defaults_tcprequestcontentsilentdrop", defaults_tcprequestcontentsilentdrop}, {"defaults_tcprequestcontentsilentdropifHTT", defaults_tcprequestcontentsilentdropifHTT}, + {"defaults_tcprequestcontentsilentdroprsttt", defaults_tcprequestcontentsilentdroprsttt}, + {"defaults_tcprequestcontentsilentdroprsttt_", defaults_tcprequestcontentsilentdroprsttt_}, {"defaults_tcprequestcontentswitchmodehttp", defaults_tcprequestcontentswitchmodehttp}, {"defaults_tcprequestcontentswitchmodehttpi", defaults_tcprequestcontentswitchmodehttpi}, {"defaults_tcprequestcontentswitchmodehttpp", defaults_tcprequestcontentswitchmodehttpp}, @@ -889,6 +897,8 @@ func TestWholeConfigsSectionsDefaults(t *testing.T) { {"defaults_tcprequestsessionsetvarsesssrcsr", defaults_tcprequestsessionsetvarsesssrcsr}, {"defaults_tcprequestsessionsilentdrop", defaults_tcprequestsessionsilentdrop}, {"defaults_tcprequestsessionsilentdropifHTT", defaults_tcprequestsessionsilentdropifHTT}, + {"defaults_tcprequestsessionsilentdroprsttt", defaults_tcprequestsessionsilentdroprsttt}, + {"defaults_tcprequestsessionsilentdroprsttt_", defaults_tcprequestsessionsilentdroprsttt_}, {"defaults_tcprequestsessiontracksc0src", defaults_tcprequestsessiontracksc0src}, {"defaults_tcprequestsessiontracksc0srcifso", defaults_tcprequestsessiontracksc0srcifso}, {"defaults_tcprequestsessiontracksc0srctabl", defaults_tcprequestsessiontracksc0srctabl}, @@ -919,7 +929,7 @@ func TestWholeConfigsSectionsDefaults(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -929,7 +939,7 @@ func TestWholeConfigsSectionsDefaults(t *testing.T) { t.Error("======== RESULT ===========") t.Error(result) t.Error("===========================") - t.Fatalf("configurations does not match") + t.Fatal("configurations does not match") } }) } diff --git a/config-parser/tests/integration/fcgi-app_test.go b/config-parser/tests/integration/fcgi-app_test.go index 53a8970a..3b79533c 100644 --- a/config-parser/tests/integration/fcgi-app_test.go +++ b/config-parser/tests/integration/fcgi-app_test.go @@ -30,6 +30,17 @@ func TestWholeConfigsSectionsFcgiapp(t *testing.T) { tests := []struct { Name, Config string }{ + {"fcgiapp_logstderr1270011515len8192format", fcgiapp_logstderr1270011515len8192format}, + {"fcgiapp_logstderr1270011515len8192format_", fcgiapp_logstderr1270011515len8192format_}, + {"fcgiapp_logstderr1270011515local2", fcgiapp_logstderr1270011515local2}, + {"fcgiapp_logstderrglobal", fcgiapp_logstderrglobal}, + {"fcgiapp_optionmaxreqs1024", fcgiapp_optionmaxreqs1024}, + {"fcgiapp_passheaderxheader", fcgiapp_passheaderxheader}, + {"fcgiapp_passheaderxheaderifacl", fcgiapp_passheaderxheaderifacl}, + {"fcgiapp_passheaderxheaderunlessacl", fcgiapp_passheaderxheaderunlessacl}, + {"fcgiapp_setparamnamefmt", fcgiapp_setparamnamefmt}, + {"fcgiapp_setparamnamefmtifacl", fcgiapp_setparamnamefmtifacl}, + {"fcgiapp_setparamnamefmtunlessacl", fcgiapp_setparamnamefmtunlessacl}, } for _, config := range tests { t.Run(config.Name, func(t *testing.T) { @@ -38,7 +49,7 @@ func TestWholeConfigsSectionsFcgiapp(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -48,7 +59,7 @@ func TestWholeConfigsSectionsFcgiapp(t *testing.T) { t.Error("======== RESULT ===========") t.Error(result) t.Error("===========================") - t.Fatalf("configurations does not match") + t.Fatal("configurations does not match") } }) } diff --git a/config-parser/tests/integration/frontend_data_test.go b/config-parser/tests/integration/frontend_data_test.go index d5b7032d..a035ea10 100644 --- a/config-parser/tests/integration/frontend_data_test.go +++ b/config-parser/tests/integration/frontend_data_test.go @@ -1341,6 +1341,14 @@ const frontend_httprequestsilentdropifFALSE = ` frontend test http-request silent-drop if FALSE ` +const frontend_httprequestsilentdroprstttl1 = ` +frontend test + http-request silent-drop rst-ttl 1 +` +const frontend_httprequestsilentdroprstttl1ifsr = ` +frontend test + http-request silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +` const frontend_httprequeststrictmodeon = ` frontend test http-request strict-mode on @@ -1577,6 +1585,10 @@ const frontend_httprequestcapturereqcookcntFirs = ` frontend test http-request capture req.cook_cnt(FirstVisit),bool len 10 ` +const frontend_httprequestcapturestrDNSresoluti = ` +frontend test + http-request capture str("DNS resolution failure") len 32 unless dns_successful +` const frontend_httprequestaddheaderAuthorizatio = ` frontend test http-request add-header Authorization Basic\ eC1oYXByb3h5LXJlY3J1aXRzOlBlb3BsZSB3aG8gZGVjb2RlIG1lc3NhZ2VzIG9mdGVuIGxvdmUgd29ya2luZyBhdCBIQVByb3h5LiBEbyBub3QgYmUgc2h5LCBjb250YWN0IHVz @@ -1901,6 +1913,14 @@ const frontend_httpresponsesilentdropifFALSE = ` frontend test http-response silent-drop if FALSE ` +const frontend_httpresponsesilentdroprstttl1 = ` +frontend test + http-response silent-drop rst-ttl 1 +` +const frontend_httpresponsesilentdroprstttl1ifs = ` +frontend test + http-response silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +` const frontend_httpresponseunsetvarreqmyvar = ` frontend test http-response unset-var(req.my_var) @@ -2461,6 +2481,14 @@ const frontend_tcprequestcontentsilentdropifHTT = ` frontend test tcp-request content silent-drop if !HTTP ` +const frontend_tcprequestcontentsilentdroprsttt = ` +frontend test + tcp-request content silent-drop rst-ttl 1 +` +const frontend_tcprequestcontentsilentdroprsttt_ = ` +frontend test + tcp-request content silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +` const frontend_tcprequestcontentsendspoegroupen = ` frontend test tcp-request content send-spoe-group engine group @@ -2649,6 +2677,14 @@ const frontend_tcprequestconnectionsilentdropif = ` frontend test tcp-request connection silent-drop if !HTTP ` +const frontend_tcprequestconnectionsilentdroprs = ` +frontend test + tcp-request connection silent-drop rst-ttl 1 +` +const frontend_tcprequestconnectionsilentdroprs_ = ` +frontend test + tcp-request connection silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +` const frontend_tcprequestconnectionluafoo = ` frontend test tcp-request connection lua.foo @@ -2817,6 +2853,14 @@ const frontend_tcprequestsessionsilentdropifHTT = ` frontend test tcp-request session silent-drop if !HTTP ` +const frontend_tcprequestsessionsilentdroprsttt = ` +frontend test + tcp-request session silent-drop rst-ttl 1 +` +const frontend_tcprequestsessionsilentdroprsttt_ = ` +frontend test + tcp-request session silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +` const frontend_tcprequestsessionattachsrvsrv1 = ` frontend test tcp-request session attach-srv srv1 @@ -2957,6 +3001,10 @@ const frontend_tcprequestcontentsetfctos100 = ` frontend test tcp-request content set-fc-tos 100 ` +const frontend_tcprequestcontentcapturestrDNSre = ` +frontend test + tcp-request content capture str("DNS resolution failure") len 32 unless dns_successful +` const frontend_tcpresponsecontentluafoo = ` frontend test tcp-response content lua.foo diff --git a/config-parser/tests/integration/frontend_test.go b/config-parser/tests/integration/frontend_test.go index 77bd1194..5a629f68 100644 --- a/config-parser/tests/integration/frontend_test.go +++ b/config-parser/tests/integration/frontend_test.go @@ -259,6 +259,7 @@ func TestWholeConfigsSectionsFrontend(t *testing.T) { {"frontend_httprequestcacheusecachename", frontend_httprequestcacheusecachename}, {"frontend_httprequestcacheusecachenameifFA", frontend_httprequestcacheusecachenameifFA}, {"frontend_httprequestcapturereqcookcntFirs", frontend_httprequestcapturereqcookcntFirs}, + {"frontend_httprequestcapturestrDNSresoluti", frontend_httprequestcapturestrDNSresoluti}, {"frontend_httprequestdelaclmaplstsrc", frontend_httprequestdelaclmaplstsrc}, {"frontend_httprequestdelheaderXvalue", frontend_httprequestdelheaderXvalue}, {"frontend_httprequestdelheaderXvalueifTRUE", frontend_httprequestdelheaderXvalueifTRUE}, @@ -405,6 +406,8 @@ func TestWholeConfigsSectionsFrontend(t *testing.T) { {"frontend_httprequestsetvarreqmyvarreqfhdr", frontend_httprequestsetvarreqmyvarreqfhdr}, {"frontend_httprequestsilentdrop", frontend_httprequestsilentdrop}, {"frontend_httprequestsilentdropifFALSE", frontend_httprequestsilentdropifFALSE}, + {"frontend_httprequestsilentdroprstttl1", frontend_httprequestsilentdroprstttl1}, + {"frontend_httprequestsilentdroprstttl1ifsr", frontend_httprequestsilentdroprstttl1ifsr}, {"frontend_httprequeststrictmodeon", frontend_httprequeststrictmodeon}, {"frontend_httprequeststrictmodeonifFALSE", frontend_httprequeststrictmodeonifFALSE}, {"frontend_httprequesttarpit", frontend_httprequesttarpit}, @@ -522,6 +525,8 @@ func TestWholeConfigsSectionsFrontend(t *testing.T) { {"frontend_httpresponsesetvarreqmyvarresfhd", frontend_httpresponsesetvarreqmyvarresfhd}, {"frontend_httpresponsesilentdrop", frontend_httpresponsesilentdrop}, {"frontend_httpresponsesilentdropifFALSE", frontend_httpresponsesilentdropifFALSE}, + {"frontend_httpresponsesilentdroprstttl1", frontend_httpresponsesilentdroprstttl1}, + {"frontend_httpresponsesilentdroprstttl1ifs", frontend_httpresponsesilentdroprstttl1ifs}, {"frontend_httpresponsestrictmodeon", frontend_httpresponsestrictmodeon}, {"frontend_httpresponsestrictmodeonifFALSE", frontend_httpresponsestrictmodeonifFALSE}, {"frontend_httpresponsetracksc0src", frontend_httpresponsetracksc0src}, @@ -643,6 +648,8 @@ func TestWholeConfigsSectionsFrontend(t *testing.T) { {"frontend_tcprequestconnectionsetvarfmttxn", frontend_tcprequestconnectionsetvarfmttxn}, {"frontend_tcprequestconnectionsilentdrop", frontend_tcprequestconnectionsilentdrop}, {"frontend_tcprequestconnectionsilentdropif", frontend_tcprequestconnectionsilentdropif}, + {"frontend_tcprequestconnectionsilentdroprs", frontend_tcprequestconnectionsilentdroprs}, + {"frontend_tcprequestconnectionsilentdroprs_", frontend_tcprequestconnectionsilentdroprs_}, {"frontend_tcprequestconnectiontracksc0src", frontend_tcprequestconnectiontracksc0src}, {"frontend_tcprequestconnectiontracksc0srci", frontend_tcprequestconnectiontracksc0srci}, {"frontend_tcprequestconnectiontracksc0srct", frontend_tcprequestconnectiontracksc0srct}, @@ -663,6 +670,7 @@ func TestWholeConfigsSectionsFrontend(t *testing.T) { {"frontend_tcprequestcontentacceptifHTTP", frontend_tcprequestcontentacceptifHTTP}, {"frontend_tcprequestcontentcapturereqpaylo", frontend_tcprequestcontentcapturereqpaylo}, {"frontend_tcprequestcontentcapturereqpaylo_", frontend_tcprequestcontentcapturereqpaylo_}, + {"frontend_tcprequestcontentcapturestrDNSre", frontend_tcprequestcontentcapturestrDNSre}, {"frontend_tcprequestcontentdoresolvetxnmyi", frontend_tcprequestcontentdoresolvetxnmyi}, {"frontend_tcprequestcontentdoresolvetxnmyi_", frontend_tcprequestcontentdoresolvetxnmyi_}, {"frontend_tcprequestcontentluafoo", frontend_tcprequestcontentluafoo}, @@ -711,6 +719,8 @@ func TestWholeConfigsSectionsFrontend(t *testing.T) { {"frontend_tcprequestcontentsetvarsesssrcsr", frontend_tcprequestcontentsetvarsesssrcsr}, {"frontend_tcprequestcontentsilentdrop", frontend_tcprequestcontentsilentdrop}, {"frontend_tcprequestcontentsilentdropifHTT", frontend_tcprequestcontentsilentdropifHTT}, + {"frontend_tcprequestcontentsilentdroprsttt", frontend_tcprequestcontentsilentdroprsttt}, + {"frontend_tcprequestcontentsilentdroprsttt_", frontend_tcprequestcontentsilentdroprsttt_}, {"frontend_tcprequestcontentswitchmodehttp", frontend_tcprequestcontentswitchmodehttp}, {"frontend_tcprequestcontentswitchmodehttpi", frontend_tcprequestcontentswitchmodehttpi}, {"frontend_tcprequestcontentswitchmodehttpp", frontend_tcprequestcontentswitchmodehttpp}, @@ -760,6 +770,8 @@ func TestWholeConfigsSectionsFrontend(t *testing.T) { {"frontend_tcprequestsessionsetvarsesssrcsr", frontend_tcprequestsessionsetvarsesssrcsr}, {"frontend_tcprequestsessionsilentdrop", frontend_tcprequestsessionsilentdrop}, {"frontend_tcprequestsessionsilentdropifHTT", frontend_tcprequestsessionsilentdropifHTT}, + {"frontend_tcprequestsessionsilentdroprsttt", frontend_tcprequestsessionsilentdroprsttt}, + {"frontend_tcprequestsessionsilentdroprsttt_", frontend_tcprequestsessionsilentdroprsttt_}, {"frontend_tcprequestsessiontracksc0src", frontend_tcprequestsessiontracksc0src}, {"frontend_tcprequestsessiontracksc0srcifso", frontend_tcprequestsessiontracksc0srcifso}, {"frontend_tcprequestsessiontracksc0srctabl", frontend_tcprequestsessiontracksc0srctabl}, @@ -820,7 +832,7 @@ func TestWholeConfigsSectionsFrontend(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -830,7 +842,7 @@ func TestWholeConfigsSectionsFrontend(t *testing.T) { t.Error("======== RESULT ===========") t.Error(result) t.Error("===========================") - t.Fatalf("configurations does not match") + t.Fatal("configurations does not match") } }) } diff --git a/config-parser/tests/integration/global_test.go b/config-parser/tests/integration/global_test.go index 50c6a8d6..15d3bdaf 100644 --- a/config-parser/tests/integration/global_test.go +++ b/config-parser/tests/integration/global_test.go @@ -88,7 +88,7 @@ func TestWholeConfigsSectionsGlobal(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -98,7 +98,7 @@ func TestWholeConfigsSectionsGlobal(t *testing.T) { t.Error("======== RESULT ===========") t.Error(result) t.Error("===========================") - t.Fatalf("configurations does not match") + t.Fatal("configurations does not match") } }) } diff --git a/config-parser/tests/integration/log-forward_test.go b/config-parser/tests/integration/log-forward_test.go index 616043ba..54ac5737 100644 --- a/config-parser/tests/integration/log-forward_test.go +++ b/config-parser/tests/integration/log-forward_test.go @@ -30,6 +30,13 @@ func TestWholeConfigsSectionsLogforward(t *testing.T) { tests := []struct { Name, Config string }{ + {"logforward_dgrambind10001100801000110443", logforward_dgrambind10001100801000110443}, + {"logforward_dgrambind443interfaceeth0", logforward_dgrambind443interfaceeth0}, + {"logforward_dgrambind443interfaceeth1", logforward_dgrambind443interfaceeth1}, + {"logforward_dgrambind443interfacepppoewan", logforward_dgrambind443interfacepppoewan}, + {"logforward_dgrambind443namespaceexample", logforward_dgrambind443namespaceexample}, + {"logforward_dgrambind443transparent", logforward_dgrambind443transparent}, + {"logforward_dgrambind80443", logforward_dgrambind80443}, } for _, config := range tests { t.Run(config.Name, func(t *testing.T) { @@ -38,7 +45,7 @@ func TestWholeConfigsSectionsLogforward(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -48,7 +55,7 @@ func TestWholeConfigsSectionsLogforward(t *testing.T) { t.Error("======== RESULT ===========") t.Error(result) t.Error("===========================") - t.Fatalf("configurations does not match") + t.Fatal("configurations does not match") } }) } diff --git a/config-parser/tests/integration/mailers_test.go b/config-parser/tests/integration/mailers_test.go index 29644568..deffc2a9 100644 --- a/config-parser/tests/integration/mailers_test.go +++ b/config-parser/tests/integration/mailers_test.go @@ -40,7 +40,7 @@ func TestWholeConfigsSectionsMailers(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -50,7 +50,7 @@ func TestWholeConfigsSectionsMailers(t *testing.T) { t.Error("======== RESULT ===========") t.Error(result) t.Error("===========================") - t.Fatalf("configurations does not match") + t.Fatal("configurations does not match") } }) } diff --git a/config-parser/tests/integration/peers_test.go b/config-parser/tests/integration/peers_test.go index f73621d6..448405b5 100644 --- a/config-parser/tests/integration/peers_test.go +++ b/config-parser/tests/integration/peers_test.go @@ -188,7 +188,7 @@ func TestWholeConfigsSectionsPeers(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -198,7 +198,7 @@ func TestWholeConfigsSectionsPeers(t *testing.T) { t.Error("======== RESULT ===========") t.Error(result) t.Error("===========================") - t.Fatalf("configurations does not match") + t.Fatal("configurations does not match") } }) } diff --git a/config-parser/tests/integration/program_test.go b/config-parser/tests/integration/program_test.go index f6c87622..349f609b 100644 --- a/config-parser/tests/integration/program_test.go +++ b/config-parser/tests/integration/program_test.go @@ -40,7 +40,7 @@ func TestWholeConfigsSectionsProgram(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -50,7 +50,7 @@ func TestWholeConfigsSectionsProgram(t *testing.T) { t.Error("======== RESULT ===========") t.Error(result) t.Error("===========================") - t.Fatalf("configurations does not match") + t.Fatal("configurations does not match") } }) } diff --git a/config-parser/tests/integration/resolvers_test.go b/config-parser/tests/integration/resolvers_test.go index c2c1a9d1..c17249d3 100644 --- a/config-parser/tests/integration/resolvers_test.go +++ b/config-parser/tests/integration/resolvers_test.go @@ -40,7 +40,7 @@ func TestWholeConfigsSectionsResolvers(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -50,7 +50,7 @@ func TestWholeConfigsSectionsResolvers(t *testing.T) { t.Error("======== RESULT ===========") t.Error(result) t.Error("===========================") - t.Fatalf("configurations does not match") + t.Fatal("configurations does not match") } }) } diff --git a/config-parser/tests/integration/userlist_test.go b/config-parser/tests/integration/userlist_test.go index 2fadc5b0..171ed5d1 100644 --- a/config-parser/tests/integration/userlist_test.go +++ b/config-parser/tests/integration/userlist_test.go @@ -44,7 +44,7 @@ func TestWholeConfigsSectionsUserlist(t *testing.T) { buffer.WriteString(config.Config) p, err := parser.New(options.Reader(&buffer)) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } result := p.String() if result != config.Config { @@ -54,7 +54,7 @@ func TestWholeConfigsSectionsUserlist(t *testing.T) { t.Error("======== RESULT ===========") t.Error(result) t.Error("===========================") - t.Fatalf("configurations does not match") + t.Fatal("configurations does not match") } }) } diff --git a/config-parser/tests/load-server-state-from-file_generated_test.go b/config-parser/tests/load-server-state-from-file_generated_test.go index de5e4322..a20cc90e 100644 --- a/config-parser/tests/load-server-state-from-file_generated_test.go +++ b/config-parser/tests/load-server-state-from-file_generated_test.go @@ -55,12 +55,12 @@ func TestLoadServerStateFromFile(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -70,15 +70,15 @@ func TestLoadServerStateFromFile(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/load_generated_test.go b/config-parser/tests/load_generated_test.go index f9132bf5..2b07154e 100644 --- a/config-parser/tests/load_generated_test.go +++ b/config-parser/tests/load_generated_test.go @@ -59,12 +59,12 @@ func TestLoadCert(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -74,15 +74,15 @@ func TestLoadCert(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/log-send-hostname_generated_test.go b/config-parser/tests/log-send-hostname_generated_test.go index 41aa8294..8a4f8793 100644 --- a/config-parser/tests/log-send-hostname_generated_test.go +++ b/config-parser/tests/log-send-hostname_generated_test.go @@ -51,12 +51,12 @@ func TestLogSendHostName(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestLogSendHostName(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/log-stderr_generated_test.go b/config-parser/tests/log-stderr_generated_test.go index f1b6a541..b8e9677f 100644 --- a/config-parser/tests/log-stderr_generated_test.go +++ b/config-parser/tests/log-stderr_generated_test.go @@ -58,12 +58,12 @@ func TestLogStdErr(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -73,15 +73,15 @@ func TestLogStdErr(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/log_generated_test.go b/config-parser/tests/log_generated_test.go index 9fb46bac..d1252513 100644 --- a/config-parser/tests/log_generated_test.go +++ b/config-parser/tests/log_generated_test.go @@ -69,12 +69,12 @@ func TestLog(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -84,15 +84,15 @@ func TestLog(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/lua-load_generated_test.go b/config-parser/tests/lua-load_generated_test.go index 1c2a0ec7..e876628d 100644 --- a/config-parser/tests/lua-load_generated_test.go +++ b/config-parser/tests/lua-load_generated_test.go @@ -51,12 +51,12 @@ func TestLuaLoad(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestLuaLoad(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/lua-prepend-path_generated_test.go b/config-parser/tests/lua-prepend-path_generated_test.go index 5429c82a..a393464b 100644 --- a/config-parser/tests/lua-prepend-path_generated_test.go +++ b/config-parser/tests/lua-prepend-path_generated_test.go @@ -52,12 +52,12 @@ func TestLuaPrependPath(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -67,15 +67,15 @@ func TestLuaPrependPath(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/mailer_generated_test.go b/config-parser/tests/mailer_generated_test.go index 70db51f0..c3048fe1 100644 --- a/config-parser/tests/mailer_generated_test.go +++ b/config-parser/tests/mailer_generated_test.go @@ -53,12 +53,12 @@ func TestMailer(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestMailer(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/master-worker_generated_test.go b/config-parser/tests/master-worker_generated_test.go index 0ccf3989..69744bec 100644 --- a/config-parser/tests/master-worker_generated_test.go +++ b/config-parser/tests/master-worker_generated_test.go @@ -51,12 +51,12 @@ func TestMasterWorker(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestMasterWorker(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/maxconn_generated_test.go b/config-parser/tests/maxconn_generated_test.go index bfa7db26..896f5681 100644 --- a/config-parser/tests/maxconn_generated_test.go +++ b/config-parser/tests/maxconn_generated_test.go @@ -52,12 +52,12 @@ func TestMaxConn(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -67,15 +67,15 @@ func TestMaxConn(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/mode_generated_test.go b/config-parser/tests/mode_generated_test.go index 25266150..94bca7bf 100644 --- a/config-parser/tests/mode_generated_test.go +++ b/config-parser/tests/mode_generated_test.go @@ -53,12 +53,12 @@ func TestMode(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestMode(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/monitor-fail_generated_test.go b/config-parser/tests/monitor-fail_generated_test.go index 565aad36..c8969112 100644 --- a/config-parser/tests/monitor-fail_generated_test.go +++ b/config-parser/tests/monitor-fail_generated_test.go @@ -56,12 +56,12 @@ func TestMonitorFail(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -71,15 +71,15 @@ func TestMonitorFail(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/monitor-uri_generated_test.go b/config-parser/tests/monitor-uri_generated_test.go index b875ff9a..24c4be0c 100644 --- a/config-parser/tests/monitor-uri_generated_test.go +++ b/config-parser/tests/monitor-uri_generated_test.go @@ -51,12 +51,12 @@ func TestMonitorURI(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestMonitorURI(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/nameserver_generated_test.go b/config-parser/tests/nameserver_generated_test.go index 225bd48c..1f90f37c 100644 --- a/config-parser/tests/nameserver_generated_test.go +++ b/config-parser/tests/nameserver_generated_test.go @@ -52,12 +52,12 @@ func TestNameserver(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -67,15 +67,15 @@ func TestNameserver(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/nbproc_generated_test.go b/config-parser/tests/nbproc_generated_test.go index 80f4f616..950ca3dc 100644 --- a/config-parser/tests/nbproc_generated_test.go +++ b/config-parser/tests/nbproc_generated_test.go @@ -52,12 +52,12 @@ func TestNbProc(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -67,15 +67,15 @@ func TestNbProc(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/nbthread_generated_test.go b/config-parser/tests/nbthread_generated_test.go index 9ee5991f..2d0de036 100644 --- a/config-parser/tests/nbthread_generated_test.go +++ b/config-parser/tests/nbthread_generated_test.go @@ -52,12 +52,12 @@ func TestNbThread(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -67,15 +67,15 @@ func TestNbThread(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/nosplice_generated_test.go b/config-parser/tests/nosplice_generated_test.go index 559905c7..bf7517c5 100644 --- a/config-parser/tests/nosplice_generated_test.go +++ b/config-parser/tests/nosplice_generated_test.go @@ -51,12 +51,12 @@ func TestNoSplice(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestNoSplice(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/numa-cpu-mapping_generated_test.go b/config-parser/tests/numa-cpu-mapping_generated_test.go index 8bbb1793..521c943f 100644 --- a/config-parser/tests/numa-cpu-mapping_generated_test.go +++ b/config-parser/tests/numa-cpu-mapping_generated_test.go @@ -51,12 +51,12 @@ func TestNumaCPUMapping(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestNumaCPUMapping(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/option-forwardfor_generated_test.go b/config-parser/tests/option-forwardfor_generated_test.go index ea9c1f95..89887f7c 100644 --- a/config-parser/tests/option-forwardfor_generated_test.go +++ b/config-parser/tests/option-forwardfor_generated_test.go @@ -58,12 +58,12 @@ func TestOptionForwardFor(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -73,15 +73,15 @@ func TestOptionForwardFor(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/option-http-restrict-req-hdr-names_generated_test.go b/config-parser/tests/option-http-restrict-req-hdr-names_generated_test.go index dda797a3..21fbd123 100644 --- a/config-parser/tests/option-http-restrict-req-hdr-names_generated_test.go +++ b/config-parser/tests/option-http-restrict-req-hdr-names_generated_test.go @@ -53,12 +53,12 @@ func TestOptionHTTPRestrictReqHdrNames(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestOptionHTTPRestrictReqHdrNames(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/option-httpchk_generated_test.go b/config-parser/tests/option-httpchk_generated_test.go index 7595cf22..7659ac2a 100644 --- a/config-parser/tests/option-httpchk_generated_test.go +++ b/config-parser/tests/option-httpchk_generated_test.go @@ -53,12 +53,12 @@ func TestOptionHttpchk(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestOptionHttpchk(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/option-httplog_generated_test.go b/config-parser/tests/option-httplog_generated_test.go index 50c9b0e0..3690edf6 100644 --- a/config-parser/tests/option-httplog_generated_test.go +++ b/config-parser/tests/option-httplog_generated_test.go @@ -54,12 +54,12 @@ func TestOptionHTTPLog(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -69,15 +69,15 @@ func TestOptionHTTPLog(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/option-max-reqs_generated_test.go b/config-parser/tests/option-max-reqs_generated_test.go index 1ffddd5b..9997dcbf 100644 --- a/config-parser/tests/option-max-reqs_generated_test.go +++ b/config-parser/tests/option-max-reqs_generated_test.go @@ -51,12 +51,12 @@ func TestOptionMaxReqs(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestOptionMaxReqs(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/option-mysql-check_generated_test.go b/config-parser/tests/option-mysql-check_generated_test.go index 90d62371..db6ae342 100644 --- a/config-parser/tests/option-mysql-check_generated_test.go +++ b/config-parser/tests/option-mysql-check_generated_test.go @@ -57,12 +57,12 @@ func TestOptionMysqlCheck(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -72,15 +72,15 @@ func TestOptionMysqlCheck(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/option-originalto_generated_test.go b/config-parser/tests/option-originalto_generated_test.go index c53caefb..ed4cc5c3 100644 --- a/config-parser/tests/option-originalto_generated_test.go +++ b/config-parser/tests/option-originalto_generated_test.go @@ -59,12 +59,12 @@ func TestOptionOriginalTo(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -74,15 +74,15 @@ func TestOptionOriginalTo(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/option-pgsql-check_generated_test.go b/config-parser/tests/option-pgsql-check_generated_test.go index 3631f792..30b4afd6 100644 --- a/config-parser/tests/option-pgsql-check_generated_test.go +++ b/config-parser/tests/option-pgsql-check_generated_test.go @@ -55,12 +55,12 @@ func TestOptionPgsqlCheck(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -70,15 +70,15 @@ func TestOptionPgsqlCheck(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/option-pgsql-check_regression_test.go b/config-parser/tests/option-pgsql-check_regression_test.go index d2d8af5d..e251df04 100644 --- a/config-parser/tests/option-pgsql-check_regression_test.go +++ b/config-parser/tests/option-pgsql-check_regression_test.go @@ -38,13 +38,13 @@ func TestOptionPgsqlCheckRegression(t *testing.T) { err := ProcessLine(line, parser) if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } @@ -56,7 +56,7 @@ func TestOptionPgsqlCheckRegression(t *testing.T) { } if line != actual { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", actual, expected)) + t.Errorf("error: has [%s] expects [%s]", actual, expected) } } } diff --git a/config-parser/tests/option-redispatch_generated_test.go b/config-parser/tests/option-redispatch_generated_test.go index 70a851de..04d2a0f6 100644 --- a/config-parser/tests/option-redispatch_generated_test.go +++ b/config-parser/tests/option-redispatch_generated_test.go @@ -54,12 +54,12 @@ func TestOptionRedispatch(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -69,15 +69,15 @@ func TestOptionRedispatch(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/option-smtpchk_generated_test.go b/config-parser/tests/option-smtpchk_generated_test.go index 9a6ea4c7..aa7b542d 100644 --- a/config-parser/tests/option-smtpchk_generated_test.go +++ b/config-parser/tests/option-smtpchk_generated_test.go @@ -55,12 +55,12 @@ func TestOptionSmtpchk(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -70,15 +70,15 @@ func TestOptionSmtpchk(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/pass-header_generated_test.go b/config-parser/tests/pass-header_generated_test.go index 0a63f850..98d7ef7c 100644 --- a/config-parser/tests/pass-header_generated_test.go +++ b/config-parser/tests/pass-header_generated_test.go @@ -55,12 +55,12 @@ func TestPassHeader(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -70,15 +70,15 @@ func TestPassHeader(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/peer_generated_test.go b/config-parser/tests/peer_generated_test.go index 76cda0da..07bd2aa8 100644 --- a/config-parser/tests/peer_generated_test.go +++ b/config-parser/tests/peer_generated_test.go @@ -55,12 +55,12 @@ func TestPeer(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -70,15 +70,15 @@ func TestPeer(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/persist_generated_test.go b/config-parser/tests/persist_generated_test.go index ed9b7986..11be79b2 100644 --- a/config-parser/tests/persist_generated_test.go +++ b/config-parser/tests/persist_generated_test.go @@ -55,12 +55,12 @@ func TestPersist(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -70,15 +70,15 @@ func TestPersist(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/process-vary_generated_test.go b/config-parser/tests/process-vary_generated_test.go index bfcb6faf..7fbafb68 100644 --- a/config-parser/tests/process-vary_generated_test.go +++ b/config-parser/tests/process-vary_generated_test.go @@ -54,12 +54,12 @@ func TestProcessVary(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -69,15 +69,15 @@ func TestProcessVary(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/redirect_generated_test.go b/config-parser/tests/redirect_generated_test.go index 4908ce7c..5808197a 100644 --- a/config-parser/tests/redirect_generated_test.go +++ b/config-parser/tests/redirect_generated_test.go @@ -51,12 +51,12 @@ func TestRedirecthttp(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestRedirecthttp(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/redirect_test.go b/config-parser/tests/redirect_test.go index f637bf41..a383e774 100644 --- a/config-parser/tests/redirect_test.go +++ b/config-parser/tests/redirect_test.go @@ -48,12 +48,12 @@ func TestRedirect(t *testing.T) { parser.Init() err := ProcessLine(line, parser) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) } var actual string @@ -65,7 +65,7 @@ func TestRedirect(t *testing.T) { } if expected != actual { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", actual, expected)) + t.Errorf("error: has [%s] expects [%s]", actual, expected) } } } diff --git a/config-parser/tests/section_generated_test.go b/config-parser/tests/section_generated_test.go index 8a40b57b..a605b1ad 100644 --- a/config-parser/tests/section_generated_test.go +++ b/config-parser/tests/section_generated_test.go @@ -49,12 +49,12 @@ func TestSectionextra(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestSectionextra(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/server-template_generated_test.go b/config-parser/tests/server-template_generated_test.go index 63fbbc13..6e9704be 100644 --- a/config-parser/tests/server-template_generated_test.go +++ b/config-parser/tests/server-template_generated_test.go @@ -57,12 +57,12 @@ func TestServerTemplate(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -72,15 +72,15 @@ func TestServerTemplate(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/server_generated_test.go b/config-parser/tests/server_generated_test.go index ed199813..b93c094d 100644 --- a/config-parser/tests/server_generated_test.go +++ b/config-parser/tests/server_generated_test.go @@ -198,12 +198,12 @@ func TestServer(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -213,15 +213,15 @@ func TestServer(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/set-param_generated_test.go b/config-parser/tests/set-param_generated_test.go index abe653e5..94b9284d 100644 --- a/config-parser/tests/set-param_generated_test.go +++ b/config-parser/tests/set-param_generated_test.go @@ -55,12 +55,12 @@ func TestSetParam(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -70,15 +70,15 @@ func TestSetParam(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/set-var-fmt_generated_test.go b/config-parser/tests/set-var-fmt_generated_test.go index b6de0c6a..54f66504 100644 --- a/config-parser/tests/set-var-fmt_generated_test.go +++ b/config-parser/tests/set-var-fmt_generated_test.go @@ -53,12 +53,12 @@ func TestSetVarFmt(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestSetVarFmt(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/set-var_generated_test.go b/config-parser/tests/set-var_generated_test.go index edae4bac..53f3aeb1 100644 --- a/config-parser/tests/set-var_generated_test.go +++ b/config-parser/tests/set-var_generated_test.go @@ -54,12 +54,12 @@ func TestSetVar(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -69,15 +69,15 @@ func TestSetVar(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/simple-auto-on-off_generated_test.go b/config-parser/tests/simple-auto-on-off_generated_test.go index 11abb1be..9c8358bf 100644 --- a/config-parser/tests/simple-auto-on-off_generated_test.go +++ b/config-parser/tests/simple-auto-on-off_generated_test.go @@ -49,12 +49,12 @@ func TestAutoOnOffsimple(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestAutoOnOffsimple(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/simple-enabled_generated_test.go b/config-parser/tests/simple-enabled_generated_test.go index 4900dfad..69852e65 100644 --- a/config-parser/tests/simple-enabled_generated_test.go +++ b/config-parser/tests/simple-enabled_generated_test.go @@ -49,12 +49,12 @@ func TestEnabledsimple(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestEnabledsimple(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/simple-number_generated_test.go b/config-parser/tests/simple-number_generated_test.go index 37f45937..5f835a7b 100644 --- a/config-parser/tests/simple-number_generated_test.go +++ b/config-parser/tests/simple-number_generated_test.go @@ -49,12 +49,12 @@ func TestNumbersimple(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestNumbersimple(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/simple-on-off_generated_test.go b/config-parser/tests/simple-on-off_generated_test.go index ca7ac1af..004afb22 100644 --- a/config-parser/tests/simple-on-off_generated_test.go +++ b/config-parser/tests/simple-on-off_generated_test.go @@ -49,12 +49,12 @@ func TestOnOffsimple(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestOnOffsimple(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/simple-option_generated_test.go b/config-parser/tests/simple-option_generated_test.go index 84542adf..d807f661 100644 --- a/config-parser/tests/simple-option_generated_test.go +++ b/config-parser/tests/simple-option_generated_test.go @@ -49,12 +49,12 @@ func TestOptionsimple(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestOptionsimple(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/simple-size_generated_test.go b/config-parser/tests/simple-size_generated_test.go index 0f61eafe..24c2dfa1 100644 --- a/config-parser/tests/simple-size_generated_test.go +++ b/config-parser/tests/simple-size_generated_test.go @@ -49,12 +49,12 @@ func TestSizesimple(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestSizesimple(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/simple-string-kv_generated_test.go b/config-parser/tests/simple-string-kv_generated_test.go index 86869765..3ab4c613 100644 --- a/config-parser/tests/simple-string-kv_generated_test.go +++ b/config-parser/tests/simple-string-kv_generated_test.go @@ -49,12 +49,12 @@ func TestStringKeyValuesimple(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestStringKeyValuesimple(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/simple-string-slice_generated_test.go b/config-parser/tests/simple-string-slice_generated_test.go index dd5b6ca8..e8e4abdd 100644 --- a/config-parser/tests/simple-string-slice_generated_test.go +++ b/config-parser/tests/simple-string-slice_generated_test.go @@ -49,12 +49,12 @@ func TestStringSlicesimple(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestStringSlicesimple(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/simple-string_generated_test.go b/config-parser/tests/simple-string_generated_test.go index 639622d7..664af3ee 100644 --- a/config-parser/tests/simple-string_generated_test.go +++ b/config-parser/tests/simple-string_generated_test.go @@ -49,12 +49,12 @@ func TestStringsimple(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestStringsimple(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/simple-time_generated_test.go b/config-parser/tests/simple-time_generated_test.go index 5dde91b7..293e3a33 100644 --- a/config-parser/tests/simple-time_generated_test.go +++ b/config-parser/tests/simple-time_generated_test.go @@ -49,12 +49,12 @@ func TestTimesimple(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestTimesimple(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/simple-timeout_generated_test.go b/config-parser/tests/simple-timeout_generated_test.go index 787b2125..42a11c68 100644 --- a/config-parser/tests/simple-timeout_generated_test.go +++ b/config-parser/tests/simple-timeout_generated_test.go @@ -49,12 +49,12 @@ func TestTimeoutsimple(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestTimeoutsimple(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/simple-word_generated_test.go b/config-parser/tests/simple-word_generated_test.go index acd53c9d..edab4fbd 100644 --- a/config-parser/tests/simple-word_generated_test.go +++ b/config-parser/tests/simple-word_generated_test.go @@ -49,12 +49,12 @@ func TestWordsimple(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -64,15 +64,15 @@ func TestWordsimple(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/source_generated_test.go b/config-parser/tests/source_generated_test.go index 281a74bf..b6706534 100644 --- a/config-parser/tests/source_generated_test.go +++ b/config-parser/tests/source_generated_test.go @@ -63,12 +63,12 @@ func TestSource(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -78,15 +78,15 @@ func TestSource(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/ssl-engine_generated_test.go b/config-parser/tests/ssl-engine_generated_test.go index e76bad3a..1bd2a4ac 100644 --- a/config-parser/tests/ssl-engine_generated_test.go +++ b/config-parser/tests/ssl-engine_generated_test.go @@ -53,12 +53,12 @@ func TestSslEngine(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestSslEngine(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/ssl-mode-async_generated_test.go b/config-parser/tests/ssl-mode-async_generated_test.go index 2e0daee3..80d95884 100644 --- a/config-parser/tests/ssl-mode-async_generated_test.go +++ b/config-parser/tests/ssl-mode-async_generated_test.go @@ -52,12 +52,12 @@ func TestSslModeAsync(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -67,15 +67,15 @@ func TestSslModeAsync(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/stats-maxconn_generated_test.go b/config-parser/tests/stats-maxconn_generated_test.go index 53f7e131..30a65646 100644 --- a/config-parser/tests/stats-maxconn_generated_test.go +++ b/config-parser/tests/stats-maxconn_generated_test.go @@ -54,12 +54,12 @@ func TestStatsMaxconn(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -69,15 +69,15 @@ func TestStatsMaxconn(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/stats-socket_generated_test.go b/config-parser/tests/stats-socket_generated_test.go index ae0d0c11..a2388617 100644 --- a/config-parser/tests/stats-socket_generated_test.go +++ b/config-parser/tests/stats-socket_generated_test.go @@ -54,12 +54,12 @@ func TestSocket(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -69,15 +69,15 @@ func TestSocket(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/stats-timeout_generated_test.go b/config-parser/tests/stats-timeout_generated_test.go index e3187f0d..f1a663ea 100644 --- a/config-parser/tests/stats-timeout_generated_test.go +++ b/config-parser/tests/stats-timeout_generated_test.go @@ -54,12 +54,12 @@ func TestStatsTimeout(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -69,15 +69,15 @@ func TestStatsTimeout(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/stats_generated_test.go b/config-parser/tests/stats_generated_test.go index 11c8221c..0510bd35 100644 --- a/config-parser/tests/stats_generated_test.go +++ b/config-parser/tests/stats_generated_test.go @@ -88,12 +88,12 @@ func TestStatsstats(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -103,15 +103,15 @@ func TestStatsstats(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/stick-table_generated_test.go b/config-parser/tests/stick-table_generated_test.go index 6b45e440..e3c2d040 100644 --- a/config-parser/tests/stick-table_generated_test.go +++ b/config-parser/tests/stick-table_generated_test.go @@ -59,12 +59,12 @@ func TestStickTable(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -74,15 +74,15 @@ func TestStickTable(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/stick_generated_test.go b/config-parser/tests/stick_generated_test.go index 31460bc7..25b66545 100644 --- a/config-parser/tests/stick_generated_test.go +++ b/config-parser/tests/stick_generated_test.go @@ -53,12 +53,12 @@ func TestStick(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestStick(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/table_generated_test.go b/config-parser/tests/table_generated_test.go index f994fc01..4f4e67fe 100644 --- a/config-parser/tests/table_generated_test.go +++ b/config-parser/tests/table_generated_test.go @@ -62,12 +62,12 @@ func TestTable(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -77,15 +77,15 @@ func TestTable(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) @@ -107,12 +107,12 @@ func TestTable(t *testing.T) { err = ProcessLine(line, parser) } if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -122,7 +122,7 @@ func TestTable(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if expected != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, expected)) + t.Errorf("error: has [%s] expects [%s]", returnLine, expected) } }) } diff --git a/config-parser/tests/tcp-check_generated_test.go b/config-parser/tests/tcp-check_generated_test.go index 1552259b..d1cd9dce 100644 --- a/config-parser/tests/tcp-check_generated_test.go +++ b/config-parser/tests/tcp-check_generated_test.go @@ -78,12 +78,12 @@ func TestCheckstcp(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -93,15 +93,15 @@ func TestCheckstcp(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/tcp-request_generated_test.go b/config-parser/tests/tcp-request_generated_test.go index 1dc6eb57..8176d01a 100644 --- a/config-parser/tests/tcp-request_generated_test.go +++ b/config-parser/tests/tcp-request_generated_test.go @@ -27,6 +27,7 @@ import ( func TestRequeststcp(t *testing.T) { tests := map[string]bool{ + `tcp-request content capture str("DNS resolution failure") len 32 unless dns_successful`: true, "tcp-request content accept": true, "tcp-request content accept if !HTTP": true, "tcp-request content reject": true, @@ -75,147 +76,156 @@ func TestRequeststcp(t *testing.T) { "tcp-request content unset-var(sess.dn)": true, "tcp-request content silent-drop": true, "tcp-request content silent-drop if !HTTP": true, - "tcp-request content send-spoe-group engine group": true, - "tcp-request content use-service lua.deny": true, - "tcp-request content use-service lua.deny if !HTTP": true, - "tcp-request content lua.foo": true, - "tcp-request content lua.foo param if !HTTP": true, - "tcp-request content lua.foo param param1": true, - "tcp-request connection accept": true, - "tcp-request connection accept if !HTTP": true, - "tcp-request connection reject": true, - "tcp-request connection reject if !HTTP": true, - "tcp-request connection expect-proxy layer4 if { src -f proxies.lst }": true, - "tcp-request connection expect-netscaler-cip layer4": true, - "tcp-request connection expect-netscaler-cip layer4 if TRUE": true, - "tcp-request connection capture req.payload(0,6) len 6": true, - "tcp-request connection track-sc0 src": true, - "tcp-request connection track-sc0 src if some_check": true, - "tcp-request connection track-sc1 src": true, - "tcp-request connection track-sc1 src if some_check": true, - "tcp-request connection track-sc2 src": true, - "tcp-request connection track-sc2 src if some_check": true, - "tcp-request connection track-sc0 src table foo": true, - "tcp-request connection track-sc0 src table foo if some_check": true, - "tcp-request connection track-sc1 src table foo": true, - "tcp-request connection track-sc1 src table foo if some_check": true, - "tcp-request connection track-sc2 src table foo": true, - "tcp-request connection track-sc2 src table foo if some_check": true, - "tcp-request connection track-sc5 src": true, - "tcp-request connection track-sc5 src if some_check": true, - "tcp-request connection track-sc5 src table foo": true, - "tcp-request connection track-sc5 src table foo if some_check": true, - "tcp-request connection sc-add-gpc(1,2) 1": true, - "tcp-request connection sc-add-gpc(1,2) 1 if is-error": true, - "tcp-request connection sc-inc-gpc(1,2)": true, - "tcp-request connection sc-inc-gpc(1,2) if is-error": true, - "tcp-request connection sc-inc-gpc0(2)": true, - "tcp-request connection sc-inc-gpc0(2) if is-error": true, - "tcp-request connection sc-inc-gpc1(2)": true, - "tcp-request connection sc-inc-gpc1(2) if is-error": true, - "tcp-request connection sc-set-gpt(scx,44) 1337 if exceeds_limit": true, - "tcp-request connection sc-set-gpt0(0) 1337": true, - "tcp-request connection sc-set-gpt0(0) 1337 if exceeds_limit": true, - "tcp-request connection set-src src,ipmask(24)": true, - "tcp-request connection set-src src,ipmask(24) if some_check": true, - "tcp-request connection set-src hdr(x-forwarded-for)": true, - "tcp-request connection set-src hdr(x-forwarded-for) if some_check": true, - "tcp-request connection silent-drop": true, - "tcp-request connection silent-drop if !HTTP": true, - "tcp-request connection lua.foo": true, - "tcp-request connection lua.foo param if !HTTP": true, - "tcp-request connection lua.foo param param1": true, - "tcp-request session accept": true, - "tcp-request session accept if !HTTP": true, - "tcp-request session reject": true, - "tcp-request session reject if !HTTP": true, - "tcp-request session track-sc0 src": true, - "tcp-request session track-sc0 src if some_check": true, - "tcp-request session track-sc1 src": true, - "tcp-request session track-sc1 src if some_check": true, - "tcp-request session track-sc2 src": true, - "tcp-request session track-sc2 src if some_check": true, - "tcp-request session track-sc0 src table foo": true, - "tcp-request session track-sc0 src table foo if some_check": true, - "tcp-request session track-sc1 src table foo": true, - "tcp-request session track-sc1 src table foo if some_check": true, - "tcp-request session track-sc2 src table foo": true, - "tcp-request session track-sc2 src table foo if some_check": true, - "tcp-request session track-sc5 src": true, - "tcp-request session track-sc5 src if some_check": true, - "tcp-request session track-sc5 src table foo": true, - "tcp-request session track-sc5 src table foo if some_check": true, - "tcp-request session sc-add-gpc(1,2) 1": true, - "tcp-request session sc-add-gpc(1,2) 1 if is-error": true, - "tcp-request session sc-inc-gpc(1,2)": true, - "tcp-request session sc-inc-gpc(1,2) if is-error": true, - "tcp-request session sc-inc-gpc0(2)": true, - "tcp-request session sc-inc-gpc0(2) if is-error": true, - "tcp-request session sc-inc-gpc1(2)": true, - "tcp-request session sc-inc-gpc1(2) if is-error": true, - "tcp-request session sc-set-gpt(sc5,1) 1337 if exceeds_limit": true, - "tcp-request session sc-set-gpt0(0) 1337": true, - "tcp-request session sc-set-gpt0(0) 1337 if exceeds_limit": true, - "tcp-request session set-var(sess.src) src": true, - "tcp-request session set-var(sess.dn) ssl_c_s_dn": true, - "tcp-request session set-var-fmt(sess.src) src": true, - "tcp-request session set-var-fmt(sess.dn) ssl_c_s_dn": true, - "tcp-request session unset-var(sess.src)": true, - "tcp-request session unset-var(sess.dn)": true, - "tcp-request session silent-drop": true, - "tcp-request session silent-drop if !HTTP": true, - "tcp-request session attach-srv srv1": true, - "tcp-request session attach-srv srv1 name example.com": true, - "tcp-request session attach-srv srv1 name example.com if exceeds_limit": true, - "tcp-request content set-bandwidth-limit my-limit": true, - "tcp-request content set-bandwidth-limit my-limit limit 1m period 10s": true, - "tcp-request content set-bandwidth-limit my-limit period 10s": true, - "tcp-request content set-bandwidth-limit my-limit limit 1m": true, - "tcp-request content set-log-level silent": true, - "tcp-request content set-log-level silent if FALSE": true, - "tcp-request content set-mark 20": true, - "tcp-request content set-mark 0x1Ab if FALSE": true, - "tcp-request connection set-mark 20": true, - "tcp-request connection set-mark 0x1Ab if FALSE": true, - "tcp-request connection set-src-port hdr(port)": true, - "tcp-request connection set-src-port hdr(port) if FALSE": true, - "tcp-request content set-src-port hdr(port)": true, - "tcp-request content set-src-port hdr(port) if FALSE": true, - "tcp-request content set-tos 0 if FALSE": true, - "tcp-request content set-tos 0": true, - "tcp-request connection set-tos 0 if FALSE": true, - "tcp-request connection set-tos 0": true, - "tcp-request connection set-var-fmt(txn.ip_port) %%[dst]:%%[dst_port]": true, - "tcp-request content set-nice 0 if FALSE": true, - "tcp-request content set-nice 0": true, - "tcp-request content switch-mode http": true, - "tcp-request content switch-mode http if FALSE": true, - "tcp-request content switch-mode http proto my-proto": true, - "tcp-request connection set-fc-mark 1": true, - "tcp-request connection set-fc-tos 1": true, - "tcp-request session set-fc-mark 9999 if some_check": true, - "tcp-request session set-fc-tos 255": true, - "tcp-request content set-bc-mark hdr(port)": true, - "tcp-request content set-bc-tos 0xff if some_check": true, - "tcp-request content set-fc-mark 0xffffffff": true, - "tcp-request content set-fc-tos 100": true, - "tcp-request content sc-inc-gpc": false, - "tcp-request content sc-inc-gpc0": false, - "tcp-request content sc-inc-gpc1": false, - "tcp-request content sc-add-gpc": false, - "tcp-request connection sc-add-gpc": false, - "tcp-request connection sc-inc-gpc": false, - "tcp-request connection sc-inc-gpc0": false, - "tcp-request connection sc-inc-gpc1": false, - "tcp-request connection set-src": false, - "tcp-request session sc-add-gpc": false, - "tcp-request session sc-inc-gpc": false, - "tcp-request session sc-inc-gpc0": false, - "tcp-request session sc-inc-gpc1": false, - "tcp-request session attach-srv": false, - "tcp-request session attach-srv srv1 name": false, - "tcp-request session attach-srv srv1 if": false, - "tcp-request session attach-srv srv1 name example.com unless": false, + "tcp-request content silent-drop rst-ttl 1": true, + "tcp-request content silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 }": true, + "tcp-request content send-spoe-group engine group": true, + "tcp-request content use-service lua.deny": true, + "tcp-request content use-service lua.deny if !HTTP": true, + "tcp-request content lua.foo": true, + "tcp-request content lua.foo param if !HTTP": true, + "tcp-request content lua.foo param param1": true, + "tcp-request connection accept": true, + "tcp-request connection accept if !HTTP": true, + "tcp-request connection reject": true, + "tcp-request connection reject if !HTTP": true, + "tcp-request connection expect-proxy layer4 if { src -f proxies.lst }": true, + "tcp-request connection expect-netscaler-cip layer4": true, + "tcp-request connection expect-netscaler-cip layer4 if TRUE": true, + "tcp-request connection capture req.payload(0,6) len 6": true, + "tcp-request connection track-sc0 src": true, + "tcp-request connection track-sc0 src if some_check": true, + "tcp-request connection track-sc1 src": true, + "tcp-request connection track-sc1 src if some_check": true, + "tcp-request connection track-sc2 src": true, + "tcp-request connection track-sc2 src if some_check": true, + "tcp-request connection track-sc0 src table foo": true, + "tcp-request connection track-sc0 src table foo if some_check": true, + "tcp-request connection track-sc1 src table foo": true, + "tcp-request connection track-sc1 src table foo if some_check": true, + "tcp-request connection track-sc2 src table foo": true, + "tcp-request connection track-sc2 src table foo if some_check": true, + "tcp-request connection track-sc5 src": true, + "tcp-request connection track-sc5 src if some_check": true, + "tcp-request connection track-sc5 src table foo": true, + "tcp-request connection track-sc5 src table foo if some_check": true, + "tcp-request connection sc-add-gpc(1,2) 1": true, + "tcp-request connection sc-add-gpc(1,2) 1 if is-error": true, + "tcp-request connection sc-inc-gpc(1,2)": true, + "tcp-request connection sc-inc-gpc(1,2) if is-error": true, + "tcp-request connection sc-inc-gpc0(2)": true, + "tcp-request connection sc-inc-gpc0(2) if is-error": true, + "tcp-request connection sc-inc-gpc1(2)": true, + "tcp-request connection sc-inc-gpc1(2) if is-error": true, + "tcp-request connection sc-set-gpt(scx,44) 1337 if exceeds_limit": true, + "tcp-request connection sc-set-gpt0(0) 1337": true, + "tcp-request connection sc-set-gpt0(0) 1337 if exceeds_limit": true, + "tcp-request connection set-src src,ipmask(24)": true, + "tcp-request connection set-src src,ipmask(24) if some_check": true, + "tcp-request connection set-src hdr(x-forwarded-for)": true, + "tcp-request connection set-src hdr(x-forwarded-for) if some_check": true, + "tcp-request connection silent-drop": true, + "tcp-request connection silent-drop if !HTTP": true, + "tcp-request connection silent-drop rst-ttl 1": true, + "tcp-request connection silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 }": true, + "tcp-request connection lua.foo": true, + "tcp-request connection lua.foo param if !HTTP": true, + "tcp-request connection lua.foo param param1": true, + "tcp-request session accept": true, + "tcp-request session accept if !HTTP": true, + "tcp-request session reject": true, + "tcp-request session reject if !HTTP": true, + "tcp-request session track-sc0 src": true, + "tcp-request session track-sc0 src if some_check": true, + "tcp-request session track-sc1 src": true, + "tcp-request session track-sc1 src if some_check": true, + "tcp-request session track-sc2 src": true, + "tcp-request session track-sc2 src if some_check": true, + "tcp-request session track-sc0 src table foo": true, + "tcp-request session track-sc0 src table foo if some_check": true, + "tcp-request session track-sc1 src table foo": true, + "tcp-request session track-sc1 src table foo if some_check": true, + "tcp-request session track-sc2 src table foo": true, + "tcp-request session track-sc2 src table foo if some_check": true, + "tcp-request session track-sc5 src": true, + "tcp-request session track-sc5 src if some_check": true, + "tcp-request session track-sc5 src table foo": true, + "tcp-request session track-sc5 src table foo if some_check": true, + "tcp-request session sc-add-gpc(1,2) 1": true, + "tcp-request session sc-add-gpc(1,2) 1 if is-error": true, + "tcp-request session sc-inc-gpc(1,2)": true, + "tcp-request session sc-inc-gpc(1,2) if is-error": true, + "tcp-request session sc-inc-gpc0(2)": true, + "tcp-request session sc-inc-gpc0(2) if is-error": true, + "tcp-request session sc-inc-gpc1(2)": true, + "tcp-request session sc-inc-gpc1(2) if is-error": true, + "tcp-request session sc-set-gpt(sc5,1) 1337 if exceeds_limit": true, + "tcp-request session sc-set-gpt0(0) 1337": true, + "tcp-request session sc-set-gpt0(0) 1337 if exceeds_limit": true, + "tcp-request session set-var(sess.src) src": true, + "tcp-request session set-var(sess.dn) ssl_c_s_dn": true, + "tcp-request session set-var-fmt(sess.src) src": true, + "tcp-request session set-var-fmt(sess.dn) ssl_c_s_dn": true, + "tcp-request session unset-var(sess.src)": true, + "tcp-request session unset-var(sess.dn)": true, + "tcp-request session silent-drop": true, + "tcp-request session silent-drop if !HTTP": true, + "tcp-request session silent-drop rst-ttl 1": true, + "tcp-request session silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 }": true, + "tcp-request session attach-srv srv1": true, + "tcp-request session attach-srv srv1 name example.com": true, + "tcp-request session attach-srv srv1 name example.com if exceeds_limit": true, + "tcp-request content set-bandwidth-limit my-limit": true, + "tcp-request content set-bandwidth-limit my-limit limit 1m period 10s": true, + "tcp-request content set-bandwidth-limit my-limit period 10s": true, + "tcp-request content set-bandwidth-limit my-limit limit 1m": true, + "tcp-request content set-log-level silent": true, + "tcp-request content set-log-level silent if FALSE": true, + "tcp-request content set-mark 20": true, + "tcp-request content set-mark 0x1Ab if FALSE": true, + "tcp-request connection set-mark 20": true, + "tcp-request connection set-mark 0x1Ab if FALSE": true, + "tcp-request connection set-src-port hdr(port)": true, + "tcp-request connection set-src-port hdr(port) if FALSE": true, + "tcp-request content set-src-port hdr(port)": true, + "tcp-request content set-src-port hdr(port) if FALSE": true, + "tcp-request content set-tos 0 if FALSE": true, + "tcp-request content set-tos 0": true, + "tcp-request connection set-tos 0 if FALSE": true, + "tcp-request connection set-tos 0": true, + "tcp-request connection set-var-fmt(txn.ip_port) %%[dst]:%%[dst_port]": true, + "tcp-request content set-nice 0 if FALSE": true, + "tcp-request content set-nice 0": true, + "tcp-request content switch-mode http": true, + "tcp-request content switch-mode http if FALSE": true, + "tcp-request content switch-mode http proto my-proto": true, + "tcp-request connection set-fc-mark 1": true, + "tcp-request connection set-fc-tos 1": true, + "tcp-request session set-fc-mark 9999 if some_check": true, + "tcp-request session set-fc-tos 255": true, + "tcp-request content set-bc-mark hdr(port)": true, + "tcp-request content set-bc-tos 0xff if some_check": true, + "tcp-request content set-fc-mark 0xffffffff": true, + "tcp-request content set-fc-tos 100": true, + "tcp-request content sc-inc-gpc": false, + "tcp-request content sc-inc-gpc0": false, + "tcp-request content sc-inc-gpc1": false, + "tcp-request content sc-add-gpc": false, + "tcp-request silent-drop rst-ttl": false, + "tcp-request connection sc-add-gpc": false, + "tcp-request connection sc-inc-gpc": false, + "tcp-request connection sc-inc-gpc0": false, + "tcp-request connection sc-inc-gpc1": false, + "tcp-request connection set-src": false, + "tcp-request connection silent-drop rst-ttl": false, + "tcp-request session sc-add-gpc": false, + "tcp-request session sc-inc-gpc": false, + "tcp-request session sc-inc-gpc0": false, + "tcp-request session sc-inc-gpc1": false, + "tcp-request session silent-drop rst-ttl": false, + "tcp-request session attach-srv": false, + "tcp-request session attach-srv srv1 name": false, + "tcp-request session attach-srv srv1 if": false, + "tcp-request session attach-srv srv1 name example.com unless": false, "tcp-request": false, "tcp-request content": false, "tcp-request connection": false, @@ -287,12 +297,12 @@ func TestRequeststcp(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -302,15 +312,15 @@ func TestRequeststcp(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/tcp-response_generated_test.go b/config-parser/tests/tcp-response_generated_test.go index 623fc21c..5279f33d 100644 --- a/config-parser/tests/tcp-response_generated_test.go +++ b/config-parser/tests/tcp-response_generated_test.go @@ -94,12 +94,12 @@ func TestResponsestcp(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -109,15 +109,15 @@ func TestResponsestcp(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/thread-group_generated_test.go b/config-parser/tests/thread-group_generated_test.go index 83209bec..3984ce5a 100644 --- a/config-parser/tests/thread-group_generated_test.go +++ b/config-parser/tests/thread-group_generated_test.go @@ -53,12 +53,12 @@ func TestThreadGroup(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestThreadGroup(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/tune.quic.socket-owner_generated_test.go b/config-parser/tests/tune.quic.socket-owner_generated_test.go index 0fd8dc36..dd50c446 100644 --- a/config-parser/tests/tune.quic.socket-owner_generated_test.go +++ b/config-parser/tests/tune.quic.socket-owner_generated_test.go @@ -53,12 +53,12 @@ func TestQuicSocketOwner(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestQuicSocketOwner(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/unique-id-format_generated_test.go b/config-parser/tests/unique-id-format_generated_test.go index 89d32d5a..ac352ce6 100644 --- a/config-parser/tests/unique-id-format_generated_test.go +++ b/config-parser/tests/unique-id-format_generated_test.go @@ -53,12 +53,12 @@ func TestUniqueIDFormat(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestUniqueIDFormat(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/unique-id-header_generated_test.go b/config-parser/tests/unique-id-header_generated_test.go index 4b4759be..29ccd525 100644 --- a/config-parser/tests/unique-id-header_generated_test.go +++ b/config-parser/tests/unique-id-header_generated_test.go @@ -51,12 +51,12 @@ func TestUniqueIDHeader(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestUniqueIDHeader(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/unix-bind_generated_test.go b/config-parser/tests/unix-bind_generated_test.go index a250cd7f..5a7af10a 100644 --- a/config-parser/tests/unix-bind_generated_test.go +++ b/config-parser/tests/unix-bind_generated_test.go @@ -56,12 +56,12 @@ func TestUnixBind(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -71,15 +71,15 @@ func TestUnixBind(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/use-fcgi-app_generated_test.go b/config-parser/tests/use-fcgi-app_generated_test.go index dbbd3b4c..b404e835 100644 --- a/config-parser/tests/use-fcgi-app_generated_test.go +++ b/config-parser/tests/use-fcgi-app_generated_test.go @@ -51,12 +51,12 @@ func TestUseFcgiApp(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -66,15 +66,15 @@ func TestUseFcgiApp(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/use-server_generated_test.go b/config-parser/tests/use-server_generated_test.go index 1b771f98..f9cffc78 100644 --- a/config-parser/tests/use-server_generated_test.go +++ b/config-parser/tests/use-server_generated_test.go @@ -27,8 +27,8 @@ import ( func TestUseServer(t *testing.T) { tests := map[string]bool{ - "use-server www if { req_ssl_sni -i www.example.com }": true, - "use-server www if { req_ssl_sni -i www.example.com } # comment": true, + "use-server www if { req.ssl_sni -i www.example.com }": true, + "use-server www if { req.ssl_sni -i www.example.com } # comment": true, "use-server": false, "---": false, "--- ---": false, @@ -52,12 +52,12 @@ func TestUseServer(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -67,15 +67,15 @@ func TestUseServer(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/use_backend_generated_test.go b/config-parser/tests/use_backend_generated_test.go index 70201b76..f20a7bdf 100644 --- a/config-parser/tests/use_backend_generated_test.go +++ b/config-parser/tests/use_backend_generated_test.go @@ -53,12 +53,12 @@ func TestUseBackend(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -68,15 +68,15 @@ func TestUseBackend(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/tests/user_generated_test.go b/config-parser/tests/user_generated_test.go index 80268612..3a366be8 100644 --- a/config-parser/tests/user_generated_test.go +++ b/config-parser/tests/user_generated_test.go @@ -54,12 +54,12 @@ func TestUser(t *testing.T) { } if shouldPass { if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } result, err := parser.Result() if err != nil { - t.Errorf(err.Error()) + t.Error(err) return } var returnLine string @@ -69,15 +69,15 @@ func TestUser(t *testing.T) { returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) } if command != returnLine { - t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + t.Errorf("error: has [%s] expects [%s]", returnLine, command) } } else { if err == nil { - t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + t.Errorf("error: did not throw error for line [%s]", line) } _, parseErr := parser.Result() if parseErr == nil { - t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + t.Errorf("error: did not throw error on result for line [%s]", line) } } }) diff --git a/config-parser/types/types-generic.go b/config-parser/types/types-generic.go index 51d1b6d1..cbfd1316 100644 --- a/config-parser/types/types-generic.go +++ b/config-parser/types/types-generic.go @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -//nolint:godot package types // Enabled is used by parsers Daemon, MasterWorker, ExternalCheck, NoSplice, CompressionOffload diff --git a/config-parser/types/types-other.go b/config-parser/types/types-other.go index b9fd1eff..b85d89e3 100644 --- a/config-parser/types/types-other.go +++ b/config-parser/types/types-other.go @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -//nolint:godot package types import "github.com/haproxytech/client-native/v6/config-parser/common" @@ -272,6 +271,7 @@ type Action interface { //test:fail:http-request //test:fail:http-request capture req.cook_cnt(FirstVisit),bool strlen 10 //test:frontend-ok:http-request capture req.cook_cnt(FirstVisit),bool len 10 +//test:frontend-ok:http-request capture str("DNS resolution failure") len 32 unless dns_successful //test:ok:http-request set-map(map.lst) %[src] %[req.hdr(X-Value)] if value //test:ok:http-request set-map(map.lst) %[src] %[req.hdr(X-Value)] //test:fail:http-request set-map(map.lst) %[src] @@ -445,6 +445,9 @@ type Action interface { //test:fail:http-request set-var-fmt(req.my_var) //test:ok:http-request silent-drop //test:ok:http-request silent-drop if FALSE +//test:ok:http-request silent-drop rst-ttl 1 +//test:ok:http-request silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +//test:fail:http-request silent-drop rst-ttl //test:ok:http-request strict-mode on //test:ok:http-request strict-mode on if FALSE //test:fail:http-request strict-mode @@ -681,11 +684,15 @@ type HTTPRequests struct{} //test:fail:http-response set-var-fmt(req.my_var) //test:ok:http-response silent-drop //test:ok:http-response silent-drop if FALSE +//test:ok:http-response silent-drop rst-ttl 1 +//test:ok:http-response silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +//test:fail:http-response silent-drop rst-ttl //test:ok:http-response unset-var(req.my_var) //test:ok:http-response unset-var(req.my_var) if FALSE //test:fail:http-response unset-var(req.) //test:fail:http-response unset-var(req) //test:ok:http-response track-sc0 src if FALSE + //test:ok:http-response track-sc0 src table tr if FALSE //test:ok:http-response track-sc0 src //test:fail:http-response track-sc0 @@ -931,7 +938,7 @@ type HTTPCheck struct{} //test:fail:tcp-check unset-var(txn.from) if x type TCPCheck struct{} -type TCPType interface { +type TCPType interface { //nolint:iface Parse(parts []string, comment string) error String() string GetComment() string @@ -952,6 +959,7 @@ type TCPType interface { //test:ok:tcp-request content reject if !HTTP //test:ok:tcp-request content capture req.payload(0,6) len 6 //test:ok:tcp-request content capture req.payload(0,6) len 6 if !HTTP +//test:frontend-ok:tcp-request content capture str("DNS resolution failure") len 32 unless dns_successful //test:ok:tcp-request content do-resolve(txn.myip,mydns,ipv6) capture.req.hdr(0),lower //test:ok:tcp-request content do-resolve(txn.myip,mydns) capture.req.hdr(0),lower //test:ok:tcp-request content set-priority-class int(1) @@ -998,6 +1006,9 @@ type TCPType interface { //test:ok:tcp-request content unset-var(sess.dn) //test:ok:tcp-request content silent-drop //test:ok:tcp-request content silent-drop if !HTTP +//test:ok:tcp-request content silent-drop rst-ttl 1 +//test:ok:tcp-request content silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +//test:fail:tcp-request silent-drop rst-ttl //test:ok:tcp-request content send-spoe-group engine group //test:ok:tcp-request content use-service lua.deny //test:ok:tcp-request content use-service lua.deny if !HTTP @@ -1050,6 +1061,9 @@ type TCPType interface { //test:fail:tcp-request connection set-src //test:ok:tcp-request connection silent-drop //test:ok:tcp-request connection silent-drop if !HTTP +//test:ok:tcp-request connection silent-drop rst-ttl 1 +//test:ok:tcp-request connection silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +//test:fail:tcp-request connection silent-drop rst-ttl //test:ok:tcp-request connection lua.foo //test:ok:tcp-request connection lua.foo param if !HTTP //test:ok:tcp-request connection lua.foo param param1 @@ -1096,6 +1110,9 @@ type TCPType interface { //test:ok:tcp-request session unset-var(sess.dn) //test:ok:tcp-request session silent-drop //test:ok:tcp-request session silent-drop if !HTTP +//test:ok:tcp-request session silent-drop rst-ttl 1 +//test:ok:tcp-request session silent-drop rst-ttl 1 if { src,table_http_req_rate(ratelimits.agg),sub(txn.rate_limit) ge 1000 } +//test:fail:tcp-request session silent-drop rst-ttl //test:ok:tcp-request session attach-srv srv1 //test:ok:tcp-request session attach-srv srv1 name example.com //test:ok:tcp-request session attach-srv srv1 name example.com if exceeds_limit @@ -1254,7 +1271,7 @@ type TCPResponses struct{} //test:ok:redirect prefix http://www.bar.com code 301 if { hdr(host) -i foo.com } type Redirect struct{} -type StatsSettings interface { +type StatsSettings interface { //nolint:iface Parse(parts []string, comment string) error String() string GetComment() string diff --git a/config-parser/types/types.go b/config-parser/types/types.go index 40214300..be92d4b0 100644 --- a/config-parser/types/types.go +++ b/config-parser/types/types.go @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -//nolint:godot package types import ( @@ -1195,8 +1194,8 @@ type UseFcgiApp struct { //name:use-server //is:multiple //no:parse -//test:ok:use-server www if { req_ssl_sni -i www.example.com } -//test:ok:use-server www if { req_ssl_sni -i www.example.com } # comment +//test:ok:use-server www if { req.ssl_sni -i www.example.com } +//test:ok:use-server www if { req.ssl_sni -i www.example.com } # comment //test:fail:use-server type UseServer struct { Name string diff --git a/configuration/bind.go b/configuration/bind.go index bf09c752..fa4cf134 100644 --- a/configuration/bind.go +++ b/configuration/bind.go @@ -219,7 +219,8 @@ func ParseBind(ondiskBind types.Bind) *models.Bind { return b } -func parseBindParams(bindOptions []params.BindOption) (b models.BindParams) { //nolint:gocyclo,cyclop,maintidx,gocognit +func parseBindParams(bindOptions []params.BindOption) models.BindParams { //nolint:gocyclo,cyclop,maintidx,gocognit + var b models.BindParams for _, p := range bindOptions { switch v := p.(type) { case *params.BindOptionDoubleWord: @@ -412,7 +413,8 @@ func SerializeBind(b models.Bind) types.Bind { return bind } -func serializeBindParams(b models.BindParams, path string) (options []params.BindOption) { //nolint:gocognit,gocyclo,cyclop,maintidx +func serializeBindParams(b models.BindParams, path string) []params.BindOption { //nolint:gocognit,gocyclo,cyclop,maintidx + var options []params.BindOption if b.Name != "" { options = append(options, ¶ms.BindOptionValue{Name: "name", Value: b.Name}) } else if path != "" { @@ -499,25 +501,25 @@ func serializeBindParams(b models.BindParams, path string) (options []params.Bin options = append(options, ¶ms.BindOptionWord{Name: "defer-accept"}) } if b.ExposeFdListeners { - options = append(options, ¶ms.ServerOptionDoubleWord{Name: "expose-fd", Value: "listeners"}) + options = append(options, ¶ms.BindOptionDoubleWord{Name: "expose-fd", Value: "listeners"}) } if b.ForceSslv3 { - options = append(options, ¶ms.ServerOptionWord{Name: "force-sslv3"}) + options = append(options, ¶ms.BindOptionWord{Name: "force-sslv3"}) } if b.ForceTlsv10 { - options = append(options, ¶ms.ServerOptionWord{Name: "force-tlsv10"}) + options = append(options, ¶ms.BindOptionWord{Name: "force-tlsv10"}) } if b.ForceTlsv11 { - options = append(options, ¶ms.ServerOptionWord{Name: "force-tlsv11"}) + options = append(options, ¶ms.BindOptionWord{Name: "force-tlsv11"}) } if b.ForceTlsv12 { - options = append(options, ¶ms.ServerOptionWord{Name: "force-tlsv12"}) + options = append(options, ¶ms.BindOptionWord{Name: "force-tlsv12"}) } if b.ForceTlsv13 { - options = append(options, ¶ms.ServerOptionWord{Name: "force-tlsv13"}) + options = append(options, ¶ms.BindOptionWord{Name: "force-tlsv13"}) } if b.GenerateCertificates { - options = append(options, ¶ms.ServerOptionWord{Name: "generate-certificates"}) + options = append(options, ¶ms.BindOptionWord{Name: "generate-certificates"}) } if b.Gid != 0 { options = append(options, ¶ms.BindOptionValue{Name: "gid", Value: strconv.FormatInt(b.Gid, 10)}) @@ -556,31 +558,31 @@ func serializeBindParams(b models.BindParams, path string) (options []params.Bin options = append(options, ¶ms.BindOptionValue{Name: "nbconn", Value: strconv.FormatInt(b.Nbconn, 10)}) } if b.NoCaNames { - options = append(options, ¶ms.ServerOptionWord{Name: "no-ca-names"}) + options = append(options, ¶ms.BindOptionWord{Name: "no-ca-names"}) } if b.NoSslv3 { - options = append(options, ¶ms.ServerOptionWord{Name: "no-sslv3"}) + options = append(options, ¶ms.BindOptionWord{Name: "no-sslv3"}) } if b.NoTLSTickets { - options = append(options, ¶ms.ServerOptionWord{Name: "no-tls-tickets"}) + options = append(options, ¶ms.BindOptionWord{Name: "no-tls-tickets"}) } if b.NoTlsv10 { - options = append(options, ¶ms.ServerOptionWord{Name: "no-tlsv10"}) + options = append(options, ¶ms.BindOptionWord{Name: "no-tlsv10"}) } if b.NoTlsv11 { - options = append(options, ¶ms.ServerOptionWord{Name: "no-tlsv11"}) + options = append(options, ¶ms.BindOptionWord{Name: "no-tlsv11"}) } if b.NoTlsv12 { - options = append(options, ¶ms.ServerOptionWord{Name: "no-tlsv12"}) + options = append(options, ¶ms.BindOptionWord{Name: "no-tlsv12"}) } if b.NoTlsv13 { - options = append(options, ¶ms.ServerOptionWord{Name: "no-tlsv13"}) + options = append(options, ¶ms.BindOptionWord{Name: "no-tlsv13"}) } if b.Npn != "" { options = append(options, ¶ms.BindOptionValue{Name: "npn", Value: b.Npn}) } if b.PreferClientCiphers { - options = append(options, ¶ms.ServerOptionWord{Name: "prefer-client-ciphers"}) + options = append(options, ¶ms.BindOptionWord{Name: "prefer-client-ciphers"}) } if b.Proto != "" { options = append(options, ¶ms.BindOptionValue{Name: "proto", Value: b.Proto}) @@ -595,10 +597,10 @@ func serializeBindParams(b models.BindParams, path string) (options []params.Bin options = append(options, ¶ms.BindOptionValue{Name: "ssl-min-ver", Value: b.SslMinVer}) } if b.StrictSni { - options = append(options, ¶ms.ServerOptionWord{Name: "strict-sni"}) + options = append(options, ¶ms.BindOptionWord{Name: "strict-sni"}) } if b.Tfo { - options = append(options, ¶ms.ServerOptionWord{Name: "tfo"}) + options = append(options, ¶ms.BindOptionWord{Name: "tfo"}) } if b.Thread != "" { options = append(options, ¶ms.BindOptionValue{Name: "thread", Value: b.Thread}) diff --git a/configuration/check.go b/configuration/check.go new file mode 100644 index 00000000..cf6ef11a --- /dev/null +++ b/configuration/check.go @@ -0,0 +1,145 @@ +// Copyright 2025 HAProxy Technologies +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package configuration + +import ( + "fmt" + "os" + "os/exec" + "strconv" + "strings" + + "github.com/haproxytech/client-native/v6/configuration/options" + shellquote "github.com/kballard/go-shellquote" +) + +//nolint:noctx +func checkHaproxyConfiguration(opt options.ConfigurationOptions, path string, transactionID ...string) error { + var name string + var args []string + + // Inherit the environment but filter out a few unwanted variables. + envs := removeFromEnv(os.Environ(), "HAPROXY_STARTUPLOGS_FD", + "HAPROXY_MWORKER_WAIT_ONLY", "HAPROXY_PROCESSES") + + switch { + case len(transactionID) > 0 && len(opt.ValidateCmd) > 0: + w, _ := shellquote.Split(opt.ValidateCmd) + name = w[0] + args = w[1:] + envs = append(envs, "DATAPLANEAPI_TRANSACTION_FILE="+path) + case opt.MasterWorker: + name = opt.Haproxy + args = []string{"-W", "-f", path, "-c"} + args = addConfigFilesToArgs(args, opt) + default: + name = opt.Haproxy + args = []string{"-f", path, "-c"} + args = addConfigFilesToArgs(args, opt) + } + + // #nosec G204 + cmd := exec.Command(name, args...) + cmd.Env = envs + var stderr strings.Builder + cmd.Stderr = &stderr + + err := cmd.Run() + if err != nil { + errStr := fmt.Sprintf("%s: %s", err.Error(), parseHAProxyCheckError(stderr.String(), transactionID...)) + return NewConfError(ErrValidationError, errStr) + } + return nil +} + +func parseHAProxyCheckError(output string, transactionID ...string) string { //nolint:gocognit + var b strings.Builder + + if len(transactionID) > 0 && transactionID[0] != "" { + b.WriteString(fmt.Sprintf("err transactionId=%s \n", transactionID[0])) + } + + for lineWhole := range strings.SplitSeq(output, "\n") { + line := strings.TrimSpace(lineWhole) + if strings.HasPrefix(line, "[ALERT]") { + if strings.HasSuffix(line, "fatal errors found in configuration.") { + continue + } + if strings.Contains(line, "error(s) found in configuration file : ") { + continue + } + + parts := strings.Split(line, " : ") + if len(parts) > 2 && strings.HasPrefix(strings.TrimSpace(parts[1]), "parsing [") { + fParts := strings.Split(strings.TrimSpace(parts[1]), ":") + var msgB strings.Builder + for i := 2; i < len(parts); i++ { + msgB.WriteString(parts[i]) + msgB.WriteString(" ") + } + if len(fParts) > 1 { + lNo, err := strconv.ParseInt(strings.TrimSuffix(fParts[1], "]"), 10, 64) + if err == nil { + b.WriteString(fmt.Sprintf("line=%d msg=\"%s\"\n", lNo, strings.TrimSpace(msgB.String()))) + } else { + b.WriteString(fmt.Sprintf("msg=\"%s\"\n", strings.TrimSpace(msgB.String()))) + } + } + } else if len(parts) > 1 { + var msgB strings.Builder + for i := 1; i < len(parts); i++ { + msgB.WriteString(parts[i]) + msgB.WriteString(" ") + } + b.WriteString(fmt.Sprintf("msg=\"%s\"\n", strings.TrimSpace(msgB.String()))) + } + } + } + return strings.TrimSuffix(b.String(), "\n") +} + +func addConfigFilesToArgs(args []string, clientParams options.ConfigurationOptions) []string { + result := make([]string, 0) //nolint: prealloc + for _, file := range clientParams.ValidateConfigFilesBefore { + result = append(result, "-f", file) + } + result = append(result, args...) + + for _, file := range clientParams.ValidateConfigFilesAfter { + result = append(result, "-f", file) + } + return result +} + +// Returns a copy of envs without the unwanted environment variables. +func removeFromEnv(envs []string, unwanted ...string) []string { + newEnv := make([]string, 0, len(envs)) + + for _, v := range envs { + skip := false + for _, bad := range unwanted { + if strings.HasPrefix(v, bad+"=") { + skip = true + break + } + } + if !skip { + newEnv = append(newEnv, v) + } + } + + return newEnv +} diff --git a/configuration/configuration.go b/configuration/configuration.go index 18beb2ea..456c642d 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -16,6 +16,7 @@ package configuration import ( + "errors" "fmt" "reflect" "strconv" @@ -30,7 +31,6 @@ import ( "github.com/haproxytech/client-native/v6/config-parser/parsers" stats "github.com/haproxytech/client-native/v6/config-parser/parsers/stats/settings" "github.com/haproxytech/client-native/v6/config-parser/types" - "github.com/pkg/errors" "github.com/haproxytech/client-native/v6/configuration/options" "github.com/haproxytech/client-native/v6/misc" @@ -78,10 +78,11 @@ type ClientParams struct { // transaction files on StartTransaction, and deletes on CommitTransaction. We save // data to file on every change for persistence. type client struct { + Transaction + parser parser.Parser parsers map[string]parser.Parser services map[string]*Service - Transaction clientMu sync.Mutex } @@ -89,8 +90,8 @@ type client struct { func (c *client) SetValidateConfigFiles(before, after []string) { c.clientMu.Lock() defer c.clientMu.Unlock() - c.Transaction.ValidateConfigFilesBefore = before - c.Transaction.ValidateConfigFilesAfter = after + c.ValidateConfigFilesBefore = before + c.ValidateConfigFilesAfter = after } // HasParser checks whether transaction exists in parser @@ -128,14 +129,14 @@ func (c *client) AddParser(transactionID string) error { } parserOptions := []parser_options.ParserOption{} - if c.ConfigurationOptions.UseMd5Hash { + if c.UseMd5Hash { parserOptions = append(parserOptions, parser_options.UseMd5Hash) } if c.noNamedDefaultsFrom { parserOptions = append(parserOptions, parser_options.NoNamedDefaultsFrom) } - tFile := "" + var tFile string var err error if c.PersistentTransactions { tFile, err = c.GetTransactionFile(transactionID) @@ -148,7 +149,7 @@ func (c *client) AddParser(transactionID string) error { parserOptions = append(parserOptions, parser_options.Path(tFile)) p, err := parser.New(parserOptions...) if err != nil { - return NewConfError(ErrCannotReadConfFile, fmt.Sprintf("Cannot read %s", tFile)) + return NewConfError(ErrCannotReadConfFile, "Cannot read "+tFile) } c.clientMu.Lock() c.parsers[transactionID] = p @@ -219,7 +220,7 @@ func (c *client) IncrementVersion() error { func (c *client) LoadData(filename string) error { err := c.parser.LoadData(filename) if err != nil { - return NewConfError(ErrCannotReadConfFile, fmt.Sprintf("cannot read %s", filename)) + return NewConfError(ErrCannotReadConfFile, "cannot read "+filename) } return nil } @@ -236,7 +237,7 @@ func (c *client) Save(transactionFile, transactionID string) error { } // ParseSection sets the fields of the section based on the provided parser -func ParseSection(object interface{}, section parser.Section, pName string, p parser.Parser) error { +func ParseSection(object any, section parser.Section, pName string, p parser.Parser) error { sp := &SectionParser{ Object: object, Section: section, @@ -256,7 +257,7 @@ func NewParseSection(section parser.Section, pName string, p parser.Parser) *Sec // SectionParser is used set fields of a section based on the provided parser type SectionParser struct { - Object interface{} + Object any Parser parser.Parser Section parser.Section Name string @@ -265,7 +266,7 @@ type SectionParser struct { // Parse parses the sections fields and sets their values with the data from the parser func (s *SectionParser) Parse() error { objValue := reflect.ValueOf(s.Object).Elem() - for i := 0; i < objValue.NumField(); i++ { + for i := range objValue.NumField() { typeField := objValue.Type().Field(i) field := objValue.FieldByName(typeField.Name) val := s.parseField(typeField.Name) @@ -289,7 +290,7 @@ func (s *SectionParser) Parse() error { return nil } -func (s *SectionParser) parseField(fieldName string) interface{} { +func (s *SectionParser) parseField(fieldName string) any { if match, data := s.checkSpecialFields(fieldName); match { return data } @@ -305,7 +306,7 @@ func (s *SectionParser) parseField(fieldName string) interface{} { return nil } -func (s *SectionParser) checkSpecialFields(fieldName string) (match bool, data interface{}) { //nolint:gocyclo,cyclop +func (s *SectionParser) checkSpecialFields(fieldName string) (bool, any) { //nolint:gocyclo,cyclop switch fieldName { case "Shards": return true, s.shards() @@ -406,7 +407,7 @@ func (s *SectionParser) checkSpecialFields(fieldName string) (match bool, data i } } -func (s *SectionParser) checkTimeouts(fieldName string) (match bool, data interface{}) { +func (s *SectionParser) checkTimeouts(fieldName string) (bool, any) { if strings.HasSuffix(fieldName, "Timeout") { if pName := translateTimeout(fieldName); s.Parser.HasParser(s.Section, pName) { data, err := s.get(pName, false) @@ -420,7 +421,7 @@ func (s *SectionParser) checkTimeouts(fieldName string) (match bool, data interf return false, nil } -func (s *SectionParser) checkSingleLine(fieldName string) (match bool, data interface{}) { +func (s *SectionParser) checkSingleLine(fieldName string) (bool, any) { if pName := misc.DashCase(fieldName); s.Parser.HasParser(s.Section, pName) { data, err := s.get(pName, false) if err != nil { @@ -431,8 +432,8 @@ func (s *SectionParser) checkSingleLine(fieldName string) (match bool, data inte return false, nil } -func (s *SectionParser) checkOptions(fieldName string) (match bool, data interface{}) { - if pName := fmt.Sprintf("option %s", misc.DashCase(fieldName)); s.Parser.HasParser(s.Section, pName) { +func (s *SectionParser) checkOptions(fieldName string) (bool, any) { + if pName := "option " + misc.DashCase(fieldName); s.Parser.HasParser(s.Section, pName) { data, err := s.get(pName, false) if err != nil { return true, nil @@ -442,11 +443,11 @@ func (s *SectionParser) checkOptions(fieldName string) (match bool, data interfa return false, nil } -func (s *SectionParser) get(attribute string, createIfNotExists ...bool) (data common.ParserData, err error) { +func (s *SectionParser) get(attribute string, createIfNotExists ...bool) (common.ParserData, error) { return s.Parser.Get(s.Section, s.Name, attribute, createIfNotExists...) } -func (s *SectionParser) from() interface{} { +func (s *SectionParser) from() any { from, err := s.Parser.SectionsDefaultsFromGet(s.Section, s.Name) if err != nil { return "" @@ -454,7 +455,7 @@ func (s *SectionParser) from() interface{} { return from } -func (s *SectionParser) httpConnectionMode() interface{} { +func (s *SectionParser) httpConnectionMode() any { data, err := s.get("option http-tunnel", false) if err == nil { d := data.(*types.SimpleOption) //nolint:forcetypeassert @@ -500,7 +501,7 @@ func (s *SectionParser) httpConnectionMode() interface{} { return nil } -func (s *SectionParser) uniqueIDHeader() interface{} { +func (s *SectionParser) uniqueIDHeader() any { _, e := s.get("unique-id-format") if e != nil { return nil @@ -513,7 +514,7 @@ func (s *SectionParser) uniqueIDHeader() interface{} { return nil } -func (s *SectionParser) uniqueIDFormat() interface{} { +func (s *SectionParser) uniqueIDFormat() any { data, err := s.get("unique-id-format") if err == nil { d := data.(*types.UniqueIDFormat) @@ -522,7 +523,7 @@ func (s *SectionParser) uniqueIDFormat() interface{} { return nil } -func (s *SectionParser) httpReuse() interface{} { +func (s *SectionParser) httpReuse() any { data, err := s.get("http-reuse", false) if err == nil { d := data.(*types.HTTPReuse) @@ -531,7 +532,7 @@ func (s *SectionParser) httpReuse() interface{} { return nil } -func (s *SectionParser) httplog() interface{} { +func (s *SectionParser) httplog() any { data, err := s.get("option httplog", false) if err == nil { d := data.(*types.OptionHTTPLog) @@ -542,7 +543,7 @@ func (s *SectionParser) httplog() interface{} { return nil } -func (s *SectionParser) clflog() interface{} { +func (s *SectionParser) clflog() any { data, err := s.get("option httplog", false) if err == nil { d := data.(*types.OptionHTTPLog) @@ -553,7 +554,7 @@ func (s *SectionParser) clflog() interface{} { return nil } -func (s *SectionParser) defaultBackend() interface{} { +func (s *SectionParser) defaultBackend() any { data, err := s.get("default_backend", false) if err != nil { return nil @@ -562,7 +563,7 @@ func (s *SectionParser) defaultBackend() interface{} { return bck.Value } -func (s *SectionParser) externalCheckCommand() interface{} { +func (s *SectionParser) externalCheckCommand() any { data, err := s.get("external-check command", false) if err != nil { return nil @@ -571,7 +572,7 @@ func (s *SectionParser) externalCheckCommand() interface{} { return d.Command } -func (s *SectionParser) externalCheckPath() interface{} { +func (s *SectionParser) externalCheckPath() any { data, err := s.get("external-check path", false) if err != nil { return nil @@ -580,7 +581,7 @@ func (s *SectionParser) externalCheckPath() interface{} { return d.Path } -func (s *SectionParser) externalCheck() interface{} { +func (s *SectionParser) externalCheck() any { data, err := s.get("option external-check", false) if err != nil { return nil @@ -591,7 +592,7 @@ func (s *SectionParser) externalCheck() interface{} { return "enabled" } -func (s *SectionParser) allbackups() interface{} { +func (s *SectionParser) allbackups() any { data, err := s.get("option allbackups", false) if err != nil { return nil @@ -602,7 +603,7 @@ func (s *SectionParser) allbackups() interface{} { return "enabled" } -func (s *SectionParser) logasap() interface{} { +func (s *SectionParser) logasap() any { data, err := s.get("option logasap", false) if err != nil { return nil @@ -613,7 +614,7 @@ func (s *SectionParser) logasap() interface{} { return "enabled" } -func (s *SectionParser) useFcgiApp() interface{} { +func (s *SectionParser) useFcgiApp() any { _, e := s.get("use-fcgi-app") if e != nil { return nil @@ -626,7 +627,7 @@ func (s *SectionParser) useFcgiApp() interface{} { return nil } -func (s *SectionParser) advCheck() interface{} { +func (s *SectionParser) advCheck() any { if found, data := s.getSslChkData(); found { return data } @@ -662,7 +663,7 @@ func (s *SectionParser) advCheck() interface{} { return nil } -func (s *SectionParser) getSslChkData() (found bool, data interface{}) { +func (s *SectionParser) getSslChkData() (bool, any) { data, err := s.get("option ssl-hello-chk", false) if err == nil { d := data.(*types.SimpleOption) @@ -673,7 +674,7 @@ func (s *SectionParser) getSslChkData() (found bool, data interface{}) { return false, nil } -func (s *SectionParser) getSMTPChkData() (found bool, data interface{}) { +func (s *SectionParser) getSMTPChkData() (bool, any) { data, err := s.get("option smtpchk", false) if err == nil { d := data.(*types.OptionSmtpchk) @@ -688,7 +689,7 @@ func (s *SectionParser) getSMTPChkData() (found bool, data interface{}) { return false, nil } -func (s *SectionParser) getLdapCheckData() (found bool, data interface{}) { +func (s *SectionParser) getLdapCheckData() (bool, any) { data, err := s.get("option ldap-check", false) if err == nil { d := data.(*types.SimpleOption) @@ -699,7 +700,7 @@ func (s *SectionParser) getLdapCheckData() (found bool, data interface{}) { return false, nil } -func (s *SectionParser) getMysqlCheckData() (found bool, data interface{}) { +func (s *SectionParser) getMysqlCheckData() (bool, any) { data, err := s.get("option mysql-check", false) if err == nil { d := data.(*types.OptionMysqlCheck) @@ -714,7 +715,7 @@ func (s *SectionParser) getMysqlCheckData() (found bool, data interface{}) { return false, nil } -func (s *SectionParser) getPgsqlCheckData() (found bool, data interface{}) { +func (s *SectionParser) getPgsqlCheckData() (bool, any) { data, err := s.get("option pgsql-check", false) if err == nil { d := data.(*types.OptionPgsqlCheck) @@ -728,7 +729,7 @@ func (s *SectionParser) getPgsqlCheckData() (found bool, data interface{}) { return false, nil } -func (s *SectionParser) getTCPCheckData() (found bool, data interface{}) { +func (s *SectionParser) getTCPCheckData() (bool, any) { data, err := s.get("option tcp-check", false) if err == nil { d := data.(*types.SimpleOption) @@ -739,7 +740,7 @@ func (s *SectionParser) getTCPCheckData() (found bool, data interface{}) { return false, nil } -func (s *SectionParser) getRedisCheckData() (found bool, data interface{}) { +func (s *SectionParser) getRedisCheckData() (bool, any) { data, err := s.get("option redis-check", false) if err == nil { d := data.(*types.SimpleOption) @@ -750,7 +751,7 @@ func (s *SectionParser) getRedisCheckData() (found bool, data interface{}) { return false, nil } -func (s *SectionParser) getHttpchkData() (found bool, data interface{}) { +func (s *SectionParser) getHttpchkData() (bool, any) { data, err := s.get("option httpchk", false) if err == nil { d := data.(*types.OptionHttpchk) @@ -766,13 +767,13 @@ func (s *SectionParser) getHttpchkData() (found bool, data interface{}) { return false, nil } -func (s *SectionParser) setField(fieldName string, data interface{}) { +func (s *SectionParser) setField(fieldName string, data any) { objValue := reflect.ValueOf(s.Object).Elem() field := objValue.FieldByName(fieldName) field.Set(reflect.ValueOf(data)) } -func (s *SectionParser) stickTable() interface{} { +func (s *SectionParser) stickTable() any { data, err := s.get("stick-table", false) if err != nil { return nil @@ -805,7 +806,7 @@ func (s *SectionParser) stickTable() interface{} { return bst } -func (s *SectionParser) defaultServer() interface{} { +func (s *SectionParser) defaultServer() any { data, err := s.get("default-server", false) if err != nil { return nil @@ -818,7 +819,7 @@ func (s *SectionParser) defaultServer() interface{} { return dServer } -func (s *SectionParser) loadServerStateFromFile() interface{} { +func (s *SectionParser) loadServerStateFromFile() any { data, err := s.get("load-server-state-from-file", false) if err == nil { d := data.(*types.LoadServerStateFromFile) @@ -827,7 +828,7 @@ func (s *SectionParser) loadServerStateFromFile() interface{} { return nil } -func (s *SectionParser) errorFiles() interface{} { +func (s *SectionParser) errorFiles() any { data, err := s.get("errorfile", false) if err != nil { return nil @@ -851,7 +852,7 @@ func (s *SectionParser) errorFiles() interface{} { return dEFiles } -func (s *SectionParser) errorfilesFromHTTPErrors() interface{} { +func (s *SectionParser) errorfilesFromHTTPErrors() any { data, err := s.get("errorfiles", false) if err != nil { return nil @@ -871,7 +872,7 @@ func (s *SectionParser) errorfilesFromHTTPErrors() interface{} { return dEFiles } -func (s *SectionParser) hashType() interface{} { +func (s *SectionParser) hashType() any { data, err := s.get("hash-type", false) if err != nil { return nil @@ -884,7 +885,7 @@ func (s *SectionParser) hashType() interface{} { } } -func (s *SectionParser) cookie() interface{} { +func (s *SectionParser) cookie() any { data, err := s.get("cookie", false) if err != nil { return nil @@ -921,7 +922,7 @@ func (s *SectionParser) cookie() interface{} { } } -func (s *SectionParser) persistRule() interface{} { +func (s *SectionParser) persistRule() any { data, err := s.get("persist", false) if err != nil { return nil @@ -938,7 +939,7 @@ func (s *SectionParser) persistRule() interface{} { return p } -func (s *SectionParser) balance() interface{} { +func (s *SectionParser) balance() any { data, err := s.get("balance", false) if err != nil { return nil @@ -970,15 +971,14 @@ func (s *SectionParser) balance() interface{} { return b } -func (s *SectionParser) redispatch() interface{} { +func (s *SectionParser) redispatch() any { data, err := s.get("option redispatch", false) if err != nil { return nil } d := data.(*types.OptionRedispatch) - br := &models.Redispatch{} - if d.Interval != nil { - br.Interval = *d.Interval + br := &models.Redispatch{ + Interval: d.Interval, } if d.NoOption { d := "disabled" @@ -990,7 +990,7 @@ func (s *SectionParser) redispatch() interface{} { return br } -func (s *SectionParser) forwardfor() interface{} { +func (s *SectionParser) forwardfor() any { data, err := s.get("option forwardfor", false) if err != nil { return nil @@ -1006,7 +1006,7 @@ func (s *SectionParser) forwardfor() interface{} { return bff } -func (s *SectionParser) emailAlert() interface{} { +func (s *SectionParser) emailAlert() any { data, err := s.get("email-alert", false) if err != nil { return nil @@ -1031,7 +1031,7 @@ func (s *SectionParser) emailAlert() interface{} { return ea } -func (s *SectionParser) statsOptions() interface{} { //nolint:gocognit +func (s *SectionParser) statsOptions() any { //nolint:gocognit data, err := s.get("stats", false) if err != nil { return nil @@ -1114,7 +1114,7 @@ func (s *SectionParser) statsOptions() interface{} { //nolint:gocognit return opt } -func (s *SectionParser) monitorURI() interface{} { +func (s *SectionParser) monitorURI() any { data, err := s.get("monitor-uri", false) if err != nil { return nil @@ -1123,7 +1123,7 @@ func (s *SectionParser) monitorURI() interface{} { return models.MonitorURI(d.URI) } -func (s *SectionParser) monitorFail() interface{} { +func (s *SectionParser) monitorFail() any { if s.Section == parser.Frontends { data, err := s.get("monitor fail", false) if err != nil { @@ -1138,7 +1138,7 @@ func (s *SectionParser) monitorFail() interface{} { return nil } -func (s *SectionParser) compression() interface{} { //nolint:gocognit +func (s *SectionParser) compression() any { //nolint:gocognit compressionFound := false compression := &models.Compression{} @@ -1221,7 +1221,7 @@ func (s *SectionParser) compression() interface{} { //nolint:gocognit return nil } -func (s *SectionParser) clitcpkaIdle() interface{} { +func (s *SectionParser) clitcpkaIdle() any { data, err := s.get("clitcpka-idle", false) if err != nil { return nil @@ -1230,7 +1230,7 @@ func (s *SectionParser) clitcpkaIdle() interface{} { return misc.ParseTimeoutDefaultSeconds(d.Value) } -func (s *SectionParser) clitcpkaIntvl() interface{} { +func (s *SectionParser) clitcpkaIntvl() any { data, err := s.get("clitcpka-intvl", false) if err != nil { return nil @@ -1239,7 +1239,7 @@ func (s *SectionParser) clitcpkaIntvl() interface{} { return misc.ParseTimeoutDefaultSeconds(d.Value) } -func (s *SectionParser) srvtcpkaIdle() interface{} { +func (s *SectionParser) srvtcpkaIdle() any { data, err := s.get("srvtcpka-idle", false) if err != nil { return nil @@ -1248,7 +1248,7 @@ func (s *SectionParser) srvtcpkaIdle() interface{} { return misc.ParseTimeoutDefaultSeconds(d.Value) } -func (s *SectionParser) srvtcpkaIntvl() interface{} { +func (s *SectionParser) srvtcpkaIntvl() any { data, err := s.get("srvtcpka-intvl", false) if err != nil { return nil @@ -1257,7 +1257,7 @@ func (s *SectionParser) srvtcpkaIntvl() interface{} { return misc.ParseTimeoutDefaultSeconds(d.Value) } -func (s *SectionParser) serverStateFileName() interface{} { +func (s *SectionParser) serverStateFileName() any { data, err := s.get("server-state-file-name", false) if err != nil { return nil @@ -1266,7 +1266,7 @@ func (s *SectionParser) serverStateFileName() interface{} { return d.Value } -func (s *SectionParser) description() interface{} { +func (s *SectionParser) description() any { data, err := s.get("description", false) if err != nil { return nil @@ -1275,7 +1275,7 @@ func (s *SectionParser) description() interface{} { return d.Value } -func (s *SectionParser) errorloc302() interface{} { +func (s *SectionParser) errorloc302() any { data, err := s.get("errorloc302", false) if err != nil { return nil @@ -1295,7 +1295,7 @@ func (s *SectionParser) errorloc302() interface{} { return value } -func (s *SectionParser) errorloc303() interface{} { +func (s *SectionParser) errorloc303() any { data, err := s.get("errorloc303", false) if err != nil { return nil @@ -1315,7 +1315,7 @@ func (s *SectionParser) errorloc303() interface{} { return value } -func (s *SectionParser) httpRestirctReqHdrNames() interface{} { +func (s *SectionParser) httpRestirctReqHdrNames() any { data, err := s.get("option http-restrict-req-hdr-names", false) if err != nil { return nil @@ -1327,7 +1327,7 @@ func (s *SectionParser) httpRestirctReqHdrNames() interface{} { return d.Policy } -func (s *SectionParser) defaultBind() interface{} { +func (s *SectionParser) defaultBind() any { data, err := s.get("default-bind", false) if err != nil { return nil @@ -1339,7 +1339,7 @@ func (s *SectionParser) defaultBind() interface{} { } } -func (s *SectionParser) httpSendNameHeader() interface{} { +func (s *SectionParser) httpSendNameHeader() any { if s.Section == parser.Defaults || s.Section == parser.Backends { data, err := s.get("http-send-name-header", false) if err != nil { @@ -1354,7 +1354,7 @@ func (s *SectionParser) httpSendNameHeader() interface{} { return nil } -func (s *SectionParser) forcePersistList() interface{} { +func (s *SectionParser) forcePersistList() any { if s.Section != parser.Backends { return nil } @@ -1380,7 +1380,7 @@ func (s *SectionParser) forcePersistList() interface{} { return items } -func (s *SectionParser) ignorePersistList() interface{} { +func (s *SectionParser) ignorePersistList() any { if s.Section != parser.Backends { return nil } @@ -1406,7 +1406,7 @@ func (s *SectionParser) ignorePersistList() interface{} { return items } -func (s *SectionParser) source() interface{} { +func (s *SectionParser) source() any { if s.Section == parser.Backends || s.Section == parser.Defaults { data, err := s.get("source", false) if err != nil { @@ -1441,7 +1441,7 @@ func (s *SectionParser) source() interface{} { return nil } -func (s *SectionParser) shards() interface{} { +func (s *SectionParser) shards() any { if s.Section == parser.Peers { data, err := s.get("shards", false) if err != nil { @@ -1456,7 +1456,7 @@ func (s *SectionParser) shards() interface{} { return nil } -func (s *SectionParser) originalto() interface{} { +func (s *SectionParser) originalto() any { data, err := s.get("option originalto", false) if err != nil { return nil @@ -1473,7 +1473,7 @@ func (s *SectionParser) originalto() interface{} { // SectionObject represents a configuration section type SectionObject struct { - Object interface{} + Object any Parser parser.Parser Section parser.Section Name string @@ -1481,7 +1481,7 @@ type SectionObject struct { } // CreateEditSection creates or updates a section in the parser based on the provided object -func CreateEditSection(object interface{}, section parser.Section, pName string, p parser.Parser, opt *options.ConfigurationOptions) error { +func CreateEditSection(object any, section parser.Section, pName string, p parser.Parser, opt *options.ConfigurationOptions) error { so := SectionObject{ Object: object, Section: section, @@ -1498,7 +1498,7 @@ func (s *SectionObject) CreateEditSection() error { if objValue.Kind() == reflect.Ptr { objValue = reflect.ValueOf(s.Object).Elem() } - for i := 0; i < objValue.NumField(); i++ { + for i := range objValue.NumField() { typeField := objValue.Type().Field(i) field := objValue.FieldByName(typeField.Name) if typeField.Name != "Name" && typeField.Name != "ID" { @@ -1531,14 +1531,14 @@ func (s *SectionObject) setFieldValue(fieldName string, field reflect.Value) err return err } - return errors.Errorf("Cannot parse option for %s %s: %s", s.Section, s.Name, fieldName) + return fmt.Errorf("cannot parse option for %s %s: %s", s.Section, s.Name, fieldName) } -func (s *SectionObject) checkParams(fieldName string) (match bool) { +func (s *SectionObject) checkParams(fieldName string) bool { return s.Section != parser.FCGIApp && strings.HasSuffix(fieldName, "Params") } -func (s *SectionObject) checkSpecialFields(fieldName string, field reflect.Value) (match bool, err error) { //nolint:gocyclo,cyclop +func (s *SectionObject) checkSpecialFields(fieldName string, field reflect.Value) (bool, error) { //nolint:gocyclo,cyclop switch fieldName { case "Shard": return true, s.shard(field) @@ -1651,7 +1651,7 @@ func (s *SectionObject) checkSpecialFields(fieldName string, field reflect.Value } } -func (s *SectionObject) checkTimeouts(fieldName string, field reflect.Value) (match bool, err error) { +func (s *SectionObject) checkTimeouts(fieldName string, field reflect.Value) (bool, error) { if strings.HasSuffix(fieldName, "Timeout") { if pName := translateTimeout(fieldName); s.Parser.HasParser(s.Section, pName) { if valueIsNil(field) { @@ -1671,8 +1671,8 @@ func (s *SectionObject) checkTimeouts(fieldName string, field reflect.Value) (ma return false, nil } -func (s *SectionObject) checkOptions(fieldName string, field reflect.Value) (match bool, err error) { - if pName := fmt.Sprintf("option %s", misc.DashCase(fieldName)); s.Parser.HasParser(s.Section, pName) { +func (s *SectionObject) checkOptions(fieldName string, field reflect.Value) (bool, error) { + if pName := "option " + misc.DashCase(fieldName); s.Parser.HasParser(s.Section, pName) { if valueIsNil(field) { if err := s.set(pName, nil); err != nil { return true, err @@ -1693,7 +1693,7 @@ func (s *SectionObject) checkOptions(fieldName string, field reflect.Value) (mat return false, nil } -func (s *SectionObject) checkSingleLine(fieldName string, field reflect.Value) (match bool, err error) { +func (s *SectionObject) checkSingleLine(fieldName string, field reflect.Value) (bool, error) { if pName := misc.DashCase(fieldName); s.Parser.HasParser(s.Section, pName) { if valueIsNil(field) { if err := s.set(pName, nil); err != nil { @@ -1703,7 +1703,7 @@ func (s *SectionObject) checkSingleLine(fieldName string, field reflect.Value) ( } d := translateToParserData(field) if d == nil { - return true, errors.Errorf("Cannot parse type for %s %s: %s", s.Section, s.Name, fieldName) + return true, fmt.Errorf("cannot parse type for %s %s: %s", s.Section, s.Name, fieldName) } if err := s.set(pName, d); err != nil { return true, err @@ -1713,7 +1713,7 @@ func (s *SectionObject) checkSingleLine(fieldName string, field reflect.Value) ( return false, nil } -func (s *SectionObject) set(attribute string, data interface{}) error { +func (s *SectionObject) set(attribute string, data any) error { return s.Parser.Set(s.Section, s.Name, attribute, data) } @@ -1828,7 +1828,7 @@ func (s *SectionObject) httpReuse(field reflect.Value) error { func (s *SectionObject) httpConnectionMode(field reflect.Value) error { for _, opt := range []string{"httpclose", "http-server-close", "http-keep-alive"} { - attribute := fmt.Sprintf("option %s", opt) + attribute := "option " + opt if err := s.set(attribute, nil); err != nil { return err @@ -2080,7 +2080,7 @@ func (s *SectionObject) getHTTPChkData() (common.ParserData, error) { }, nil } -func (s *SectionObject) getFieldByName(fieldName string) interface{} { +func (s *SectionObject) getFieldByName(fieldName string) any { objValue := reflect.ValueOf(s.Object).Elem() elem := objValue.FieldByName(fieldName) if elem.IsNil() { @@ -2137,7 +2137,7 @@ func (s *SectionObject) defaultServer(field reflect.Value) error { return misc.CreateTypeAssertError("default-server") } dServers := []types.DefaultServer{{}} - dServers[0].Params = serializeServerParams(ds.ServerParams, s.Options) + dServers[0].Params = SerializeServerParams(ds.ServerParams, s.Options) if err := s.set("default-server", dServers); err != nil { return err } @@ -2350,7 +2350,7 @@ func (s *SectionObject) redispatch(field reflect.Value) error { return misc.CreateTypeAssertError("option redispatch") } d := &types.OptionRedispatch{ - Interval: &br.Interval, + Interval: br.Interval, NoOption: false, } if *br.Enabled == "disabled" { @@ -2544,7 +2544,7 @@ func (s *SectionObject) statsOptions(field reflect.Value) error { for _, httpRequest := range opt.StatsHTTPRequests { reqType := *httpRequest.Type if reqType == "auth" && httpRequest.Realm != "" { - reqType = fmt.Sprintf("auth realm %s", httpRequest.Realm) + reqType = "auth realm " + httpRequest.Realm } s := &stats.HTTPRequest{ Type: reqType, @@ -2591,8 +2591,7 @@ func (s *SectionObject) compression(field reflect.Value) error { //nolint:gocogn err = s.set("compression direction", nil) if err != nil { // compression direction does not exist on Frontends - var setErr error - if errors.As(parser_errors.ErrAttributeNotFound, &setErr) { + if errors.Is(err, parser_errors.ErrAttributeNotFound) { return nil } return err @@ -2601,7 +2600,7 @@ func (s *SectionObject) compression(field reflect.Value) error { //nolint:gocogn } compression, ok := field.Elem().Interface().(models.Compression) if !ok { - return fmt.Errorf("error casting compression model") + return errors.New("error casting compression model") } if len(compression.Algorithms) > 0 { @@ -2886,7 +2885,7 @@ func (s *SectionObject) shard(field reflect.Value) error { } func (s *SectionObject) originalto(field reflect.Value) error { - if !(s.Section == parser.Defaults || s.Section == parser.Frontends || s.Section == parser.Backends) { + if s.Section != parser.Defaults && s.Section != parser.Frontends && s.Section != parser.Backends { return nil } if valueIsNil(field) { @@ -2921,7 +2920,7 @@ func (c *client) deleteSection(section parser.Section, name string, transactionI return c.SaveData(p, t, transactionID == "") } -func (c *client) editSection(section parser.Section, name string, data interface{}, transactionID string, version int64) error { +func (c *client) editSection(section parser.Section, name string, data any, transactionID string, version int64) error { p, t, err := c.loadDataForChange(transactionID, version) if err != nil { return err @@ -2939,7 +2938,7 @@ func (c *client) editSection(section parser.Section, name string, data interface return c.SaveData(p, t, transactionID == "") } -func (c *client) createSection(section parser.Section, name string, data interface{}, transactionID string, version int64) error { +func (c *client) createSection(section parser.Section, name string, data any, transactionID string, version int64) error { p, t, err := c.loadDataForChange(transactionID, version) if err != nil { return err @@ -3023,7 +3022,7 @@ func translateToParserData(field reflect.Value) common.ParserData { } } -func parseOption(d interface{}) interface{} { +func parseOption(d any) any { switch v := d.(type) { case *types.StringC: return v.Value @@ -3043,5 +3042,5 @@ func parseOption(d interface{}) interface{} { func translateTimeout(mName string) string { mName = strings.TrimSuffix(mName, "Timeout") - return fmt.Sprintf("timeout %s", misc.DashCase(mName)) + return "timeout " + misc.DashCase(mName) } diff --git a/configuration/convert/v2v3/convert_global.go b/configuration/convert/v2v3/convert_global.go new file mode 100644 index 00000000..64989aa7 --- /dev/null +++ b/configuration/convert/v2v3/convert_global.go @@ -0,0 +1,219 @@ +package v2v3 + +import ( + v2 "github.com/haproxytech/client-native/v5/models" + v3 "github.com/haproxytech/client-native/v6/models" +) + +func GlobalV2ToV3(v2g *v2.Global) (*v3.GlobalBase, error) { //nolint:maintidx + var v3g *v3.GlobalBase + // Global + daemon := v2g.Daemon == "enabled" + v3t, err := V2Tov3[v2.Global, v3.GlobalBase](v2g, "daemon") + if err != nil { + return nil, err + } + v3g = v3t + + // Fields restructured + // PerformanceOptions + performanceOptions, err := V2Tov3[v2.Global, v3.PerformanceOptions](v2g) + if err != nil { + return nil, err + } + if !performanceOptions.Equal(v3.PerformanceOptions{}) { + v3g.PerformanceOptions = performanceOptions + } + + // HTTPClientOptions + httpClientOptions := &v3.HTTPClientOptions{ + ResolversDisabled: v2g.HttpclientResolversDisabled, + ResolversID: v2g.HttpclientResolversID, + ResolversPrefer: v2g.HttpclientResolversPrefer, + Retries: v2g.HttpclientRetries, + SslCaFile: v2g.HttpclientSslCaFile, + SslVerify: v2g.HttpclientSslVerify, + TimeoutConnect: v2g.HttpclientTimeoutConnect, + } + if !httpClientOptions.Equal(v3.HTTPClientOptions{}) { + v3g.HTTPClientOptions = httpClientOptions + } + + // TuneQuicOptions + if v2g.TuneOptions != nil { + tuneQuicOptions := &v3.TuneQuicOptions{ + FrontendConnTxBuffersLimit: v2g.TuneOptions.QuicFrontendConnTxBuffersLimit, + FrontendMaxIdleTimeout: v2g.TuneOptions.QuicFrontendMaxIdleTimeout, + FrontendMaxStreamsBidi: v2g.TuneOptions.QuicFrontendMaxStreamsBidi, + MaxFrameLoss: v2g.TuneOptions.QuicMaxFrameLoss, + RetryThreshold: v2g.TuneOptions.QuicRetryThreshold, + SocketOwner: v2g.TuneOptions.QuicSocketOwner, + // ReorderRatio: not present in v2 + // ZeroCopyFwdSend: not present in v2 + } + if !tuneQuicOptions.Equal(v3.TuneQuicOptions{}) { + v3g.TuneQuicOptions = tuneQuicOptions + } + + // TuneVarsOptions + tuneVarsOptions := &v3.TuneVarsOptions{ + GlobalMaxSize: v2g.TuneOptions.VarsGlobalMaxSize, + ProcMaxSize: v2g.TuneOptions.VarsProcMaxSize, + ReqresMaxSize: v2g.TuneOptions.VarsReqresMaxSize, + SessMaxSize: v2g.TuneOptions.VarsSessMaxSize, + TxnMaxSize: v2g.TuneOptions.VarsTxnMaxSize, + } + if !tuneVarsOptions.Equal(v3.TuneVarsOptions{}) { + v3g.TuneVarsOptions = tuneVarsOptions + } + + // TuneZlibOptions + tuneZlibOptions := &v3.TuneZlibOptions{ + Memlevel: v2g.TuneOptions.ZlibMemlevel, + Windowsize: v2g.TuneOptions.ZlibWindowsize, + } + if !tuneZlibOptions.Equal(v3.TuneZlibOptions{}) { + v3g.TuneZlibOptions = tuneZlibOptions + } + + // TuneSslOptions + tuneSslOptions := &v3.TuneSslOptions{ + Cachesize: v2g.TuneOptions.SslCachesize, + CtxCacheSize: v2g.TuneOptions.SslCtxCacheSize, + CaptureBufferSize: v2g.TuneOptions.SslCaptureBufferSize, + DefaultDhParam: v2g.TuneOptions.SslDefaultDhParam, + ForcePrivateCache: v2g.TuneOptions.SslForcePrivateCache, + Keylog: v2g.TuneOptions.SslKeylog, + Lifetime: v2g.TuneOptions.SslLifetime, + Maxrecord: v2g.TuneOptions.SslMaxrecord, + OcspUpdateMaxDelay: v2g.TuneOptions.SslOcspUpdateMaxDelay, + OcspUpdateMinDelay: v2g.TuneOptions.SslOcspUpdateMinDelay, + } + if !tuneSslOptions.Equal(v3.TuneSslOptions{}) { + v3g.TuneSslOptions = tuneSslOptions + } + + // TuneLuaOptions + tuneLuaOptions := &v3.TuneLuaOptions{ + BurstTimeout: v2g.TuneOptions.LuaBurstTimeout, + ForcedYield: v2g.TuneOptions.LuaForcedYield, + LogLoggers: v2g.TuneOptions.LuaLogLoggers, + LogStderr: v2g.TuneOptions.LuaLogStderr, + // Maxmem: was a boolean + ServiceTimeout: v2g.TuneOptions.LuaServiceTimeout, + SessionTimeout: v2g.TuneOptions.LuaSessionTimeout, + TaskTimeout: v2g.TuneOptions.LuaTaskTimeout, + } + if !tuneLuaOptions.Equal(v3.TuneLuaOptions{}) { + v3g.TuneLuaOptions = tuneLuaOptions + } + + // TuneBufOptions + tuneBufferOptions := &v3.TuneBufferOptions{ + BuffersLimit: v2g.TuneOptions.BuffersLimit, + BuffersReserve: v2g.TuneOptions.BuffersReserve, + Bufsize: v2g.TuneOptions.Bufsize, + Pipesize: v2g.TuneOptions.Pipesize, + RcvbufBackend: v2g.TuneOptions.RcvbufBackend, + RcvbufClient: v2g.TuneOptions.RcvbufClient, + RcvbufFrontend: v2g.TuneOptions.RcvbufFrontend, + RcvbufServer: v2g.TuneOptions.RcvbufServer, + RecvEnough: v2g.TuneOptions.RecvEnough, + SndbufBackend: v2g.TuneOptions.SndbufBackend, + SndbufClient: v2g.TuneOptions.SndbufClient, + SndbufFrontend: v2g.TuneOptions.SndbufFrontend, + SndbufServer: v2g.TuneOptions.SndbufServer, + } + if !tuneBufferOptions.Equal(v3.TuneBufferOptions{}) { + v3g.TuneBufferOptions = tuneBufferOptions + } + } + + // SslOptions + v3engines, err := ListV2ToV3[v2.SslEngine, v3.SslEngine](v2g.SslEngines) + if err != nil { + return nil, err + } + sslOptions := &v3.SslOptions{ + SslEngines: v3engines, + CaBase: v2g.CaBase, + CrtBase: v2g.CrtBase, + DefaultBindCiphers: v2g.SslDefaultBindCiphers, + DefaultBindCiphersuites: v2g.SslDefaultBindCiphersuites, + DefaultBindClientSigalgs: v2g.SslDefaultBindClientSigalgs, + DefaultBindCurves: v2g.SslDefaultBindCurves, + DefaultBindOptions: v2g.SslDefaultBindOptions, + DefaultBindSigalgs: v2g.SslDefaultBindSigalgs, + DefaultServerCiphers: v2g.SslDefaultServerCiphers, + DefaultServerCiphersuites: v2g.SslDefaultServerCiphersuites, + DefaultServerClientSigalgs: v2g.SslDefaultServerClientSigalgs, + DefaultServerCurves: v2g.SslDefaultServerCurves, + DefaultServerOptions: v2g.SslDefaultServerOptions, + DefaultServerSigalgs: v2g.SslDefaultServerSigalgs, + DhParamFile: v2g.SslDhParamFile, + IssuersChainPath: v2g.IssuersChainPath, + LoadExtraFiles: v2g.SslLoadExtraFiles, + Maxsslconn: v2g.Maxsslconn, + Maxsslrate: v2g.Maxsslrate, + ModeAsync: v2g.SslModeAsync, + Propquery: v2g.SslPropquery, + Provider: v2g.SslProvider, + ProviderPath: v2g.SslProviderPath, + // SecurityLevel: not present in v2 + ServerVerify: v2g.SslServerVerify, + SkipSelfIssuedCa: v2g.SslSkipSelfIssuedCa, + } + if !sslOptions.Equal(v3.SslOptions{}) { + v3g.SslOptions = sslOptions + } + + // EnvironmentOptions + v3preset, err := ListV2ToV3[v2.PresetEnv, v3.PresetEnv](v2g.PresetEnvs) + if err != nil { + return nil, err + } + v3set, err := ListV2ToV3[v2.SetEnv, v3.SetEnv](v2g.SetEnvs) + if err != nil { + return nil, err + } + envOptions := &v3.EnvironmentOptions{ + PresetEnvs: v3preset, + SetEnvs: v3set, + Resetenv: v2g.Resetenv, + Unsetenv: v2g.Unsetenv, + } + if !envOptions.Equal(v3.EnvironmentOptions{}) { + v3g.EnvironmentOptions = envOptions + } + + // DebugOptions + debugOptions := &v3.DebugOptions{ + Anonkey: v2g.Anonkey, + Quiet: v2g.Quiet, + ZeroWarning: v2g.ZeroWarning, + } + if !debugOptions.Equal(v3.DebugOptions{}) { + v3g.DebugOptions = debugOptions + } + + // LuaOptions + luaLoad, err := ListV2ToV3[v2.LuaLoad, v3.LuaLoad](v2g.LuaLoads) + if err != nil { + return nil, err + } + luaPrependPath, err := ListV2ToV3[v2.LuaPrependPath, v3.LuaPrependPath](v2g.LuaPrependPath) + if err != nil { + return nil, err + } + luaOptions := &v3.LuaOptions{ + LoadPerThread: v2g.LuaLoadPerThread, + Loads: luaLoad, + PrependPath: luaPrependPath, + } + if !luaOptions.Equal(v3.LuaOptions{}) { + v3g.LuaOptions = luaOptions + } + + v3g.Daemon = daemon + return v3g, nil +} diff --git a/configuration/convert/v2v3/convert_v2_v3.go b/configuration/convert/v2v3/convert_v2_v3.go new file mode 100644 index 00000000..804b490f --- /dev/null +++ b/configuration/convert/v2v3/convert_v2_v3.go @@ -0,0 +1,153 @@ +package v2v3 + +import ( + "cmp" + "encoding/json" + "errors" + "reflect" + "slices" + + "github.com/haproxytech/client-native/v6/misc" +) + +// V2Tov3 converts a Structured type from v2 to v3 +// For example +// v3f, err := V2Tov3[v2.Frontend, models.Frontend](&v2s.Frontend) +// The conversion allows to have an evolving type v3: +// - extra fields would be ignored in the conversion, keeping the v2 fields converted +func V2Tov3[TV2, TV3 any](resource *TV2, skip ...string) (*TV3, error) { + original, err := json.Marshal(resource) + if err != nil { + return nil, err + } + originalMap := make(map[string]any) + err = json.Unmarshal(original, &originalMap) + if err != nil { + return nil, err + } + for _, s := range skip { + delete(originalMap, s) + } + versionj, err := json.Marshal(originalMap) + if err != nil { + return nil, err + } + var otherversion TV3 + err = json.Unmarshal(versionj, &otherversion) + if err != nil { + return nil, err + } + return &otherversion, nil +} + +func ListV2ToV3[TV2, TV3 any](listV2 []*TV2) ([]*TV3, error) { + SortListByIndex(listV2) + listV3 := make([]*TV3, len(listV2)) + for i, v := range listV2 { + resourceV3, err := V2Tov3[TV2, TV3](v) + if err != nil { + return nil, err + } + listV3[i] = resourceV3 + } + return listV3, nil +} + +func NamedResourceArrayToMap[T any](namedResource []*T) (map[string]T, error) { + return NamedResourceArrayToMapWithKey[T](namedResource, "Name") +} + +//nolint:nilnil +func NamedResourceArrayToMapWithKey[T any](namedResource []*T, key string) (map[string]T, error) { + if len(namedResource) == 0 { + return nil, nil + } + res := make(map[string]T) + for _, r := range namedResource { + name, err := getKey(r, key) + if err != nil { + return nil, err + } + res[name] = *r + } + return res, nil +} + +// getKey returns the value of the 'Name' field from any struct or pointer to struct using reflection. +// Constraint: the struct must have an exportable 'Name' field +func getKey(obj any, keyName string) (string, error) { + value := reflect.ValueOf(obj) + // If Pointer, first get the pointed value + if value.Kind() == reflect.Ptr { + value = value.Elem() + } + if value.Kind() != reflect.Struct { + return "", errors.New("object is not a struct") + } + nameField := value.FieldByName(keyName) + if !nameField.IsValid() || !nameField.CanInterface() { + return "", errors.New("object does not have an exportable 'Name' field") + } + name := nameField.Interface().(string) + return name, nil +} + +func SortListByIndex[T any](list []*T) { + slices.SortFunc(list, + func(a, b *T) int { + ia, _ := getIndex(a) + ib, _ := getIndex(b) + if ia == nil || ib == nil { + return -1 + } + return cmp.Compare(*ia, *ib) + }) +} + +func getIndex(obj any) (*int64, error) { + value := reflect.ValueOf(obj) + // If Pointer, first get the pointed value + if value.Kind() == reflect.Ptr { + value = value.Elem() + } + if value.Kind() != reflect.Struct { + return misc.Ptr[int64](-1), errors.New("object is not a struct") + } + nameField := value.FieldByName("Index") + if !nameField.IsValid() || !nameField.CanInterface() { + return misc.Ptr[int64](-1), errors.New("object does not have an exportable 'Index' field") + } + index := nameField.Interface().(*int64) + return index, nil +} + +func NamedResourceArrayV2ToMapV3[TV2, TV3 any](namedResource []*TV2, options ...optionV2ToV3) (map[string]TV3, error) { + var res map[string]TV3 + if len(namedResource) == 0 { + return res, nil + } + keyName := "Name" + if len(options) > 0 { + keyName = options[0].keyName + } + res = make(map[string]TV3) + for _, r := range namedResource { + name, err := getKey(r, keyName) + if err != nil { + return nil, err + } + + // version change + otherversion, err := V2Tov3[TV2, TV3](r) + if err != nil { + return nil, err + } + + res[name] = *otherversion + } + return res, nil +} + +type optionV2ToV3 struct { + keyName string +} diff --git a/configuration/dgram_bind.go b/configuration/dgram_bind.go index f13914fe..ad50d23b 100644 --- a/configuration/dgram_bind.go +++ b/configuration/dgram_bind.go @@ -223,7 +223,6 @@ func ParseDgramBind(ondiskDgramBind types.DgramBind) *models.DgramBind { } case n > 0: b.Address = addSlice[0] - } } for _, p := range ondiskDgramBind.Params { diff --git a/configuration/fcgi_app.go b/configuration/fcgi_app.go index 771494b6..dc4cf663 100644 --- a/configuration/fcgi_app.go +++ b/configuration/fcgi_app.go @@ -333,82 +333,82 @@ func (c *client) CreateFCGIApplication(data *models.FCGIApp, transactionID strin } //nolint:gocognit -func SerializeFCGIAppSection(p parser.Parser, data *models.FCGIApp) (err error) { +func SerializeFCGIAppSection(p parser.Parser, data *models.FCGIApp) error { if data == nil { - return fmt.Errorf("empty FCGI app") + return errors.New("empty FCGI app") } if data.Docroot == nil && len(*data.Docroot) == 0 { - return fmt.Errorf("missing required docroot") - } else if err = p.Set(parser.FCGIApp, data.Name, "docroot", types.StringC{Value: *data.Docroot}); err != nil { + return errors.New("missing required docroot") + } else if err := p.Set(parser.FCGIApp, data.Name, "docroot", types.StringC{Value: *data.Docroot}); err != nil { return err } - if err = p.Set(parser.FCGIApp, data.Name, "option get-values", serializeSimpleOption(data.GetValues)); err != nil { + if err := p.Set(parser.FCGIApp, data.Name, "option get-values", serializeSimpleOption(data.GetValues)); err != nil { return err } if len(data.Index) > 0 { - if err = p.Set(parser.FCGIApp, data.Name, "index", types.StringC{Value: data.Index}); err != nil { + if err := p.Set(parser.FCGIApp, data.Name, "index", types.StringC{Value: data.Index}); err != nil { return err } } else { - if err = p.Set(parser.FCGIApp, data.Name, "index", nil); err != nil { + if err := p.Set(parser.FCGIApp, data.Name, "index", nil); err != nil { return err } } - if err = p.Set(parser.FCGIApp, data.Name, "option keep-conn", serializeSimpleOption(data.KeepConn)); err != nil { + if err := p.Set(parser.FCGIApp, data.Name, "option keep-conn", serializeSimpleOption(data.KeepConn)); err != nil { return err } - if err = p.Set(parser.FCGIApp, data.Name, "log-stderr", nil); err != nil { + if err := p.Set(parser.FCGIApp, data.Name, "log-stderr", nil); err != nil { return err } for _, i := range serializeLogStderr(data.LogStderrs) { - if err = p.Set(parser.FCGIApp, data.Name, "log-stderr", i); err != nil { + if err := p.Set(parser.FCGIApp, data.Name, "log-stderr", i); err != nil { return err } } if data.MaxReqs > 0 { - if err = p.Set(parser.FCGIApp, data.Name, "option max-reqs", types.OptionMaxReqs{Reqs: data.MaxReqs}); err != nil { + if err := p.Set(parser.FCGIApp, data.Name, "option max-reqs", types.OptionMaxReqs{Reqs: data.MaxReqs}); err != nil { return err } } else { - if err = p.Set(parser.FCGIApp, data.Name, "option max-reqs", nil); err != nil { + if err := p.Set(parser.FCGIApp, data.Name, "option max-reqs", nil); err != nil { return err } } - if err = p.Set(parser.FCGIApp, data.Name, "option mpxs-conns", serializeSimpleOption(data.GetValues)); err != nil { + if err := p.Set(parser.FCGIApp, data.Name, "option mpxs-conns", serializeSimpleOption(data.GetValues)); err != nil { return err } - if err = p.Set(parser.FCGIApp, data.Name, "pass-header", nil); err != nil { + if err := p.Set(parser.FCGIApp, data.Name, "pass-header", nil); err != nil { return err } for _, i := range serializePassHeader(data.PassHeaders) { - if err = p.Set(parser.FCGIApp, data.Name, "pass-header", i); err != nil { + if err := p.Set(parser.FCGIApp, data.Name, "pass-header", i); err != nil { return err } } if len(data.PathInfo) > 0 { - if err = p.Set(parser.FCGIApp, data.Name, "path-info", types.StringC{Value: data.PathInfo}); err != nil { + if err := p.Set(parser.FCGIApp, data.Name, "path-info", types.StringC{Value: data.PathInfo}); err != nil { return err } } else { - if err = p.Set(parser.FCGIApp, data.Name, "path-info", nil); err != nil { + if err := p.Set(parser.FCGIApp, data.Name, "path-info", nil); err != nil { return err } } - if err = p.Set(parser.FCGIApp, data.Name, "set-param", nil); err != nil { + if err := p.Set(parser.FCGIApp, data.Name, "set-param", nil); err != nil { return err } for _, i := range serializeSetParam(data.SetParams) { - if err = p.Set(parser.FCGIApp, data.Name, "set-param", i); err != nil { + if err := p.Set(parser.FCGIApp, data.Name, "set-param", i); err != nil { return err } } diff --git a/configuration/filter.go b/configuration/filter.go index e22e6efe..580458c7 100644 --- a/configuration/filter.go +++ b/configuration/filter.go @@ -75,9 +75,10 @@ func (c *client) GetFilter(id int64, parentType, parentName string, transactionI } var section parser.Section - if parentType == BackendParentName { + switch parentType { + case BackendParentName: section = parser.Backends - } else if parentType == FrontendParentName { + case FrontendParentName: section = parser.Frontends } @@ -100,9 +101,10 @@ func (c *client) DeleteFilter(id int64, parentType string, parentName string, tr } var section parser.Section - if parentType == BackendParentName { + switch parentType { + case BackendParentName: section = parser.Backends - } else if parentType == FrontendParentName { + case FrontendParentName: section = parser.Frontends } @@ -129,9 +131,10 @@ func (c *client) CreateFilter(id int64, parentType string, parentName string, da } var section parser.Section - if parentType == BackendParentName { + switch parentType { + case BackendParentName: section = parser.Backends - } else if parentType == FrontendParentName { + case FrontendParentName: section = parser.Frontends } diff --git a/configuration/global.go b/configuration/global.go index 28bf7f22..e48c985e 100644 --- a/configuration/global.go +++ b/configuration/global.go @@ -1004,7 +1004,7 @@ func parseFiftyOneDegreesOptions(p parser.Parser) (*models.FiftyOneDegreesOption if err != nil { return nil, err } - if option != "" { + if optionInt != 0 { isEmpty = false options.CacheSize = optionInt } @@ -2164,6 +2164,18 @@ func ParseGlobalSection(p parser.Parser) (*models.Global, error) { //nolint:goco } global.H1CaseAdjustFile = h1CaseAdjustFile + h1AcceptPayloadWithAnyMethod, err := parseBoolOption(p, "h1-accept-payload-with-any-method") + if err != nil { + return nil, err + } + global.H1AcceptPayloadWithAnyMethod = h1AcceptPayloadWithAnyMethod + + h1DoNotCloseOnInsecureTransferEncoding, err := parseBoolOption(p, "h1-do-not-close-on-insecure-transfer-encoding") + if err != nil { + return nil, err + } + global.H1DoNotCloseOnInsecureTransferEncoding = h1DoNotCloseOnInsecureTransferEncoding + h2WorkaroundBogusWebsocketClients, err := parseBoolOption(p, "h2-workaround-bogus-websocket-clients") if err != nil { return nil, err @@ -2358,6 +2370,12 @@ func ParseGlobalSection(p parser.Parser) (*models.Global, error) { //nolint:goco } global.SslOptions = sslOptions + statsFile, err := parseStringOption(p, "stats-file") + if err != nil { + return nil, err + } + global.StatsFile = statsFile + statsMaxconn, err := parseInt64POption(p, "stats maxconn") if err != nil { return nil, err @@ -2486,7 +2504,7 @@ func serializeEnvironmentOptions(p parser.Parser, options *models.EnvironmentOpt options = &models.EnvironmentOptions{} } presetEnvs := []types.StringKeyValueC{} - if options.PresetEnvs != nil && len(options.PresetEnvs) > 0 { + if len(options.PresetEnvs) > 0 { for _, presetEnv := range options.PresetEnvs { if presetEnv != nil { env := types.StringKeyValueC{ @@ -2502,7 +2520,7 @@ func serializeEnvironmentOptions(p parser.Parser, options *models.EnvironmentOpt } setEnvs := []types.StringKeyValueC{} - if options.SetEnvs != nil && len(options.SetEnvs) > 0 { + if len(options.SetEnvs) > 0 { for _, presetEnv := range options.SetEnvs { if presetEnv != nil { env := types.StringKeyValueC{ @@ -2605,7 +2623,7 @@ func serializeSSLOptions(p parser.Parser, options *models.SslOptions) error { // } sslEngines := []types.SslEngine{} - if options.SslEngines != nil && len(options.SslEngines) > 0 { + if len(options.SslEngines) > 0 { for _, sslEngine := range options.SslEngines { if sslEngine != nil { se := types.SslEngine{ @@ -2855,20 +2873,20 @@ func serializeLuaOptions(p parser.Parser, options *models.LuaOptions) error { } func SerializeGlobalSection(p parser.Parser, data *models.Global, opt *options.ConfigurationOptions) error { //nolint:gocognit,gocyclo,cyclop,maintidx - cpuMaps := []types.CPUMap{} - for _, cpuMap := range data.CPUMaps { + cpuMaps := make([]types.CPUMap, len(data.CPUMaps)) + for i, cpuMap := range data.CPUMaps { cm := types.CPUMap{ Process: *cpuMap.Process, CPUSet: *cpuMap.CPUSet, } - cpuMaps = append(cpuMaps, cm) + cpuMaps[i] = cm } if err := p.Set(parser.Global, parser.GlobalSectionName, "cpu-map", cpuMaps); err != nil { return err } pH1CaseAdjusts := []types.H1CaseAdjust{} - if data.H1CaseAdjusts != nil && len(data.H1CaseAdjusts) > 0 { + if len(data.H1CaseAdjusts) > 0 { for _, caseAdjust := range data.H1CaseAdjusts { if caseAdjust != nil && caseAdjust.From != nil && caseAdjust.To != nil { ca := types.H1CaseAdjust{From: *caseAdjust.From, To: *caseAdjust.To} @@ -2894,7 +2912,7 @@ func SerializeGlobalSection(p parser.Parser, data *models.Global, opt *options.C } setVars := []types.SetVar{} - if data.SetVars != nil && len(data.SetVars) > 0 { + if len(data.SetVars) > 0 { for _, setVar := range data.SetVars { if setVar != nil { sv := types.SetVar{ @@ -2910,7 +2928,7 @@ func SerializeGlobalSection(p parser.Parser, data *models.Global, opt *options.C } setVarFmts := []types.SetVarFmt{} - if data.SetVarFmts != nil && len(data.SetVarFmts) > 0 { + if len(data.SetVarFmts) > 0 { for _, setVarFmt := range data.SetVarFmts { if setVarFmt != nil { svf := types.SetVarFmt{ @@ -2926,7 +2944,7 @@ func SerializeGlobalSection(p parser.Parser, data *models.Global, opt *options.C } threadGroupLines := []types.ThreadGroup{} - if data.ThreadGroupLines != nil && len(data.ThreadGroupLines) > 0 { + if len(data.ThreadGroupLines) > 0 { for _, threadGroupLine := range data.ThreadGroupLines { if threadGroupLine != nil { tgl := types.ThreadGroup{ @@ -3009,6 +3027,14 @@ func SerializeGlobalSection(p parser.Parser, data *models.Global, opt *options.C return err } + if err := serializeBoolOption(p, "h1-accept-payload-with-any-method", data.H1AcceptPayloadWithAnyMethod); err != nil { + return err + } + + if err := serializeBoolOption(p, "h1-do-not-close-on-insecure-transfer-encoding", data.H1DoNotCloseOnInsecureTransferEncoding); err != nil { + return err + } + if err := serializeTimeoutOption(p, "hard-stop-after", data.HardStopAfter, opt); err != nil { return err } @@ -3022,7 +3048,7 @@ func SerializeGlobalSection(p parser.Parser, data *models.Global, opt *options.C } httpErrCodes := []types.HTTPErrCodes{} - if data.HTTPErrCodes != nil && len(data.HTTPErrCodes) > 0 { + if len(data.HTTPErrCodes) > 0 { for _, errCodes := range data.HTTPErrCodes { if errCodes != nil { errCode := types.HTTPErrCodes{ @@ -3039,7 +3065,7 @@ func SerializeGlobalSection(p parser.Parser, data *models.Global, opt *options.C } httpFailCodes := []types.HTTPFailCodes{} - if data.HTTPFailCodes != nil && len(data.HTTPFailCodes) > 0 { + if len(data.HTTPFailCodes) > 0 { for _, failCodes := range data.HTTPFailCodes { if failCodes != nil { failCode := types.HTTPFailCodes{ @@ -3106,9 +3132,10 @@ func SerializeGlobalSection(p parser.Parser, data *models.Global, opt *options.C } numaCPUMapping := &types.NumaCPUMapping{} - if data.NumaCPUMapping == "" { + switch data.NumaCPUMapping { + case "": numaCPUMapping = nil - } else if data.NumaCPUMapping == "disabled" { + case "disabled": numaCPUMapping.NoOption = true } if err := p.Set(parser.Global, parser.GlobalSectionName, "numa-cpu-mapping", numaCPUMapping); err != nil { @@ -3147,6 +3174,10 @@ func SerializeGlobalSection(p parser.Parser, data *models.Global, opt *options.C return err } + if err := serializeStringOption(p, "stats-file", data.StatsFile); err != nil { + return err + } + if err := serializeInt64POption(p, "stats maxconn", data.StatsMaxconn); err != nil { return err } @@ -3251,7 +3282,6 @@ func serializeOcspUpdateOptions(p parser.Parser, options *models.OcspUpdateOptio if options.Httpproxy.Port != nil { addr = fmt.Sprintf("%s:%d", addr, *options.Httpproxy.Port) } - } if err := serializeStringOption(p, "ocsp-update.httpproxy", addr); err != nil { return err diff --git a/configuration/http_after_response_rule.go b/configuration/http_after_response_rule.go index d35ab971..8f767deb 100644 --- a/configuration/http_after_response_rule.go +++ b/configuration/http_after_response_rule.go @@ -211,7 +211,6 @@ func (c *client) ReplaceHTTPAfterResponseRules(parentType string, parentName str } for i, newHarRule := range data { - s, err := SerializeHTTPAfterRule(*newHarRule) if err != nil { return err @@ -469,7 +468,8 @@ func ParseHTTPAfterRule(f types.Action) (*models.HTTPAfterResponseRule, error) { return nil, nil //nolint:nilnil } -func SerializeHTTPAfterRule(f models.HTTPAfterResponseRule) (rule types.Action, err error) { //nolint:ireturn +func SerializeHTTPAfterRule(f models.HTTPAfterResponseRule) (types.Action, error) { //nolint:ireturn + var rule types.Action switch f.Type { case "add-header": rule = &http_actions.AddHeader{ @@ -625,5 +625,5 @@ func SerializeHTTPAfterRule(f models.HTTPAfterResponseRule) (rule types.Action, CondTest: f.CondTest, } } - return rule, err + return rule, nil } diff --git a/configuration/http_check.go b/configuration/http_check.go index 936d482f..4bb6cde8 100644 --- a/configuration/http_check.go +++ b/configuration/http_check.go @@ -17,7 +17,6 @@ package configuration import ( "errors" - "fmt" "strconv" "strings" @@ -76,9 +75,10 @@ func (c *client) GetHTTPCheck(id int64, parentType string, parentName string, tr } var section parser.Section - if parentType == BackendParentName { + switch parentType { + case BackendParentName: section = parser.Backends - } else if parentType == DefaultsParentName { + case DefaultsParentName: section = parser.Defaults if parentName == "" { parentName = parser.DefaultSectionName @@ -106,9 +106,10 @@ func (c *client) DeleteHTTPCheck(id int64, parentType string, parentName string, } var section parser.Section - if parentType == BackendParentName { + switch parentType { + case BackendParentName: section = parser.Backends - } else if parentType == DefaultsParentName { + case DefaultsParentName: section = parser.Defaults if parentName == "" { parentName = parser.DefaultSectionName @@ -138,9 +139,10 @@ func (c *client) CreateHTTPCheck(id int64, parentType string, parentName string, } var section parser.Section - if parentType == BackendParentName { + switch parentType { + case BackendParentName: section = parser.Backends - } else if parentType == DefaultsParentName { + case DefaultsParentName: section = parser.Defaults if parentName == "" { parentName = parser.DefaultSectionName @@ -172,9 +174,10 @@ func (c *client) EditHTTPCheck(id int64, parentType string, parentName string, d return err } var section parser.Section - if parentType == BackendParentName { + switch parentType { + case BackendParentName: section = parser.Backends - } else if parentType == DefaultsParentName { + case DefaultsParentName: section = parser.Defaults if parentName == "" { parentName = parser.DefaultSectionName @@ -217,9 +220,10 @@ func (c *client) ReplaceHTTPChecks(parentType string, parentName string, data mo } var section parser.Section - if parentType == BackendParentName { + switch parentType { + case BackendParentName: section = parser.Backends - } else if parentType == DefaultsParentName { + case DefaultsParentName: section = parser.Defaults if parentName == "" { parentName = parser.DefaultSectionName @@ -257,7 +261,7 @@ func ParseHTTPChecks(t, pName string, p parser.Parser) (models.HTTPChecks, error case BackendParentName: section = parser.Backends default: - return nil, NewConfError(ErrValidationError, fmt.Sprintf("unsupported section in http_check: %s", t)) + return nil, NewConfError(ErrValidationError, "unsupported section in http_error: "+t) } var checks models.HTTPChecks @@ -281,7 +285,8 @@ func ParseHTTPChecks(t, pName string, p parser.Parser) (models.HTTPChecks, error return checks, nil } -func ParseHTTPCheck(f types.Action) (check *models.HTTPCheck, err error) { +func ParseHTTPCheck(f types.Action) (*models.HTTPCheck, error) { + var check *models.HTTPCheck switch v := f.(type) { case *http_actions.CheckComment: check = &models.HTTPCheck{ @@ -342,15 +347,15 @@ func ParseHTTPCheck(f types.Action) (check *models.HTTPCheck, err error) { BodyLogFormat: v.BodyLogFormat, CheckComment: v.CheckComment, } - headers := []*models.ReturnHeader{} - for _, h := range v.Header { + headers := make([]*models.ReturnHeader, len(v.Header)) + for i, h := range v.Header { name := h.Name value := h.Format header := &models.ReturnHeader{ Name: &name, Fmt: &value, } - headers = append(headers, header) + headers[i] = header } check.CheckHeaders = headers case *http_actions.CheckSendState: @@ -382,7 +387,7 @@ func ParseHTTPCheck(f types.Action) (check *models.HTTPCheck, err error) { return check, nil } -func SerializeHTTPCheck(f models.HTTPCheck) (action types.Action, err error) { //nolint:ireturn +func SerializeHTTPCheck(f models.HTTPCheck) (types.Action, error) { //nolint:ireturn switch f.Type { case models.HTTPCheckTypeComment: return &http_actions.CheckComment{ diff --git a/configuration/http_error_rule.go b/configuration/http_error_rule.go index 49727a2a..e186f88e 100644 --- a/configuration/http_error_rule.go +++ b/configuration/http_error_rule.go @@ -271,7 +271,7 @@ func ParseHTTPErrorRules(t, pName string, p parser.Parser) (models.HTTPErrorRule case BackendParentName: section = parser.Backends default: - return nil, NewConfError(ErrValidationError, fmt.Sprintf("unsupported section in http_error: %s", t)) + return nil, NewConfError(ErrValidationError, "unsupported section in http_error: "+t) } var httpErrRules models.HTTPErrorRules @@ -312,7 +312,7 @@ func ParseHTTPErrorRule(f types.Action) *models.HTTPErrorRule { } } -func SerializeHTTPErrorRule(f models.HTTPErrorRule) (rule types.Action, err error) { //nolint:ireturn +func SerializeHTTPErrorRule(f models.HTTPErrorRule) (types.Action, error) { //nolint:ireturn if f.Type != "status" { return nil, NewConfError(ErrValidationError, fmt.Sprintf("unsupported action %s in http_error", f.Type)) } @@ -321,7 +321,7 @@ func SerializeHTTPErrorRule(f models.HTTPErrorRule) (rule types.Action, err erro if f.ReturnContentType != nil { contentType = *f.ReturnContentType } - rule = &http_actions.Status{ + rule := &http_actions.Status{ Status: &f.Status, ContentType: contentType, ContentFormat: f.ReturnContentFormat, diff --git a/configuration/http_errors_section.go b/configuration/http_errors_section.go index d3aeba83..89504f82 100644 --- a/configuration/http_errors_section.go +++ b/configuration/http_errors_section.go @@ -15,6 +15,7 @@ package configuration import ( + "errors" "fmt" "strconv" @@ -159,7 +160,7 @@ func (c *client) EditHTTPErrorsSection(name string, data *models.HTTPErrorsSecti // SerializeProgramSection saves a single http-errors section's data in the configuration. func SerializeHTTPErrorsSection(p parser.Parser, data *models.HTTPErrorsSection) error { if data == nil { - return fmt.Errorf("empty http-errors section") + return errors.New("empty http-errors section") } for _, ef := range data.ErrorFiles { diff --git a/configuration/http_request_rule.go b/configuration/http_request_rule.go index b6f80c0d..a3ded9b1 100644 --- a/configuration/http_request_rule.go +++ b/configuration/http_request_rule.go @@ -256,7 +256,8 @@ func ParseHTTPRequestRules(t, pName string, p parser.Parser) (models.HTTPRequest return httpReqRules, nil } -func ParseHTTPRequestRule(f types.Action) (rule *models.HTTPRequestRule, err error) { //nolint:gocyclo,cyclop,maintidx,gocognit +func ParseHTTPRequestRule(f types.Action) (*models.HTTPRequestRule, error) { //nolint:gocyclo,cyclop,maintidx,gocognit + var rule *models.HTTPRequestRule switch v := f.(type) { case *http_actions.AddACL: rule = &models.HTTPRequestRule{ @@ -335,6 +336,10 @@ func ParseHTTPRequestRule(f types.Action) (rule *models.HTTPRequestRule, err err CondTest: v.CondTest, } case *http_actions.Deny: + var returnContentTypePtr *string + if v.ContentType != "" { + returnContentTypePtr = &v.ContentType + } rule = &models.HTTPRequestRule{ Type: "deny", Cond: v.Cond, @@ -342,7 +347,7 @@ func ParseHTTPRequestRule(f types.Action) (rule *models.HTTPRequestRule, err err ReturnHeaders: actionHdr2ModelHdr(v.Hdrs), ReturnContent: v.Content, ReturnContentFormat: v.ContentFormat, - ReturnContentType: &v.ContentType, + ReturnContentType: returnContentTypePtr, DenyStatus: v.Status, } case *http_actions.DisableL7Retry: @@ -388,10 +393,11 @@ func ParseHTTPRequestRule(f types.Action) (rule *models.HTTPRequestRule, err err } case *http_actions.Redirect: var codePtr *int64 - var code int64 if v.Code != "" { - if code, err = strconv.ParseInt(v.Code, 10, 64); err == nil { + if code, err := strconv.ParseInt(v.Code, 10, 64); err == nil { codePtr = &code + } else { + return nil, err } } rule = &models.HTTPRequestRule{ @@ -452,13 +458,17 @@ func ParseHTTPRequestRule(f types.Action) (rule *models.HTTPRequestRule, err err CondTest: v.CondTest, } case *http_actions.Return: + var returnContentTypePtr *string + if v.ContentType != "" { + returnContentTypePtr = &v.ContentType + } rule = &models.HTTPRequestRule{ Cond: v.Cond, CondTest: v.CondTest, ReturnHeaders: actionHdr2ModelHdr(v.Hdrs), ReturnContent: v.Content, ReturnContentFormat: v.ContentFormat, - ReturnContentType: &v.ContentType, + ReturnContentType: returnContentTypePtr, ReturnStatusCode: v.Status, Type: "return", } @@ -701,6 +711,7 @@ func ParseHTTPRequestRule(f types.Action) (rule *models.HTTPRequestRule, err err } case *actions.SilentDrop: rule = &models.HTTPRequestRule{ + RstTTL: v.RstTTL, Type: "silent-drop", Cond: v.Cond, CondTest: v.CondTest, @@ -796,10 +807,11 @@ func ParseHTTPRequestRule(f types.Action) (rule *models.HTTPRequestRule, err err } } - return rule, err + return rule, nil } -func SerializeHTTPRequestRule(f models.HTTPRequestRule, opt *options.ConfigurationOptions) (rule types.Action, err error) { //nolint:gocyclo,gocognit,ireturn,cyclop,maintidx +func SerializeHTTPRequestRule(f models.HTTPRequestRule, opt *options.ConfigurationOptions) (types.Action, error) { //nolint:gocyclo,gocognit,ireturn,cyclop,maintidx + var rule types.Action switch f.Type { case "add-acl": rule = &http_actions.AddACL{ @@ -1200,6 +1212,7 @@ func SerializeHTTPRequestRule(f models.HTTPRequestRule, opt *options.Configurati } case "silent-drop": rule = &actions.SilentDrop{ + RstTTL: f.RstTTL, Cond: f.Cond, CondTest: f.CondTest, } @@ -1291,5 +1304,5 @@ func SerializeHTTPRequestRule(f models.HTTPRequestRule, opt *options.Configurati } } - return rule, err + return rule, nil } diff --git a/configuration/http_response_rule.go b/configuration/http_response_rule.go index fbb82ca7..0b764a31 100644 --- a/configuration/http_response_rule.go +++ b/configuration/http_response_rule.go @@ -542,6 +542,7 @@ func ParseHTTPResponseRule(f types.Action) *models.HTTPResponseRule { //nolint:m } case *actions.SilentDrop: return &models.HTTPResponseRule{ + RstTTL: v.RstTTL, Type: "silent-drop", Cond: v.Cond, CondTest: v.CondTest, @@ -603,7 +604,8 @@ func ParseHTTPResponseRule(f types.Action) *models.HTTPResponseRule { //nolint:m return nil } -func SerializeHTTPResponseRule(f models.HTTPResponseRule, opt *options.ConfigurationOptions) (rule types.Action, err error) { //nolint:gocyclo,ireturn,cyclop,maintidx,gocognit +func SerializeHTTPResponseRule(f models.HTTPResponseRule, opt *options.ConfigurationOptions) (types.Action, error) { //nolint:gocyclo,ireturn,cyclop,maintidx,gocognit + var rule types.Action switch f.Type { case "add-acl": rule = &http_actions.AddACL{ @@ -865,6 +867,7 @@ func SerializeHTTPResponseRule(f models.HTTPResponseRule, opt *options.Configura } case "silent-drop": rule = &actions.SilentDrop{ + RstTTL: f.RstTTL, Cond: f.Cond, CondTest: f.CondTest, } @@ -921,5 +924,5 @@ func SerializeHTTPResponseRule(f models.HTTPResponseRule, opt *options.Configura CondTest: f.CondTest, } } - return rule, err + return rule, nil } diff --git a/configuration/interface.go b/configuration/interface.go index 8045f90e..de0768b1 100644 --- a/configuration/interface.go +++ b/configuration/interface.go @@ -17,6 +17,7 @@ package configuration import ( "context" + "errors" "fmt" "os/exec" "path/filepath" @@ -129,7 +130,7 @@ func New(ctx context.Context, opt ...options.ConfigurationOption) (Configuration } parserOptions := []parser_options.ParserOption{} - if c.ConfigurationOptions.UseMd5Hash { + if c.UseMd5Hash { parserOptions = append(parserOptions, parser_options.UseMd5Hash) } @@ -143,7 +144,7 @@ func New(ctx context.Context, opt ...options.ConfigurationOption) (Configuration p, err := parser.New(parserOptions...) if err != nil { - return nil, NewConfError(ErrCannotReadConfFile, fmt.Sprintf("Cannot read %s", c.ConfigurationFile)) + return nil, NewConfError(ErrCannotReadConfFile, "Cannot read "+c.ConfigurationFile) } c.parser = p @@ -155,6 +156,7 @@ func (c *client) Parser() parser.Parser { return c.parser } +//nolint:noctx func (c *client) fetchVersion(haproxy string) (string, error) { versionString, err := exec.Command(haproxy, "-v").Output() if err != nil { @@ -165,30 +167,30 @@ func (c *client) fetchVersion(haproxy string) (string, error) { func getVersionNumbers(version string) (int64, int64, int64, error) { if !strings.HasPrefix(version, "HAProxy version ") { - return 0, 0, 0, fmt.Errorf("not a haproxy version string") + return 0, 0, 0, errors.New("not a haproxy version string") } version = version[strings.Index(version, "HAProxy version ")+len("HAProxy version "):] versionSlice := strings.SplitN(version, "-", 2) if len(versionSlice) != 2 { - return 0, 0, 0, fmt.Errorf("not a haproxy version string") + return 0, 0, 0, errors.New("not a haproxy version string") } versionInts := strings.SplitN(versionSlice[0], ".", 3) if len(versionInts) != 3 { - return 0, 0, 0, fmt.Errorf("not a haproxy version string") + return 0, 0, 0, errors.New("not a haproxy version string") } major, err := strconv.ParseInt(versionInts[0], 10, 64) if err != nil { - return 0, 0, 0, fmt.Errorf("not a haproxy version string") + return 0, 0, 0, errors.New("not a haproxy version string") } minor, err := strconv.ParseInt(versionInts[1], 10, 64) if err != nil { - return 0, 0, 0, fmt.Errorf("not a haproxy version string") + return 0, 0, 0, errors.New("not a haproxy version string") } patch, err := strconv.ParseInt(versionInts[2], 10, 64) if err != nil { - return 0, 0, 0, fmt.Errorf("not a haproxy version string") + return 0, 0, 0, errors.New("not a haproxy version string") } return major, minor, patch, nil } diff --git a/configuration/log_forward.go b/configuration/log_forward.go index cb428777..cdb93f49 100644 --- a/configuration/log_forward.go +++ b/configuration/log_forward.go @@ -200,7 +200,7 @@ func (c *client) EditLogForward(name string, data *models.LogForward, transactio func SerializeLogForwardSection(p parser.Parser, data *models.LogForward, opt *options.ConfigurationOptions) error { if data == nil { - return fmt.Errorf("empty log forward") + return errors.New("empty log forward") } var err error diff --git a/configuration/mailers_section.go b/configuration/mailers_section.go index 95612b22..464d352a 100644 --- a/configuration/mailers_section.go +++ b/configuration/mailers_section.go @@ -174,7 +174,7 @@ func ParseMailersSection(p parser.Parser, ms *models.MailersSection) error { func SerializeMailersSection(p parser.Parser, data *models.MailersSection, opt *options.ConfigurationOptions) error { if data == nil { - return fmt.Errorf("empty mailers section") + return errors.New("empty mailers section") } if data.Timeout != nil { diff --git a/configuration/misc.go b/configuration/misc.go index 903e21cd..41d47421 100644 --- a/configuration/misc.go +++ b/configuration/misc.go @@ -1,6 +1,8 @@ package configuration import ( + "encoding/json" + "github.com/haproxytech/client-native/v6/config-parser/parsers/http/actions" "github.com/haproxytech/client-native/v6/misc" @@ -36,3 +38,27 @@ func modelHdr2ActionHdr(hdrs []*models.ReturnHeader) []*actions.Hdr { } return headers } + +func parseMetadata(comment string) map[string]any { + if comment == "" { + return nil + } + metadata := make(map[string]any) + err := json.Unmarshal([]byte(comment), &metadata) + if err != nil { + metadata["comment"] = comment + return metadata + } + return metadata +} + +func serializeMetadata(metadata map[string]any) (string, error) { + if metadata == nil { + return "", nil + } + b, err := json.Marshal(metadata) + if err != nil { + return "", err + } + return string(b), nil +} diff --git a/configuration/program.go b/configuration/program.go index 013e86fc..fef92e3e 100644 --- a/configuration/program.go +++ b/configuration/program.go @@ -150,11 +150,11 @@ func (c *client) EditProgram(name string, data *models.Program, transactionID st func SerializeProgramSection(p parser.Parser, data *models.Program) error { if data == nil { - return fmt.Errorf("empty program") + return errors.New("empty program") } if data.Command == nil { - return fmt.Errorf("command must be set") + return errors.New("command must be set") } if err := p.Set(parser.Program, data.Name, "command", types.Command{Args: *data.Command}); err != nil { return err diff --git a/configuration/raw.go b/configuration/raw.go index 3659c6de..5e66819c 100644 --- a/configuration/raw.go +++ b/configuration/raw.go @@ -20,7 +20,6 @@ import ( "bytes" "fmt" "os" - "os/exec" "strconv" "strings" ) @@ -139,13 +138,9 @@ func (c *client) PostRawConfiguration(config *string, version int64, skipVersion if err != nil { return NewConfError(ErrGeneralError, err.Error()) } - err = c.validateConfigFile(f.Name()) - if err != nil { - return err - } - return nil + return checkHaproxyConfiguration(c.ConfigurationOptions, f.Name()) } - t := "" + var t string if skipVersionCheck { // Create impicit transaction transaction, err := c.startTransaction(version, skipVersionCheck) @@ -180,7 +175,7 @@ func (c *client) PostRawConfiguration(config *string, version int64, skipVersion w := bufio.NewWriter(tmp) if !skipVersionCheck { - _, _ = w.WriteString(fmt.Sprintf("# _version=%v\n%v", version, *config)) + _, _ = fmt.Fprintf(w, "# _version=%d\n%s", version, c.dropVersionFromRaw(*config)) } else { _, _ = w.WriteString(*config) } @@ -193,7 +188,7 @@ func (c *client) PostRawConfiguration(config *string, version int64, skipVersion } if err := p.LoadData(tFile); err != nil { - return NewConfError(ErrCannotReadConfFile, fmt.Sprintf("Cannot read %s", tFile)) + return NewConfError(ErrCannotReadConfFile, "Cannot read "+tFile) } // Do a regular commit of the transaction @@ -204,26 +199,23 @@ func (c *client) PostRawConfiguration(config *string, version int64, skipVersion return nil } -func (c *client) validateConfigFile(confFile string) error { - // #nosec G204 - cmd := exec.Command(c.Haproxy) - cmd.Args = append(cmd.Args, "-c") +// dropVersionFromRaw is used when force pushing a raw configuration with version check: +// if the provided user input has already a version metadata it must be withdrawn. +func (c *client) dropVersionFromRaw(input string) string { + scanner := bufio.NewScanner(strings.NewReader(input)) - if confFile != "" { - cmd.Args = append(cmd.Args, "-f") - cmd.Args = append(cmd.Args, confFile) - } else { - cmd.Args = append(cmd.Args, "-f") - cmd.Args = append(cmd.Args, c.ConfigurationFile) - } + var sanitized strings.Builder - var stdout, stderr bytes.Buffer - cmd.Stdout = &stdout - cmd.Stderr = &stderr + for scanner.Scan() { + t := scanner.Bytes() - err := cmd.Run() - if err != nil { - return NewConfError(ErrValidationError, err.Error()) + if bytes.HasPrefix(t, []byte("# _version=")) { + continue + } + + sanitized.Write(t) + sanitized.WriteByte('\n') } - return nil + + return sanitized.String() } diff --git a/configuration/ring.go b/configuration/ring.go index 44f1311f..bde11511 100644 --- a/configuration/ring.go +++ b/configuration/ring.go @@ -243,7 +243,7 @@ func (c *client) EditRing(name string, data *models.Ring, transactionID string, func SerializeRingSection(p parser.Parser, data *models.Ring, opt *options.ConfigurationOptions) error { //nolint:gocognit if data == nil { - return fmt.Errorf("empty ring") + return errors.New("empty ring") } var err error diff --git a/configuration/server.go b/configuration/server.go index 0e751565..5eb1bd46 100644 --- a/configuration/server.go +++ b/configuration/server.go @@ -38,6 +38,7 @@ type Server interface { DeleteServer(name string, parentType string, parentName string, transactionID string, version int64) error CreateServer(parentType string, parentName string, data *models.Server, transactionID string, version int64) error EditServer(name string, parentType string, parentName string, data *models.Server, transactionID string, version int64) error + CreateOrEditServer(parentType string, parentName string, data *models.Server, transactionID string, version int64) error GetServerSwitchingRules(backend string, transactionID string) (int64, models.ServerSwitchingRules, error) GetServerSwitchingRule(id int64, backend string, transactionID string) (int64, *models.ServerSwitchingRule, error) DeleteServerSwitchingRule(id int64, backend string, transactionID string, version int64) error @@ -163,6 +164,33 @@ func (c *client) EditServer(name string, parentType string, parentName string, d return c.SaveData(p, t, transactionID == "") } +func (c *client) CreateOrEditServer(parentType string, parentName string, data *models.Server, transactionID string, version int64) error { + if c.UseModelsValidation { + validationErr := data.Validate(strfmt.Default) + if validationErr != nil { + return NewConfError(ErrValidationError, validationErr.Error()) + } + } + p, t, err := c.loadDataForChange(transactionID, version) + if err != nil { + return err + } + + server, i := GetServerByName(data.Name, parentType, parentName, p) + // Edition func by default + f := p.Set + if server == nil { + i = -1 + // If server does not exist then Create func + f = p.Insert + } + if err := f(sectionType(parentType), parentName, "server", SerializeServer(*data, &c.ConfigurationOptions), i); err != nil { + return c.HandleError(data.Name, parentType, parentName, t, transactionID == "", err) + } + + return c.SaveData(p, t, transactionID == "") +} + func ParseServers(parentType string, parentName string, p parser.Parser) (models.Servers, error) { var servers models.Servers @@ -187,7 +215,8 @@ func ParseServers(parentType string, parentName string, p parser.Parser) (models return servers, nil } -func ParseAddress(address string) (ipOrAddress string, port *int64) { +func ParseAddress(address string) (string, *int64) { + var port *int64 if strings.HasPrefix(address, "[") && strings.ContainsRune(address, ']') { // IPv6 with port [2001:0DB8:0000:0000:0000:0000:1428:57ab]:80 split := strings.Split(address, "]") split[0] = strings.TrimPrefix(split[0], "[") @@ -214,11 +243,11 @@ func ParseAddress(address string) (ipOrAddress string, port *int64) { // This is an imperfect solution, which is why dataplaneapi // adds brackets to IPv6 when it can. idx := strings.LastIndex(address, ":") - p, err := strconv.ParseUint(address[idx+1:], 10, 16) + p, err := strconv.ParseInt(address[idx+1:], 10, 16) if err != nil { return address, nil } - return address[:idx], misc.Int64P(int(p)) + return address[:idx], &p case c == 0: return address, nil // IPv4 or socket address default: @@ -248,6 +277,8 @@ func parseServerParams(serverOptions []params.ServerOption, serverParams *models serverParams.Check = "disabled" case "check-send-proxy": serverParams.CheckSendProxy = "enabled" + case "no-check-send-proxy": + serverParams.CheckSendProxy = "disabled" case "check-ssl": serverParams.CheckSsl = "enabled" case "no-check-ssl": @@ -511,6 +542,7 @@ func ParseServer(ondiskServer types.Server) *models.Server { } s.Address = address s.Port = port + s.Metadata = parseMetadata(ondiskServer.Comment) for _, p := range ondiskServer.Params { if v, ok := p.(*params.ServerOptionValue); ok { if v.Name == "id" { @@ -525,7 +557,8 @@ func ParseServer(ondiskServer types.Server) *models.Server { return s } -func serializeServerParams(s models.ServerParams, opt *options.ConfigurationOptions) (options []params.ServerOption) { //nolint:gocognit,gocyclo,cyclop,cyclop,maintidx +func SerializeServerParams(s models.ServerParams, opt *options.ConfigurationOptions) []params.ServerOption { //nolint:gocognit,gocyclo,cyclop,cyclop,maintidx + var options []params.ServerOption // ServerOptionWord if s.AgentCheck == "enabled" { options = append(options, ¶ms.ServerOptionWord{Name: "agent-check"}) @@ -861,7 +894,9 @@ func SerializeServer(s models.Server, opt *options.ConfigurationOptions) types.S } else { server.Address = misc.SanitizeIPv6Address(s.Address) } - server.Params = serializeServerParams(s.ServerParams, opt) + comment, _ := serializeMetadata(s.Metadata) + server.Comment = comment + server.Params = SerializeServerParams(s.ServerParams, opt) if s.ID != nil { server.Params = append(server.Params, ¶ms.ServerOptionValue{Name: "id", Value: strconv.FormatInt(*s.ID, 10)}) } @@ -869,17 +904,11 @@ func SerializeServer(s models.Server, opt *options.ConfigurationOptions) types.S } func GetServerByName(name string, parentType string, parentName string, p parser.Parser) (*models.Server, int) { - servers, err := ParseServers(parentType, parentName, p) + server, i, err := FindServers(parentType, parentName, name, p) if err != nil { - return nil, 0 + return nil, i } - - for i, s := range servers { - if s.Name == name { - return s, i - } - } - return nil, 0 + return server, i } func sectionType(parentType string) parser.Section { @@ -894,3 +923,26 @@ func sectionType(parentType string) parser.Section { } return sectionType } + +func FindServers(parentType string, parentName string, serverName string, p parser.Parser) (*models.Server, int, error) { + data, err := p.Get(sectionType(parentType), parentName, "server", false) + if err != nil { + if errors.Is(err, parser_errors.ErrFetch) { + return nil, 0, nil + } + return nil, 0, err + } + + ondiskServers, ok := data.([]types.Server) + if !ok { + return nil, 0, misc.CreateTypeAssertError("server") + } + + for i, ondiskServer := range ondiskServers { + if ondiskServer.Name == serverName { + return ParseServer(ondiskServer), i, nil + } + } + + return nil, 0, nil +} diff --git a/configuration/server_template.go b/configuration/server_template.go index f0466ee8..076c9639 100644 --- a/configuration/server_template.go +++ b/configuration/server_template.go @@ -200,7 +200,7 @@ func SerializeServerTemplate(s models.ServerTemplate, opt *options.Configuration if s.Port != nil { template.Port = *s.Port } - template.Params = serializeServerParams(s.ServerParams, opt) + template.Params = SerializeServerParams(s.ServerParams, opt) return template } diff --git a/configuration/service.go b/configuration/service.go index f055348d..2d88d342 100644 --- a/configuration/service.go +++ b/configuration/service.go @@ -148,7 +148,6 @@ func (s *Service) Update(servers []ServiceServer) (bool, error) { } reload = reload || r r, err = s.removeExcessNodes(len(servers)) - if err != nil { return false, err } @@ -215,7 +214,7 @@ func (s *Service) handleNode(server ServiceServer) error { } func (s *Service) createNewNodes(nodeCount int) error { - for i := 0; i < nodeCount; i++ { + for range nodeCount { if err := s.addNode(); err != nil { return err } @@ -251,6 +250,7 @@ func (s *Service) getLastNodeIndex(nodeCount int) (int, bool) { } currentNodeCount := s.serverCount() + //nolint: staticcheck for { if currentNodeCount/2 < s.scaling.BaseSlots { break @@ -402,16 +402,16 @@ func (s *Service) addNode() error { } func (s *Service) getNodeName() string { - name := fmt.Sprintf("SRV_%s", misc.RandomString(5)) + name := "SRV_" + misc.RandomString(5) for _, ok := s.usedNames[name]; ok; { - name = fmt.Sprintf("SRV_%s", misc.RandomString(5)) + name = "SRV_" + misc.RandomString(5) } s.usedNames[name] = struct{}{} return name } func (s *Service) reorderNodes(count int) { - for i := 0; i < count; i++ { + for i := range count { if s.nodes[i].disabled { s.swapDisabledNode(i) } diff --git a/configuration/site.go b/configuration/site.go index 5f3e8301..0b4a0a4a 100644 --- a/configuration/site.go +++ b/configuration/site.go @@ -232,7 +232,7 @@ func (c *client) EditSite(name string, data *models.Site, transactionID string, } } } - bcks := make([]interface{}, len(confS.Farms)) + bcks := make([]any, len(confS.Farms)) for i := range confS.Farms { bcks[i] = confS.Farms[i] } @@ -328,7 +328,7 @@ func (c *client) EditSite(name string, data *models.Site, transactionID string, } } } - bcks = make([]interface{}, len(data.Farms)) + bcks = make([]any, len(data.Farms)) for i := range data.Farms { bcks[i] = data.Farms[i] } @@ -533,7 +533,6 @@ func SerializeServiceToFrontend(service *models.SiteService, name string) *model fr.Mode = service.Mode fr.Maxconn = service.Maxconn fr.HTTPConnectionMode = service.HTTPConnectionMode - } return fr } diff --git a/configuration/structured_convert.go b/configuration/structured_convert.go index 03189e90..1f4e32c8 100644 --- a/configuration/structured_convert.go +++ b/configuration/structured_convert.go @@ -16,7 +16,7 @@ package configuration import ( - "fmt" + "errors" "reflect" ) @@ -42,18 +42,18 @@ func namedResourceArrayToMap[T any](namedResource []*T) (map[string]T, error) { // getKey returns the value of the 'Name' field from any struct or pointer to struct using reflection. // Constraint: the struct must have an exportable 'Name' field -func getKey(obj interface{}, keyName string) (string, error) { +func getKey(obj any, keyName string) (string, error) { value := reflect.ValueOf(obj) // If Pointer, first get the pointed value if value.Kind() == reflect.Ptr { value = value.Elem() } if value.Kind() != reflect.Struct { - return "", fmt.Errorf("object is not a struct") + return "", errors.New("object is not a struct") } nameField := value.FieldByName(keyName) if !nameField.IsValid() || !nameField.CanInterface() { - return "", fmt.Errorf("object does not have an exportable 'Name' field") + return "", errors.New("object does not have an exportable 'Name' field") } name := nameField.Interface().(string) return name, nil diff --git a/configuration/structured_defaults.go b/configuration/structured_defaults.go index 6b010be8..7431a472 100644 --- a/configuration/structured_defaults.go +++ b/configuration/structured_defaults.go @@ -255,7 +255,7 @@ func serializeDefaultsSection(a StructuredToParserArgs, d *models.Defaults) erro err = p.SectionsCreate(parser.Defaults, d.Name) if err != nil { - if !(errors.Is(err, parserErrors.ErrSectionAlreadyExists) && parser.DefaultSectionName == d.Name) { + if !errors.Is(err, parserErrors.ErrSectionAlreadyExists) || parser.DefaultSectionName != d.Name { return err } } diff --git a/configuration/structured_peers.go b/configuration/structured_peers.go index ba9654ad..3b06ea16 100644 --- a/configuration/structured_peers.go +++ b/configuration/structured_peers.go @@ -200,6 +200,17 @@ func parsePeerSection(name string, p parser.Parser) (*models.PeerSection, error) return nil, errsa } ps.Servers = serversa + + // tables + tables, err := ParseTables(name, p) + if err != nil { + return nil, err + } + tablesa, errsa := namedResourceArrayToMap(tables) + if errsa != nil { + return nil, errsa + } + ps.Tables = tablesa return ps, nil } @@ -233,5 +244,10 @@ func serializePeerSection(a StructuredToParserArgs, ps *models.PeerSection) erro return a.HandleError(strconv.FormatInt(int64(i), 10), PeersParentName, ps.Name, a.TID, a.TID == "", err) } } + for _, table := range ps.Tables { + if err = p.Insert(parser.Peers, ps.Name, "table", SerializeTable(table), -1); err != nil { + return a.HandleError(table.Name, PeersParentName, ps.Name, a.TID, a.TID == "", err) + } + } return nil } diff --git a/configuration/structured_userlists.go b/configuration/structured_userlists.go index f0b48b20..5551c964 100644 --- a/configuration/structured_userlists.go +++ b/configuration/structured_userlists.go @@ -125,7 +125,7 @@ func parseUserlistsSection(name string, p parser.Parser) (*models.Userlist, erro } userlista, errula := namedResourceArrayToMapWithKey(userlist, "Username") if errula != nil { - return nil, err + return nil, errula } u := &models.Userlist{ Users: userlista, @@ -139,7 +139,7 @@ func parseUserlistsSection(name string, p parser.Parser) (*models.Userlist, erro } groupsa, errga := namedResourceArrayToMap(groups) if errga != nil { - return nil, err + return nil, errga } u.Groups = groupsa diff --git a/configuration/tcp_check.go b/configuration/tcp_check.go index 294cb1f3..03be5130 100644 --- a/configuration/tcp_check.go +++ b/configuration/tcp_check.go @@ -17,7 +17,6 @@ package configuration import ( "errors" - "fmt" "strconv" "strings" @@ -76,9 +75,10 @@ func (c *client) GetTCPCheck(id int64, parentType string, parentName string, tra } var section parser.Section - if parentType == BackendParentName { + switch parentType { + case BackendParentName: section = parser.Backends - } else if parentType == DefaultsParentName { + case DefaultsParentName: section = parser.Defaults if parentName == "" { parentName = parser.DefaultSectionName @@ -106,9 +106,10 @@ func (c *client) DeleteTCPCheck(id int64, parentType string, parentName string, } var section parser.Section - if parentType == BackendParentName { + switch parentType { + case BackendParentName: section = parser.Backends - } else if parentType == DefaultsParentName { + case DefaultsParentName: section = parser.Defaults if parentName == "" { parentName = parser.DefaultSectionName @@ -138,9 +139,10 @@ func (c *client) CreateTCPCheck(id int64, parentType string, parentName string, } var section parser.Section - if parentType == BackendParentName { + switch parentType { + case BackendParentName: section = parser.Backends - } else if parentType == DefaultsParentName { + case DefaultsParentName: section = parser.Defaults if parentName == "" { parentName = parser.DefaultSectionName @@ -172,9 +174,10 @@ func (c *client) EditTCPCheck(id int64, parentType string, parentName string, da return err } var section parser.Section - if parentType == BackendParentName { + switch parentType { + case BackendParentName: section = parser.Backends - } else if parentType == DefaultsParentName { + case DefaultsParentName: section = parser.Defaults if parentName == "" { parentName = parser.DefaultSectionName @@ -217,9 +220,10 @@ func (c *client) ReplaceTCPChecks(parentType string, parentName string, data mod } var section parser.Section - if parentType == BackendParentName { + switch parentType { + case BackendParentName: section = parser.Backends - } else if parentType == DefaultsParentName { + case DefaultsParentName: section = parser.Defaults if parentName == "" { parentName = parser.DefaultSectionName @@ -257,7 +261,7 @@ func ParseTCPChecks(t, pName string, p parser.Parser) (models.TCPChecks, error) case BackendParentName: section = parser.Backends default: - return nil, NewConfError(ErrValidationError, fmt.Sprintf("unsupported section in tcp_check: %s", t)) + return nil, NewConfError(ErrValidationError, "unsupported section in tcp_check: "+t) } var checks models.TCPChecks @@ -281,15 +285,15 @@ func ParseTCPChecks(t, pName string, p parser.Parser) (models.TCPChecks, error) return checks, nil } -func ParseTCPCheck(f types.Action) (check *models.TCPCheck, err error) { +func ParseTCPCheck(f types.Action) (*models.TCPCheck, error) { switch v := f.(type) { case *tcp_actions.CheckComment: - check = &models.TCPCheck{ + return &models.TCPCheck{ Action: models.TCPCheckActionComment, CheckComment: v.LogMessage, - } + }, nil case *actions.CheckConnect: - check = &models.TCPCheck{ + return &models.TCPCheck{ Action: models.TCPCheckActionConnect, PortString: v.Port, Addr: v.Addr, @@ -302,9 +306,9 @@ func ParseTCPCheck(f types.Action) (check *models.TCPCheck, err error) { ViaSocks4: v.ViaSOCKS4, Ssl: v.SSL, Linger: v.Linger, - } + }, nil case *actions.CheckExpect: - check = &models.TCPCheck{ + check := &models.TCPCheck{ Action: models.TCPCheckActionExpect, CheckComment: v.CheckComment, OkStatus: v.OKStatus, @@ -320,56 +324,57 @@ func ParseTCPCheck(f types.Action) (check *models.TCPCheck, err error) { if v.MinRecv != nil { check.MinRecv = *v.MinRecv } + return check, nil case *tcp_actions.CheckSend: - check = &models.TCPCheck{ + return &models.TCPCheck{ Action: models.TCPCheckActionSend, Data: v.Data, CheckComment: v.CheckComment, - } + }, nil case *tcp_actions.CheckSendLf: - check = &models.TCPCheck{ + return &models.TCPCheck{ Action: models.TCPCheckActionSendDashLf, Fmt: v.Fmt, CheckComment: v.CheckComment, - } + }, nil case *tcp_actions.CheckSendBinary: - check = &models.TCPCheck{ + return &models.TCPCheck{ Action: models.TCPCheckActionSendDashBinary, HexString: v.HexString, CheckComment: v.CheckComment, - } + }, nil case *tcp_actions.CheckSendBinaryLf: - check = &models.TCPCheck{ + return &models.TCPCheck{ Action: models.TCPCheckActionSendDashBinaryDashLf, HexFmt: v.HexFmt, CheckComment: v.CheckComment, - } + }, nil case *actions.SetVarCheck: - check = &models.TCPCheck{ + return &models.TCPCheck{ Action: models.TCPCheckActionSetDashVar, VarScope: v.VarScope, VarName: v.VarName, VarExpr: strings.Join(v.Expr.Expr, " "), - } + }, nil case *actions.SetVarFmtCheck: - check = &models.TCPCheck{ + return &models.TCPCheck{ Action: models.TCPCheckActionSetDashVarDashFmt, VarScope: v.VarScope, VarName: v.VarName, VarFmt: strings.Join(v.Format.Expr, " "), - } + }, nil case *actions.UnsetVarCheck: - check = &models.TCPCheck{ + return &models.TCPCheck{ Action: models.TCPCheckActionUnsetDashVar, VarScope: v.Scope, VarName: v.Name, - } + }, nil } - return check, nil + return nil, nil //nolint:nilnil } -func SerializeTCPCheck(f models.TCPCheck) (action types.Action, err error) { //nolint:ireturn +func SerializeTCPCheck(f models.TCPCheck) (types.Action, error) { //nolint:ireturn switch f.Action { case models.TCPCheckActionComment: return &tcp_actions.CheckComment{ diff --git a/configuration/tcp_request_rule.go b/configuration/tcp_request_rule.go index 64df1d3b..83a41bb2 100644 --- a/configuration/tcp_request_rule.go +++ b/configuration/tcp_request_rule.go @@ -256,7 +256,8 @@ func ParseTCPRequestRules(t, pName string, p parser.Parser) (models.TCPRequestRu return tcpReqRules, nil } -func ParseTCPRequestRule(f types.TCPType) (rule *models.TCPRequestRule, err error) { //nolint:gocyclo,cyclop,maintidx +func ParseTCPRequestRule(f types.TCPType) (*models.TCPRequestRule, error) { //nolint:gocyclo,cyclop,maintidx + var rule *models.TCPRequestRule switch v := f.(type) { case *tcp_types.InspectDelay: return &models.TCPRequestRule{ @@ -357,6 +358,7 @@ func ParseTCPRequestRule(f types.TCPType) (rule *models.TCPRequestRule, err erro rule.CondTest = a.CondTest case *actions.SilentDrop: rule.Action = models.TCPRequestRuleActionSilentDashDrop + rule.RstTTL = a.RstTTL rule.Cond = a.Cond rule.CondTest = a.CondTest case *actions.Lua: @@ -536,6 +538,7 @@ func ParseTCPRequestRule(f types.TCPType) (rule *models.TCPRequestRule, err erro rule.CondTest = a.CondTest case *actions.SilentDrop: rule.Action = models.TCPRequestRuleActionSilentDashDrop + rule.RstTTL = a.RstTTL rule.Cond = a.Cond rule.CondTest = a.CondTest case *actions.SendSpoeGroup: @@ -749,6 +752,7 @@ func ParseTCPRequestRule(f types.TCPType) (rule *models.TCPRequestRule, err erro rule.CondTest = a.CondTest case *actions.SilentDrop: rule.Action = models.TCPRequestRuleActionSilentDashDrop + rule.RstTTL = a.RstTTL rule.Cond = a.Cond rule.CondTest = a.CondTest default: @@ -760,7 +764,7 @@ func ParseTCPRequestRule(f types.TCPType) (rule *models.TCPRequestRule, err erro return rule, nil } -func SerializeTCPRequestRule(f models.TCPRequestRule, opt *options.ConfigurationOptions) (rule types.TCPType, err error) { //nolint:gocyclo,cyclop,maintidx +func SerializeTCPRequestRule(f models.TCPRequestRule, opt *options.ConfigurationOptions) (types.TCPType, error) { //nolint:gocyclo,cyclop,maintidx switch f.Type { case models.TCPRequestRuleTypeConnection: switch f.Action { @@ -801,39 +805,6 @@ func SerializeTCPRequestRule(f models.TCPRequestRule, opt *options.Configuration CondTest: f.CondTest, }, }, nil - case models.TCPRequestRuleActionTrackDashSc0: - return &tcp_types.Connection{ - Action: &actions.TrackSc{ - Type: actions.TrackScType, - StickCounter: 0, - Key: f.TrackKey, - Table: f.TrackTable, - Cond: f.Cond, - CondTest: f.CondTest, - }, - }, nil - case models.TCPRequestRuleActionTrackDashSc1: - return &tcp_types.Connection{ - Action: &actions.TrackSc{ - Type: actions.TrackScType, - StickCounter: 1, - Key: f.TrackKey, - Table: f.TrackTable, - Cond: f.Cond, - CondTest: f.CondTest, - }, - }, nil - case models.TCPRequestRuleActionTrackDashSc2: - return &tcp_types.Connection{ - Action: &actions.TrackSc{ - Type: actions.TrackScType, - StickCounter: 2, - Key: f.TrackKey, - Table: f.TrackTable, - Cond: f.Cond, - CondTest: f.CondTest, - }, - }, nil case models.TCPRequestRuleActionTrackDashSc: if f.TrackStickCounter == nil { return nil, NewConfError(ErrValidationError, "track_sc_stick_counter must be set") @@ -908,6 +879,7 @@ func SerializeTCPRequestRule(f models.TCPRequestRule, opt *options.Configuration case models.TCPRequestRuleActionSilentDashDrop: return &tcp_types.Connection{ Action: &actions.SilentDrop{ + RstTTL: f.RstTTL, Cond: f.Cond, CondTest: f.CondTest, }, @@ -1068,39 +1040,6 @@ func SerializeTCPRequestRule(f models.TCPRequestRule, opt *options.Configuration CondTest: f.CondTest, }, }, nil - case models.TCPRequestRuleActionTrackDashSc0: - return &tcp_types.Content{ - Action: &actions.TrackSc{ - Type: actions.TrackScType, - StickCounter: 0, - Key: f.TrackKey, - Table: f.TrackTable, - Cond: f.Cond, - CondTest: f.CondTest, - }, - }, nil - case models.TCPRequestRuleActionTrackDashSc1: - return &tcp_types.Content{ - Action: &actions.TrackSc{ - Type: actions.TrackScType, - StickCounter: 1, - Key: f.TrackKey, - Table: f.TrackTable, - Cond: f.Cond, - CondTest: f.CondTest, - }, - }, nil - case models.TCPRequestRuleActionTrackDashSc2: - return &tcp_types.Content{ - Action: &actions.TrackSc{ - Type: actions.TrackScType, - StickCounter: 2, - Key: f.TrackKey, - Table: f.TrackTable, - Cond: f.Cond, - CondTest: f.CondTest, - }, - }, nil case models.TCPRequestRuleActionTrackDashSc: if f.TrackStickCounter == nil { return nil, NewConfError(ErrValidationError, "track_sc_stick_counter must be set") @@ -1218,6 +1157,7 @@ func SerializeTCPRequestRule(f models.TCPRequestRule, opt *options.Configuration case models.TCPRequestRuleActionSilentDashDrop: return &tcp_types.Content{ Action: &actions.SilentDrop{ + RstTTL: f.RstTTL, Cond: f.Cond, CondTest: f.CondTest, }, @@ -1375,39 +1315,6 @@ func SerializeTCPRequestRule(f models.TCPRequestRule, opt *options.Configuration CondTest: f.CondTest, }, }, nil - case models.TCPRequestRuleActionTrackDashSc0: - return &tcp_types.Session{ - Action: &actions.TrackSc{ - Type: actions.TrackScType, - StickCounter: 0, - Key: f.TrackKey, - Table: f.TrackTable, - Cond: f.Cond, - CondTest: f.CondTest, - }, - }, nil - case models.TCPRequestRuleActionTrackDashSc1: - return &tcp_types.Session{ - Action: &actions.TrackSc{ - Type: actions.TrackScType, - StickCounter: 1, - Key: f.TrackKey, - Table: f.TrackTable, - Cond: f.Cond, - CondTest: f.CondTest, - }, - }, nil - case models.TCPRequestRuleActionTrackDashSc2: - return &tcp_types.Session{ - Action: &actions.TrackSc{ - Type: actions.TrackScType, - StickCounter: 2, - Key: f.TrackKey, - Table: f.TrackTable, - Cond: f.Cond, - CondTest: f.CondTest, - }, - }, nil case models.TCPRequestRuleActionTrackDashSc: if f.TrackStickCounter == nil { return nil, NewConfError(ErrValidationError, "track_sc_stick_counter must be set") @@ -1559,6 +1466,7 @@ func SerializeTCPRequestRule(f models.TCPRequestRule, opt *options.Configuration case models.TCPRequestRuleActionSilentDashDrop: return &tcp_types.Session{ Action: &actions.SilentDrop{ + RstTTL: f.RstTTL, Cond: f.Cond, CondTest: f.CondTest, }, diff --git a/configuration/tcp_response_rule.go b/configuration/tcp_response_rule.go index afa2b0a3..08ba0f06 100644 --- a/configuration/tcp_response_rule.go +++ b/configuration/tcp_response_rule.go @@ -427,6 +427,7 @@ func ParseTCPResponseRule(t types.TCPType) (*models.TCPResponseRule, error) { return &models.TCPResponseRule{ Type: models.TCPResponseRuleTypeContent, Action: models.TCPResponseRuleActionSilentDashDrop, + RstTTL: a.RstTTL, Cond: a.Cond, CondTest: a.CondTest, }, nil @@ -625,6 +626,7 @@ func SerializeTCPResponseRule(t models.TCPResponseRule, opt *options.Configurati case models.TCPResponseRuleActionSilentDashDrop: return &tcp_types.Content{ Action: &actions.SilentDrop{ + RstTTL: t.RstTTL, Cond: t.Cond, CondTest: t.CondTest, }, diff --git a/configuration/transaction-handling.go b/configuration/transaction-handling.go index 3419c0c6..cdeb7d35 100644 --- a/configuration/transaction-handling.go +++ b/configuration/transaction-handling.go @@ -16,8 +16,6 @@ package configuration import ( - "fmt" - parser "github.com/haproxytech/client-native/v6/config-parser" parser_options "github.com/haproxytech/client-native/v6/config-parser/options" "github.com/haproxytech/client-native/v6/config-parser/types" @@ -52,7 +50,7 @@ func (c *client) InitTransactionParsers() error { return err } if err := p.LoadData(tFile); err != nil { - return NewConfError(ErrCannotReadConfFile, fmt.Sprintf("Cannot read %s", tFile)) + return NewConfError(ErrCannotReadConfFile, "cannot read "+tFile) } } return nil @@ -78,7 +76,7 @@ func (c *client) GetParserTransactions() models.Transactions { func (c *client) GetFailedParserTransactionVersion(transactionID string) (int64, error) { p, err := parser.New(parser_options.Path(transactionID)) if err != nil { - return 0, NewConfError(ErrCannotReadConfFile, fmt.Sprintf("cannot read %s", transactionID)) + return 0, NewConfError(ErrCannotReadConfFile, "cannot read "+transactionID) } data, _ := p.Get(parser.Comments, parser.CommentsSectionName, "# _version", false) diff --git a/configuration/transaction.go b/configuration/transaction.go index 0239f7cb..31b8035f 100644 --- a/configuration/transaction.go +++ b/configuration/transaction.go @@ -16,12 +16,10 @@ package configuration import ( - "bytes" "errors" "fmt" "io/fs" "os" - "os/exec" "path/filepath" "strconv" "strings" @@ -32,7 +30,6 @@ import ( parser_errors "github.com/haproxytech/client-native/v6/config-parser/errors" parser_options "github.com/haproxytech/client-native/v6/config-parser/options" spoe "github.com/haproxytech/client-native/v6/config-parser/spoe" - shellquote "github.com/kballard/go-shellquote" "github.com/haproxytech/client-native/v6/configuration/options" "github.com/haproxytech/client-native/v6/models" @@ -58,8 +55,9 @@ type TransactionClient interface { type transactionCleanerHandler func(transactionId, configurationFile string) type Transaction struct { - TransactionClient TransactionClient options.ConfigurationOptions + + TransactionClient TransactionClient mu sync.Mutex noNamedDefaultsFrom bool } @@ -222,39 +220,6 @@ func (t *Transaction) backupCfgAndCleanup(version int64) { os.Remove(backupToDel) } -func addConfigFilesToArgs(args []string, clientParams options.ConfigurationOptions) []string { - result := []string{} - for _, file := range clientParams.ValidateConfigFilesBefore { - result = append(result, "-f", file) - } - result = append(result, args...) - - for _, file := range clientParams.ValidateConfigFilesAfter { - result = append(result, "-f", file) - } - return result -} - -// Returns a copy of envs without the unwanted environment variables. -func removeFromEnv(envs []string, unwanted ...string) []string { - newEnv := make([]string, 0, len(envs)) - - for _, v := range envs { - skip := false - for _, bad := range unwanted { - if strings.HasPrefix(v, bad+"=") { - skip = true - break - } - } - if !skip { - newEnv = append(newEnv, v) - } - } - - return newEnv -} - func (t *Transaction) checkTransactionFile(transactionID string) error { // check only against HAProxy file _, ok := t.TransactionClient.(*client) @@ -265,7 +230,7 @@ func (t *Transaction) checkTransactionFile(transactionID string) error { // such as if want to use different HAProxy (community, enterprise, aloha) // where different options are supported. // By disabling validation we can still use DPAPI - if t.ConfigurationOptions.SkipConfigurationFileValidation { + if t.SkipConfigurationFileValidation { return nil } @@ -274,47 +239,12 @@ func (t *Transaction) checkTransactionFile(transactionID string) error { return err } - var name string - var args []string - - // Inherit the environment but filter out a few unwanted variables. - envs := removeFromEnv(os.Environ(), "HAPROXY_STARTUPLOGS_FD", - "HAPROXY_MWORKER_WAIT_ONLY", "HAPROXY_PROCESSES") - - switch { - case len(t.ValidateCmd) > 0: - w, _ := shellquote.Split(t.ValidateCmd) - name = w[0] - args = w[1:] - envs = append(envs, fmt.Sprintf("DATAPLANEAPI_TRANSACTION_FILE=%s", transactionFile)) - case t.MasterWorker: - name = t.Haproxy - args = []string{"-W", "-f", transactionFile, "-c"} - args = addConfigFilesToArgs(args, t.ConfigurationOptions) - default: - name = t.Haproxy - args = []string{"-f", transactionFile, "-c"} - args = addConfigFilesToArgs(args, t.ConfigurationOptions) - } - - // #nosec G204 - cmd := exec.Command(name, args...) - cmd.Env = envs - var stdout, stderr bytes.Buffer - cmd.Stdout = &stdout - cmd.Stderr = &stderr - - err = cmd.Run() - if err != nil { - errStr := fmt.Sprintf("%s: %s", err.Error(), t.parseHAProxyCheckError(stderr.Bytes(), transactionID)) - return NewConfError(ErrValidationError, errStr) - } - return nil + return checkHaproxyConfiguration(t.ConfigurationOptions, transactionFile, transactionID) } func (t *Transaction) CheckTransactionOrVersion(transactionID string, version int64) (string, error) { // start an implicit transaction if transaction is not already given - tID := "" + var tID string if transactionID != "" && version != 0 { return "", NewConfError(ErrBothVersionTransaction, "") } @@ -337,64 +267,19 @@ func (t *Transaction) CheckTransactionOrVersion(transactionID string, version in return "", err } tID = transaction.ID - } return tID, nil } -func (t *Transaction) parseHAProxyCheckError(output []byte, id string) string { //nolint:gocognit - oStr := string(output) - var b strings.Builder - b.WriteString(fmt.Sprintf("err transactionId=%s \n", id)) - - for _, lineWhole := range strings.Split(oStr, "\n") { - line := strings.TrimSpace(lineWhole) - if strings.HasPrefix(line, "[ALERT]") { - if strings.HasSuffix(line, "fatal errors found in configuration.") { - continue - } - if strings.Contains(line, "error(s) found in configuration file : ") { - continue - } - - parts := strings.Split(line, " : ") - if len(parts) > 2 && strings.HasPrefix(strings.TrimSpace(parts[1]), "parsing [") { - fParts := strings.Split(strings.TrimSpace(parts[1]), ":") - var msgB strings.Builder - for i := 2; i < len(parts); i++ { - msgB.WriteString(parts[i]) - msgB.WriteString(" ") - } - if len(fParts) > 1 { - lNo, err := strconv.ParseInt(strings.TrimSuffix(fParts[1], "]"), 10, 64) - if err == nil { - b.WriteString(fmt.Sprintf("line=%d msg=\"%s\"\n", lNo, strings.TrimSpace(msgB.String()))) - } else { - b.WriteString(fmt.Sprintf("msg=\"%s\"\n", strings.TrimSpace(msgB.String()))) - } - } - } else if len(parts) > 1 { - var msgB strings.Builder - for i := 1; i < len(parts); i++ { - msgB.WriteString(parts[i]) - msgB.WriteString(" ") - } - b.WriteString(fmt.Sprintf("msg=\"%s\"\n", strings.TrimSpace(msgB.String()))) - } - } - } - return strings.TrimSuffix(b.String(), "\n") -} - // MarkTransactionOutdated is marking the transaction by ID as outdated due to a newer commit, // moving it to the `outdated` folder, as well cleaning from the current parsers. -func (t *Transaction) MarkTransactionOutdated(transactionID string) (err error) { +func (t *Transaction) MarkTransactionOutdated(transactionID string) error { t.mu.Lock() defer t.mu.Unlock() // retrieving current version var version int64 - version, err = t.TransactionClient.GetVersion("") + version, err := t.TransactionClient.GetVersion("") if err != nil { return err } @@ -680,7 +565,7 @@ func (t *Transaction) getFailedTransactionVersion(transactionID string) (int64, parser_options.Path(fPath), ) if err != nil { - return 0, NewConfError(ErrCannotReadConfFile, fmt.Sprintf("cannot read %s", fPath)) + return 0, NewConfError(ErrCannotReadConfFile, "cannot read "+fPath) } ver, err := t.TransactionClient.GetFailedParserTransactionVersion(transactionID) @@ -694,7 +579,7 @@ func moveFile(src, dest string) error { return os.Rename(src, dest) } -func (t *Transaction) SaveData(prsr interface{}, tID string, commitImplicit bool) error { +func (t *Transaction) SaveData(prsr any, tID string, commitImplicit bool) error { if t.PersistentTransactions { tFile, err := t.GetTransactionFile(tID) if err != nil { diff --git a/e2e/runtime/parallel/haproxy.cfg b/e2e/runtime/parallel/haproxy.cfg new file mode 100644 index 00000000..a4fcb6f9 --- /dev/null +++ b/e2e/runtime/parallel/haproxy.cfg @@ -0,0 +1,15 @@ +global + maxconn 1000 + stats socket "$SOCK_PATH" level admin + +defaults + mode http + +frontend test + bind localhost:32000 + default_backend test_bck + +backend test_bck + balance roundrobin + server test1 127.0.0.1:5000 + server test2 127.0.0.1:5001 diff --git a/e2e/runtime/parallel/parallel_test.go b/e2e/runtime/parallel/parallel_test.go new file mode 100644 index 00000000..095d36ae --- /dev/null +++ b/e2e/runtime/parallel/parallel_test.go @@ -0,0 +1,45 @@ +// Copyright 2021 HAProxy Technologies +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//go:build integration +// +build integration + +package parallel_test + +import ( + "sync" +) + +func (s *ParallelRuntime) TestParallel() { + runtime, err := s.client.Runtime() + if err != nil { + s.FailNow(err.Error()) + } + var wg sync.WaitGroup + for range 3000 { + wg.Add(1) + go func() { + defer wg.Done() + info, err := runtime.GetInfo() + s.Assert().Empty(info.Error, "error is: ", info.Error) + s.Assert().NotNil(info.Info, "information is nil", info.Error) + s.Assert().Equal(info.RuntimeAPI, s.socketPath, "runtime not correct, runtime is ", info.RuntimeAPI) + s.Assert().Contains(info.Info.Version, s.haproxyVersion, "version not correct, version is ", info.Info.Version) + if err != nil { + s.FailNow(err.Error()) + } + }() + } + wg.Wait() +} diff --git a/e2e/runtime/parallel/setup_test.go b/e2e/runtime/parallel/setup_test.go new file mode 100644 index 00000000..dd0ff6bf --- /dev/null +++ b/e2e/runtime/parallel/setup_test.go @@ -0,0 +1,66 @@ +// Copyright 2021 HAProxy Technologies +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//go:build integration +// +build integration + +package parallel_test + +import ( + "os" + "os/exec" + "testing" + + client_native "github.com/haproxytech/client-native/v6" + + "github.com/haproxytech/client-native/v6/e2e" + "github.com/stretchr/testify/suite" +) + +type ParallelRuntime struct { + suite.Suite + cmd *exec.Cmd + client client_native.HAProxyClient + tmpDir string + haproxyVersion string + socketPath string +} + +func (s *ParallelRuntime) SetupTest() { + result, err := e2e.GetClient(s.T()) + if err != nil { + s.FailNow(err.Error()) + } + s.haproxyVersion = result.HAProxyVersion + s.cmd = result.Cmd + s.client = result.Client + s.tmpDir = result.TmpDir + s.socketPath = result.SocketPath +} + +func (s *ParallelRuntime) TearDownSuite() { + if err := s.cmd.Process.Kill(); err != nil { + s.FailNow(err.Error()) + } + if s.tmpDir != "" { + err := os.RemoveAll(s.tmpDir) + if err != nil { + s.FailNow(err.Error()) + } + } +} + +func TestParallelRuntimes(t *testing.T) { + suite.Run(t, new(ParallelRuntime)) +} diff --git a/e2e/test_client.go b/e2e/test_client.go index c0b0d061..3da485f0 100644 --- a/e2e/test_client.go +++ b/e2e/test_client.go @@ -42,9 +42,10 @@ type ClientResponse struct { Cmd *exec.Cmd TmpDir string HAProxyVersion string + SocketPath string } -func GetClient(t *testing.T) (*ClientResponse, error) { +func GetClient(t *testing.T) (*ClientResponse, error) { //nolint:thelper cmd := exec.Command("haproxy", "-v") var out bytes.Buffer @@ -72,6 +73,7 @@ func GetClient(t *testing.T) (*ClientResponse, error) { tmpPath := path.Join(os.TempDir(), "client-native/", testName) socketPath := path.Join(tmpPath, "runtime.sock") + err = os.MkdirAll(tmpPath, 0o777) if err != nil { return nil, err @@ -79,14 +81,14 @@ func GetClient(t *testing.T) (*ClientResponse, error) { cmd = exec.Command("haproxy", "-f", "haproxy.cfg") cmd.Env = os.Environ() - cmd.Env = append(cmd.Env, fmt.Sprintf("SOCK_PATH=%s", socketPath)) + cmd.Env = append(cmd.Env, "SOCK_PATH="+socketPath) if err = cmd.Start(); err != nil { return nil, err } HAProxyCFG := "haproxy.cfg" - confClient, err := configuration.New(context.Background(), + confClient, err := configuration.New(t.Context(), configuration_options.ConfigurationFile(HAProxyCFG), // options.UsePersistentTransactions, configuration_options.TransactionsDir(os.TempDir()), @@ -116,13 +118,13 @@ func GetClient(t *testing.T) (*ClientResponse, error) { end := time.Now() t.Logf("%s done", end.Format("15:04:05.000")) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) + ctx, cancel := context.WithTimeout(t.Context(), time.Second) defer cancel() runtimeClient, err := runtime.New(ctx, runtime_options.Socket(socketPath)) if err != nil { return nil, err } - nativeAPI, err := clientnative.New(context.Background(), + nativeAPI, err := clientnative.New(t.Context(), options.Configuration(confClient), options.Runtime(runtimeClient), ) @@ -131,5 +133,6 @@ func GetClient(t *testing.T) (*ClientResponse, error) { Cmd: cmd, TmpDir: tmpPath, HAProxyVersion: version, + SocketPath: socketPath, }, err } diff --git a/errors/errors.go b/errors/errors.go index decb43a2..f1740295 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -1,5 +1,6 @@ package errors +//nolint:revive import "errors" var ( diff --git a/go.mod b/go.mod index e04ae721..7ac8cd11 100644 --- a/go.mod +++ b/go.mod @@ -1,45 +1,58 @@ module github.com/haproxytech/client-native/v6 -go 1.22 +go 1.25 require ( - github.com/go-faker/faker/v4 v4.4.2 - github.com/go-openapi/errors v0.22.0 - github.com/go-openapi/strfmt v0.23.0 - github.com/go-openapi/swag v0.23.0 - github.com/go-openapi/validate v0.24.0 - github.com/gofrs/flock v0.12.1 - github.com/google/go-cmp v0.6.0 + github.com/go-faker/faker/v4 v4.7.0 + github.com/go-openapi/errors v0.22.6 + github.com/go-openapi/strfmt v0.25.0 + github.com/go-openapi/swag v0.25.4 + github.com/go-openapi/swag/mangling v0.25.4 + github.com/go-openapi/validate v0.25.1 + github.com/gofrs/flock v0.13.0 + github.com/google/go-cmp v0.7.0 github.com/google/renameio v1.0.1 github.com/google/uuid v1.6.0 + github.com/haproxytech/client-native/v5 v5.1.9 github.com/haproxytech/go-logger v1.1.0 github.com/json-iterator/go v1.1.12 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/mitchellh/mapstructure v1.5.0 - github.com/pkg/errors v0.9.1 github.com/sirkon/dst v0.26.4 - github.com/stretchr/testify v1.9.0 - golang.org/x/text v0.17.0 - golang.org/x/tools v0.24.0 + github.com/stretchr/testify v1.11.1 + golang.org/x/sync v0.19.0 + golang.org/x/text v0.33.0 + golang.org/x/tools v0.41.0 gopkg.in/yaml.v3 v3.0.1 ) require ( - github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/go-openapi/analysis v0.23.0 // indirect - github.com/go-openapi/jsonpointer v0.21.0 // indirect - github.com/go-openapi/jsonreference v0.21.0 // indirect - github.com/go-openapi/loads v0.22.0 // indirect - github.com/go-openapi/spec v0.21.0 // indirect - github.com/josharian/intern v1.0.0 // indirect - github.com/mailru/easyjson v0.7.7 // indirect + github.com/go-openapi/analysis v0.24.2 // indirect + github.com/go-openapi/jsonpointer v0.22.4 // indirect + github.com/go-openapi/jsonreference v0.21.4 // indirect + github.com/go-openapi/loads v0.23.2 // indirect + github.com/go-openapi/spec v0.22.3 // indirect + github.com/go-openapi/swag/cmdutils v0.25.4 // indirect + github.com/go-openapi/swag/conv v0.25.4 // indirect + github.com/go-openapi/swag/fileutils v0.25.4 // indirect + github.com/go-openapi/swag/jsonname v0.25.4 // indirect + github.com/go-openapi/swag/jsonutils v0.25.4 // indirect + github.com/go-openapi/swag/loading v0.25.4 // indirect + github.com/go-openapi/swag/netutils v0.25.4 // indirect + github.com/go-openapi/swag/stringutils v0.25.4 // indirect + github.com/go-openapi/swag/typeutils v0.25.4 // indirect + github.com/go-openapi/swag/yamlutils v0.25.4 // indirect + github.com/go-viper/mapstructure/v2 v2.5.0 // indirect + github.com/kr/text v0.2.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/oklog/ulid v1.3.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - go.mongodb.org/mongo-driver v1.16.1 // indirect - golang.org/x/mod v0.20.0 // indirect - golang.org/x/sync v0.8.0 // indirect - golang.org/x/sys v0.24.0 // indirect + github.com/rogpeppe/go-internal v1.14.1 // indirect + go.mongodb.org/mongo-driver v1.17.8 // indirect + go.yaml.in/yaml/v3 v3.0.4 // indirect + golang.org/x/mod v0.32.0 // indirect + golang.org/x/net v0.49.0 // indirect + golang.org/x/sys v0.40.0 // indirect ) diff --git a/go.sum b/go.sum index cec20346..bb80fcdf 100644 --- a/go.sum +++ b/go.sum @@ -1,41 +1,70 @@ -github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= -github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-faker/faker/v4 v4.4.2 h1:96WeU9QKEqRUVYdjHquY2/5bAqmVM0IfGKHV5mbfqmQ= -github.com/go-faker/faker/v4 v4.4.2/go.mod h1:4K3v4AbKXYNHMQNaREMc9/kRB9j5JJzpFo6KHRvrcIw= -github.com/go-openapi/analysis v0.23.0 h1:aGday7OWupfMs+LbmLZG4k0MYXIANxcuBTYUC03zFCU= -github.com/go-openapi/analysis v0.23.0/go.mod h1:9mz9ZWaSlV8TvjQHLl2mUW2PbZtemkE8yA5v22ohupo= -github.com/go-openapi/errors v0.22.0 h1:c4xY/OLxUBSTiepAg3j/MHuAv5mJhnf53LLMWFB+u/w= -github.com/go-openapi/errors v0.22.0/go.mod h1:J3DmZScxCDufmIMsdOuDHxJbdOGC0xtUynjIx092vXE= -github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= -github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= -github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ= -github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4= -github.com/go-openapi/loads v0.22.0 h1:ECPGd4jX1U6NApCGG1We+uEozOAvXvJSF4nnwHZ8Aco= -github.com/go-openapi/loads v0.22.0/go.mod h1:yLsaTCS92mnSAZX5WWoxszLj0u+Ojl+Zs5Stn1oF+rs= -github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY= -github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk= -github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c= -github.com/go-openapi/strfmt v0.23.0/go.mod h1:NrtIpfKtWIygRkKVsxh7XQMDQW5HKQl6S5ik2elW+K4= -github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= -github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= -github.com/go-openapi/validate v0.24.0 h1:LdfDKwNbpB6Vn40xhTdNZAnfLECL81w+VX3BumrGD58= -github.com/go-openapi/validate v0.24.0/go.mod h1:iyeX1sEufmv3nPbBdX3ieNviWnOZaJ1+zquzJEf2BAQ= -github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= -github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/go-faker/faker/v4 v4.7.0 h1:VboC02cXHl/NuQh5lM2W8b87yp4iFXIu59x4w0RZi4E= +github.com/go-faker/faker/v4 v4.7.0/go.mod h1:u1dIRP5neLB6kTzgyVjdBOV5R1uP7BdxkcWk7tiKQXk= +github.com/go-openapi/analysis v0.24.2 h1:6p7WXEuKy1llDgOH8FooVeO+Uq2za9qoAOq4ZN08B50= +github.com/go-openapi/analysis v0.24.2/go.mod h1:x27OOHKANE0lutg2ml4kzYLoHGMKgRm1Cj2ijVOjJuE= +github.com/go-openapi/errors v0.22.6 h1:eDxcf89O8odEnohIXwEjY1IB4ph5vmbUsBMsFNwXWPo= +github.com/go-openapi/errors v0.22.6/go.mod h1:z9S8ASTUqx7+CP1Q8dD8ewGH/1JWFFLX/2PmAYNQLgk= +github.com/go-openapi/jsonpointer v0.22.4 h1:dZtK82WlNpVLDW2jlA1YCiVJFVqkED1MegOUy9kR5T4= +github.com/go-openapi/jsonpointer v0.22.4/go.mod h1:elX9+UgznpFhgBuaMQ7iu4lvvX1nvNsesQ3oxmYTw80= +github.com/go-openapi/jsonreference v0.21.4 h1:24qaE2y9bx/q3uRK/qN+TDwbok1NhbSmGjjySRCHtC8= +github.com/go-openapi/jsonreference v0.21.4/go.mod h1:rIENPTjDbLpzQmQWCj5kKj3ZlmEh+EFVbz3RTUh30/4= +github.com/go-openapi/loads v0.23.2 h1:rJXAcP7g1+lWyBHC7iTY+WAF0rprtM+pm8Jxv1uQJp4= +github.com/go-openapi/loads v0.23.2/go.mod h1:IEVw1GfRt/P2Pplkelxzj9BYFajiWOtY2nHZNj4UnWY= +github.com/go-openapi/spec v0.22.3 h1:qRSmj6Smz2rEBxMnLRBMeBWxbbOvuOoElvSvObIgwQc= +github.com/go-openapi/spec v0.22.3/go.mod h1:iIImLODL2loCh3Vnox8TY2YWYJZjMAKYyLH2Mu8lOZs= +github.com/go-openapi/strfmt v0.25.0 h1:7R0RX7mbKLa9EYCTHRcCuIPcaqlyQiWNPTXwClK0saQ= +github.com/go-openapi/strfmt v0.25.0/go.mod h1:nNXct7OzbwrMY9+5tLX4I21pzcmE6ccMGXl3jFdPfn8= +github.com/go-openapi/swag v0.25.4 h1:OyUPUFYDPDBMkqyxOTkqDYFnrhuhi9NR6QVUvIochMU= +github.com/go-openapi/swag v0.25.4/go.mod h1:zNfJ9WZABGHCFg2RnY0S4IOkAcVTzJ6z2Bi+Q4i6qFQ= +github.com/go-openapi/swag/cmdutils v0.25.4 h1:8rYhB5n6WawR192/BfUu2iVlxqVR9aRgGJP6WaBoW+4= +github.com/go-openapi/swag/cmdutils v0.25.4/go.mod h1:pdae/AFo6WxLl5L0rq87eRzVPm/XRHM3MoYgRMvG4A0= +github.com/go-openapi/swag/conv v0.25.4 h1:/Dd7p0LZXczgUcC/Ikm1+YqVzkEeCc9LnOWjfkpkfe4= +github.com/go-openapi/swag/conv v0.25.4/go.mod h1:3LXfie/lwoAv0NHoEuY1hjoFAYkvlqI/Bn5EQDD3PPU= +github.com/go-openapi/swag/fileutils v0.25.4 h1:2oI0XNW5y6UWZTC7vAxC8hmsK/tOkWXHJQH4lKjqw+Y= +github.com/go-openapi/swag/fileutils v0.25.4/go.mod h1:cdOT/PKbwcysVQ9Tpr0q20lQKH7MGhOEb6EwmHOirUk= +github.com/go-openapi/swag/jsonname v0.25.4 h1:bZH0+MsS03MbnwBXYhuTttMOqk+5KcQ9869Vye1bNHI= +github.com/go-openapi/swag/jsonname v0.25.4/go.mod h1:GPVEk9CWVhNvWhZgrnvRA6utbAltopbKwDu8mXNUMag= +github.com/go-openapi/swag/jsonutils v0.25.4 h1:VSchfbGhD4UTf4vCdR2F4TLBdLwHyUDTd1/q4i+jGZA= +github.com/go-openapi/swag/jsonutils v0.25.4/go.mod h1:7OYGXpvVFPn4PpaSdPHJBtF0iGnbEaTk8AvBkoWnaAY= +github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.4 h1:IACsSvBhiNJwlDix7wq39SS2Fh7lUOCJRmx/4SN4sVo= +github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.4/go.mod h1:Mt0Ost9l3cUzVv4OEZG+WSeoHwjWLnarzMePNDAOBiM= +github.com/go-openapi/swag/loading v0.25.4 h1:jN4MvLj0X6yhCDduRsxDDw1aHe+ZWoLjW+9ZQWIKn2s= +github.com/go-openapi/swag/loading v0.25.4/go.mod h1:rpUM1ZiyEP9+mNLIQUdMiD7dCETXvkkC30z53i+ftTE= +github.com/go-openapi/swag/mangling v0.25.4 h1:2b9kBJk9JvPgxr36V23FxJLdwBrpijI26Bx5JH4Hp48= +github.com/go-openapi/swag/mangling v0.25.4/go.mod h1:6dxwu6QyORHpIIApsdZgb6wBk/DPU15MdyYj/ikn0Hg= +github.com/go-openapi/swag/netutils v0.25.4 h1:Gqe6K71bGRb3ZQLusdI8p/y1KLgV4M/k+/HzVSqT8H0= +github.com/go-openapi/swag/netutils v0.25.4/go.mod h1:m2W8dtdaoX7oj9rEttLyTeEFFEBvnAx9qHd5nJEBzYg= +github.com/go-openapi/swag/stringutils v0.25.4 h1:O6dU1Rd8bej4HPA3/CLPciNBBDwZj9HiEpdVsb8B5A8= +github.com/go-openapi/swag/stringutils v0.25.4/go.mod h1:GTsRvhJW5xM5gkgiFe0fV3PUlFm0dr8vki6/VSRaZK0= +github.com/go-openapi/swag/typeutils v0.25.4 h1:1/fbZOUN472NTc39zpa+YGHn3jzHWhv42wAJSN91wRw= +github.com/go-openapi/swag/typeutils v0.25.4/go.mod h1:Ou7g//Wx8tTLS9vG0UmzfCsjZjKhpjxayRKTHXf2pTE= +github.com/go-openapi/swag/yamlutils v0.25.4 h1:6jdaeSItEUb7ioS9lFoCZ65Cne1/RZtPBZ9A56h92Sw= +github.com/go-openapi/swag/yamlutils v0.25.4/go.mod h1:MNzq1ulQu+yd8Kl7wPOut/YHAAU/H6hL91fF+E2RFwc= +github.com/go-openapi/testify/enable/yaml/v2 v2.0.2 h1:0+Y41Pz1NkbTHz8NngxTuAXxEodtNSI1WG1c/m5Akw4= +github.com/go-openapi/testify/enable/yaml/v2 v2.0.2/go.mod h1:kme83333GCtJQHXQ8UKX3IBZu6z8T5Dvy5+CW3NLUUg= +github.com/go-openapi/testify/v2 v2.0.2 h1:X999g3jeLcoY8qctY/c/Z8iBHTbwLz7R2WXd6Ub6wls= +github.com/go-openapi/testify/v2 v2.0.2/go.mod h1:HCPmvFFnheKK2BuwSA0TbbdxJ3I16pjwMkYkP4Ywn54= +github.com/go-openapi/validate v0.25.1 h1:sSACUI6Jcnbo5IWqbYHgjibrhhmt3vR6lCzKZnmAgBw= +github.com/go-openapi/validate v0.25.1/go.mod h1:RMVyVFYte0gbSTaZ0N4KmTn6u/kClvAFp+mAVfS/DQc= +github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro= +github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/gofrs/flock v0.13.0 h1:95JolYOvGMqeH31+FC7D2+uULf6mG61mEZ/A8dRYMzw= +github.com/gofrs/flock v0.13.0/go.mod h1:jxeyy9R1auM5S6JYDBhDt+E2TCo7DkratH4Pgi8P+Z0= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/renameio v1.0.1 h1:Lh/jXZmvZxb0BBeSY5VKEfidcbcbenKjZFzM/q0fSeU= github.com/google/renameio v1.0.1/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWUAweKUpk= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/haproxytech/client-native/v5 v5.1.9 h1:D+JvMsRHCewn+r+FJpzf3QUu2yHwGuV+s6IuJlajxYE= +github.com/haproxytech/client-native/v5 v5.1.9/go.mod h1:rSJ7gT0vpZqNYdZQwzttLC4doOyoTL+B68F7cDjELNQ= github.com/haproxytech/go-logger v1.1.0 h1:HgGtYaI1ApkvbQdsm7f9AzQQoxTB7w37criTflh7IQE= github.com/haproxytech/go-logger v1.1.0/go.mod h1:OekUd8HCb7ubxMplzHUPBTHNxZmddOWfOjWclZsqIeM= -github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= -github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= @@ -44,8 +73,6 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= -github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -55,32 +82,34 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= +github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sirkon/dst v0.26.4 h1:ETxfjyp5JKE8OCpdybyyhzTyQqq/MwbIIcs7kxcUAcA= github.com/sirkon/dst v0.26.4/go.mod h1:e6HRc56jU5F2XT6GB8Cyci1Jb5cjX6gLqrm5+T/P7Zo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -go.mongodb.org/mongo-driver v1.16.1 h1:rIVLL3q0IHM39dvE+z2ulZLp9ENZKThVfuvN/IiN4l8= -go.mongodb.org/mongo-driver v1.16.1/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw= -golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= -golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= -golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= -golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= -golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= -golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= +go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c= +golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU= +golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o= +golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8= +golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= +golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= +golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= +golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= +golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc= +golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/misc/address.go b/misc/address.go index 049084e9..b57ce2e4 100644 --- a/misc/address.go +++ b/misc/address.go @@ -25,7 +25,7 @@ func SanitizeIPv6Address(addr string) string { switch { case strings.HasPrefix(addr, "ipv6@"), strings.HasPrefix(addr, "udp6@"), - strings.HasPrefix(addr, "quicv6@"): + strings.HasPrefix(addr, "quic6@"): addrSlice := strings.SplitN(addr, "@", 2) if strings.HasPrefix(addrSlice[1], "[") { return addr @@ -60,15 +60,15 @@ func ParseBindAddress(path string) (string, string, error) { // ipv6 address and port is mandatory case strings.HasPrefix(path, "ipv6@"), strings.HasPrefix(path, "udp6@"), - strings.HasPrefix(path, "quicv6@"), + strings.HasPrefix(path, "quic6@"), strings.HasPrefix(path, "["), strings.Count(path, ":") > 1: pathSlice := strings.SplitN(path, "@", 2) prefix := "" - address := "" + var address string if len(pathSlice) > 1 { - prefix = fmt.Sprintf("%s@", pathSlice[0]) + prefix = pathSlice[0] + "@" address = pathSlice[1] } else { address = pathSlice[0] @@ -99,9 +99,9 @@ func ParseBindAddress(path string) (string, string, error) { pathSlice := strings.SplitN(path, "@", 2) prefix := "" - address := "" + var address string if len(pathSlice) > 1 { - prefix = fmt.Sprintf("%s@", pathSlice[0]) + prefix = pathSlice[0] + "@" address = pathSlice[1] } else { address = pathSlice[0] diff --git a/misc/arrayutil.go b/misc/arrayutil.go index a8e459f8..acf150d5 100644 --- a/misc/arrayutil.go +++ b/misc/arrayutil.go @@ -4,23 +4,21 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -// - -package misc +package misc //nolint: revive import ( "reflect" ) // ObjInArray returns true if struct in list y has field named identifier with value value -func ObjInArray(value string, y []interface{}, identifier string) bool { +func ObjInArray(value string, y []any, identifier string) bool { for _, b := range y { objValue := reflect.ValueOf(b).Elem().FieldByName(identifier).String() if objValue == value { @@ -31,7 +29,7 @@ func ObjInArray(value string, y []interface{}, identifier string) bool { } // GetObjByField returns struct from list l if it has field named identifier with value value -func GetObjByField(l []interface{}, identifier string, value string) interface{} { +func GetObjByField(l []any, identifier string, value string) any { for _, b := range l { objValue := reflect.ValueOf(b).Elem().FieldByName(identifier).String() if objValue == value { diff --git a/misc/fs.go b/misc/fs.go index 390aff41..015882c9 100644 --- a/misc/fs.go +++ b/misc/fs.go @@ -1,6 +1,7 @@ package misc import ( + "errors" "fmt" "os" "path/filepath" @@ -8,7 +9,7 @@ import ( func CheckOrCreateWritableDirectory(dirname string) (string, error) { if dirname == "" { - return dirname, fmt.Errorf("no storage dir or empty dirname specified") + return dirname, errors.New("no storage dir or empty dirname specified") } dirname = filepath.Clean(dirname) @@ -38,8 +39,8 @@ func CheckOrCreateWritableDirectory(dirname string) (string, error) { } // CreateTempDir will create a new temporary dir. If config is provided it will create a file with its content -func CreateTempDir(config string, createFile bool, extension ...string) (dirname, file string, err error) { - dirname, err = os.MkdirTemp("/tmp", "storage") +func CreateTempDir(config string, createFile bool, extension ...string) (string, string, error) { + dirname, err := os.MkdirTemp("/tmp", "storage") if err != nil { return "", "", err } diff --git a/misc/reflect.go b/misc/reflect.go index edb6579a..dcf5aa4c 100644 --- a/misc/reflect.go +++ b/misc/reflect.go @@ -4,21 +4,19 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -// - package misc import "reflect" // IsZeroValue is a helper method for reflect, checks if reflect.Value has zero value -func IsZeroValue(v reflect.Value) bool { +func IsZeroValue(v reflect.Value) bool { //nolint:revive switch v.Kind() { //nolint:exhaustive case reflect.Array, reflect.String: return v.Len() == 0 diff --git a/misc/stringutil.go b/misc/stringutil.go index 7f5b1c64..e162ff28 100644 --- a/misc/stringutil.go +++ b/misc/stringutil.go @@ -20,6 +20,7 @@ import ( "math/rand" "path/filepath" "regexp" + "slices" "strconv" "strings" "time" @@ -29,31 +30,26 @@ var chars = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX // StringInSlice checks if a string is in a list of strings func StringInSlice(a string, list []string) bool { - for _, b := range list { - if b == a { - return true - } - } - return false + return slices.Contains(list, a) } // CamelCase turns snake case to camel case string func CamelCase(fieldName string, initCase bool) string { s := strings.Trim(fieldName, " ") - n := "" capNext := initCase + sb := strings.Builder{} for _, v := range s { if v >= 'A' && v <= 'Z' { - n += string(v) + sb.WriteRune(v) } if v >= '0' && v <= '9' { - n += string(v) + sb.WriteRune(v) } if v >= 'a' && v <= 'z' { if capNext { - n += strings.ToUpper(string(v)) + sb.WriteString(strings.ToUpper(string(v))) } else { - n += string(v) + sb.WriteRune(v) } } if v == '_' || v == ' ' || v == '-' { @@ -62,6 +58,7 @@ func CamelCase(fieldName string, initCase bool) string { capNext = false } } + n := sb.String() // special cases n = strings.ReplaceAll(n, "Http", "HTTP") n = strings.ReplaceAll(n, "Uri", "URI") @@ -109,38 +106,32 @@ func SnakeCase(fieldName string) string { } // DashCase turns camel case to snake case string -func DashCase(fieldName string) string { - fieldName = strings.Trim(fieldName, " ") - n := "" - for i, v := range fieldName { - // treat acronyms as words, eg for JSONData -> JSON is a whole word - nextCaseIsChanged := false - if i+1 < len(fieldName) { - next := fieldName[i+1] - if (v >= 'A' && v <= 'Z' && next >= 'a' && next <= 'z') || (v >= 'a' && v <= 'z' && next >= 'A' && next <= 'Z') { - nextCaseIsChanged = true - } - } - - switch { - case i > 0 && n[len(n)-1] != '-' && nextCaseIsChanged: - // add underscore if next letter case type is changed - if v >= 'A' && v <= 'Z' { - n += "-" + string(v) - } else if v >= 'a' && v <= 'z' { - n += string(v) + "-" +func DashCase(input string) string { + var result strings.Builder + n := len(input) + // Grow to worst case where a dash is inserted every character. + result.Grow(n * 2) + + for i, r := range input { + // if r is capital .. + if r >= 'A' && r <= 'Z' { + // add a dash before if : + // 1. we're not on the first or last character. + // 2. the previous character is not capital. + // 3. the next character is not capital. + // To understand the rules take "JSONData" -> "json-data" as an example + if i > 0 && !(input[i-1] >= 'A' && input[i-1] <= 'Z' && (i+1 == n || i+1 < n && input[i+1] >= 'A' && input[i+1] <= 'Z')) { //nolint: staticcheck + result.WriteByte('-') } - case v == ' ': - // replace spaces with underscores - n += "-" - default: - n += string(v) + // Lower the case of the character + result.WriteByte(byte(r + ('a' - 'A'))) + } else { + // If lowercase just write it + result.WriteRune(r) } } - n = strings.ToLower(n) - // special case - n = strings.ReplaceAll(n, "httpuri", "http-uri") - return n + + return strings.ReplaceAll(result.String(), "httpuri", "http-uri") } func ParseSize(size string) *int64 { @@ -244,7 +235,7 @@ func SanitizeFilename(name string) string { if name != "" { return fmt.Sprintf("%s.%s", name, ext) } - return fmt.Sprintf("_%s", ext) + return "_" + ext } return name diff --git a/misc/stringutil_test.go b/misc/stringutil_test.go index 8ab0d1f9..d182d666 100644 --- a/misc/stringutil_test.go +++ b/misc/stringutil_test.go @@ -57,3 +57,87 @@ func TestSanitizeFilename(t *testing.T) { }) } } + +func TestDashCase(t *testing.T) { + tests := []struct { + fieldname string + dashcase string + }{ + {fieldname: "Abortonclose", dashcase: "abortonclose"}, + {fieldname: "AcceptInvalidHTTPRequest", dashcase: "accept-invalid-http-request"}, + {fieldname: "AcceptInvalidHTTPResponse", dashcase: "accept-invalid-http-response"}, + {fieldname: "Backlog", dashcase: "backlog"}, + {fieldname: "Check", dashcase: "check"}, + {fieldname: "Checkcache", dashcase: "checkcache"}, + {fieldname: "Client", dashcase: "client"}, + {fieldname: "ClientFin", dashcase: "client-fin"}, + {fieldname: "Clitcpka", dashcase: "clitcpka"}, + {fieldname: "ClitcpkaCnt", dashcase: "clitcpka-cnt"}, + {fieldname: "Connect", dashcase: "connect"}, + {fieldname: "Contstats", dashcase: "contstats"}, + {fieldname: "DisableH2Upgrade", dashcase: "disable-h2-upgrade"}, + {fieldname: "Disabled", dashcase: "disabled"}, + {fieldname: "DontlogNormal", dashcase: "dontlog-normal"}, + {fieldname: "Dontlognull", dashcase: "dontlognull"}, + {fieldname: "DynamicCookieKey", dashcase: "dynamic-cookie-key"}, + {fieldname: "Enabled", dashcase: "enabled"}, + {fieldname: "ErrorLogFormat", dashcase: "error-log-format"}, + {fieldname: "Fullconn", dashcase: "fullconn"}, + {fieldname: "H1CaseAdjustBogusClient", dashcase: "h1-case-adjust-bogus-client"}, + {fieldname: "H1CaseAdjustBogusServer", dashcase: "h1-case-adjust-bogus-server"}, + {fieldname: "HashBalanceFactor", dashcase: "hash-balance-factor"}, + {fieldname: "HTTPBufferRequest", dashcase: "http-buffer-request"}, + {fieldname: "HTTPIgnoreProbes", dashcase: "http-ignore-probes"}, + {fieldname: "HTTPKeepAlive", dashcase: "http-keep-alive"}, + {fieldname: "HTTPNoDelay", dashcase: "http-no-delay"}, + {fieldname: "HTTPPretendKeepalive", dashcase: "http-pretend-keepalive"}, + {fieldname: "HTTPRequest", dashcase: "http-request"}, + {fieldname: "HTTPUseHtx", dashcase: "http-use-htx"}, + {fieldname: "HTTPUseProxyHeader", dashcase: "http-use-proxy-header"}, + {fieldname: "HttpchkParams", dashcase: "httpchk-params"}, + {fieldname: "Httpslog", dashcase: "httpslog"}, + {fieldname: "IdleCloseOnResponse", dashcase: "idle-close-on-response"}, + {fieldname: "IndependentStreams", dashcase: "independent-streams"}, + {fieldname: "LogFormat", dashcase: "log-format"}, + {fieldname: "LogFormatSd", dashcase: "log-format-sd"}, + {fieldname: "LogHealthChecks", dashcase: "log-health-checks"}, + {fieldname: "LogSeparateErrors", dashcase: "log-separate-errors"}, + {fieldname: "LogTag", dashcase: "log-tag"}, + {fieldname: "MaxKeepAliveQueue", dashcase: "max-keep-alive-queue"}, + {fieldname: "Maxconn", dashcase: "maxconn"}, + {fieldname: "Mode", dashcase: "mode"}, + {fieldname: "MysqlCheckParams", dashcase: "mysql-check-params"}, + {fieldname: "Name", dashcase: "name"}, + {fieldname: "Nolinger", dashcase: "nolinger"}, + {fieldname: "Persist", dashcase: "persist"}, + {fieldname: "PgsqlCheckParams", dashcase: "pgsql-check-params"}, + {fieldname: "PreferLastServer", dashcase: "prefer-last-server"}, + {fieldname: "Queue", dashcase: "queue"}, + {fieldname: "Retries", dashcase: "retries"}, + {fieldname: "RetryOn", dashcase: "retry-on"}, + {fieldname: "Server", dashcase: "server"}, + {fieldname: "ServerFin", dashcase: "server-fin"}, + {fieldname: "SmtpchkParams", dashcase: "smtpchk-params"}, + {fieldname: "SocketStats", dashcase: "socket-stats"}, + {fieldname: "SpliceAuto", dashcase: "splice-auto"}, + {fieldname: "SpliceRequest", dashcase: "splice-request"}, + {fieldname: "SpliceResponse", dashcase: "splice-response"}, + {fieldname: "Srvtcpka", dashcase: "srvtcpka"}, + {fieldname: "SrvtcpkaCnt", dashcase: "srvtcpka-cnt"}, + {fieldname: "Tarpit", dashcase: "tarpit"}, + {fieldname: "TCPSmartAccept", dashcase: "tcp-smart-accept"}, + {fieldname: "TCPSmartConnect", dashcase: "tcp-smart-connect"}, + {fieldname: "Tcpka", dashcase: "tcpka"}, + {fieldname: "Tcplog", dashcase: "tcplog"}, + {fieldname: "Transparent", dashcase: "transparent"}, + {fieldname: "Tunnel", dashcase: "tunnel"}, + } + + for _, tt := range tests { + t.Run(tt.fieldname, func(t *testing.T) { + if got := DashCase(tt.fieldname); got != tt.dashcase { + t.Errorf("DashCase(%s) = %s, want %s", tt.fieldname, got, tt.dashcase) + } + }) + } +} diff --git a/models/acl_compare_test.go b/models/acl_compare_test.go index 74dcedf9..acda6504 100644 --- a/models/acl_compare_test.go +++ b/models/acl_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestACLEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ACL var result ACL - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestACLEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ACL to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestACLEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ACL var result ACL - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ACL @@ -94,11 +97,11 @@ func TestACLEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ACL to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestACLDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ACL var result ACL - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestACLDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ACL to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestACLDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ACL var result ACL - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ACL @@ -173,11 +176,11 @@ func TestACLDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ACL to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/acl_file_compare_test.go b/models/acl_file_compare_test.go index adf2f1d7..b23edf84 100644 --- a/models/acl_file_compare_test.go +++ b/models/acl_file_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestACLFileEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ACLFile var result ACLFile - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestACLFileEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ACLFile to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestACLFileEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ACLFile var result ACLFile - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ACLFile @@ -94,11 +97,11 @@ func TestACLFileEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ACLFile to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestACLFileDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ACLFile var result ACLFile - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestACLFileDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ACLFile to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestACLFileDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ACLFile var result ACLFile - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ACLFile @@ -173,11 +176,11 @@ func TestACLFileDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ACLFile to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/acl_file_entry_compare_test.go b/models/acl_file_entry_compare_test.go index 2e5b4742..1029267b 100644 --- a/models/acl_file_entry_compare_test.go +++ b/models/acl_file_entry_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestACLFileEntryEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ACLFileEntry var result ACLFileEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestACLFileEntryEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ACLFileEntry to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestACLFileEntryEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ACLFileEntry var result ACLFileEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ACLFileEntry @@ -94,11 +97,11 @@ func TestACLFileEntryEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ACLFileEntry to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestACLFileEntryDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ACLFileEntry var result ACLFileEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestACLFileEntryDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ACLFileEntry to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestACLFileEntryDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ACLFileEntry var result ACLFileEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ACLFileEntry @@ -173,11 +176,11 @@ func TestACLFileEntryDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ACLFileEntry to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/acl_files.go b/models/acl_files.go index e31edb5b..ce8cca49 100644 --- a/models/acl_files.go +++ b/models/acl_files.go @@ -71,6 +71,11 @@ func (m ACLFiles) ContextValidate(ctx context.Context, formats strfmt.Registry) for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/acl_files_entries.go b/models/acl_files_entries.go index 5a1a3263..233cb0e8 100644 --- a/models/acl_files_entries.go +++ b/models/acl_files_entries.go @@ -71,6 +71,11 @@ func (m ACLFilesEntries) ContextValidate(ctx context.Context, formats strfmt.Reg for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/acls.go b/models/acls.go index c2449673..b5d1e122 100644 --- a/models/acls.go +++ b/models/acls.go @@ -71,6 +71,11 @@ func (m Acls) ContextValidate(ctx context.Context, formats strfmt.Registry) erro for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/aws_filters_compare_test.go b/models/aws_filters_compare_test.go index 47ce570a..fed77dcc 100644 --- a/models/aws_filters_compare_test.go +++ b/models/aws_filters_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestAwsFiltersEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample AwsFilters var result AwsFilters - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestAwsFiltersEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected AwsFilters to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestAwsFiltersEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample AwsFilters var result AwsFilters - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b AwsFilters @@ -94,11 +97,11 @@ func TestAwsFiltersEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected AwsFilters to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestAwsFiltersDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample AwsFilters var result AwsFilters - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestAwsFiltersDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected AwsFilters to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestAwsFiltersDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample AwsFilters var result AwsFilters - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b AwsFilters @@ -173,11 +176,11 @@ func TestAwsFiltersDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected AwsFilters to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/aws_region.go b/models/aws_region.go index 8ce5817f..7597cf8b 100644 --- a/models/aws_region.go +++ b/models/aws_region.go @@ -63,7 +63,7 @@ type AwsRegion struct { // Select which IPv4 address the Service Discovery has to use for the backend server entry // Required: true - // Enum: [private public] + // Enum: ["private","public"] // +kubebuilder:validation:Enum=private;public; IPV4Address *string `json:"ipv4_address"` @@ -91,7 +91,7 @@ type AwsRegion struct { ServerSlotsGrowthIncrement int64 `json:"server_slots_growth_increment,omitempty"` // server slots growth type - // Enum: [linear exponential] + // Enum: ["linear","exponential"] // +kubebuilder:validation:Enum=linear;exponential; ServerSlotsGrowthType *string `json:"server_slots_growth_type,omitempty"` } @@ -358,6 +358,11 @@ func (m *AwsRegion) contextValidateAllowlist(ctx context.Context, formats strfmt for i := 0; i < len(m.Allowlist); i++ { if m.Allowlist[i] != nil { + + if swag.IsZero(m.Allowlist[i]) { // not required + return nil + } + if err := m.Allowlist[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("allowlist" + "." + strconv.Itoa(i)) @@ -378,6 +383,11 @@ func (m *AwsRegion) contextValidateDenylist(ctx context.Context, formats strfmt. for i := 0; i < len(m.Denylist); i++ { if m.Denylist[i] != nil { + + if swag.IsZero(m.Denylist[i]) { // not required + return nil + } + if err := m.Denylist[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("denylist" + "." + strconv.Itoa(i)) diff --git a/models/aws_region_compare_test.go b/models/aws_region_compare_test.go index 5ee5ee63..68293aaf 100644 --- a/models/aws_region_compare_test.go +++ b/models/aws_region_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestAwsRegionEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample AwsRegion var result AwsRegion - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestAwsRegionEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected AwsRegion to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestAwsRegionEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample AwsRegion var result AwsRegion - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Enabled = Ptr(!*sample.Enabled) result.RetryTimeout = Ptr(*sample.RetryTimeout + 1) @@ -98,11 +101,11 @@ func TestAwsRegionEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected AwsRegion to be different, but it is not %s %s", a, b) } @@ -116,17 +119,17 @@ func TestAwsRegionDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample AwsRegion var result AwsRegion - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -140,11 +143,11 @@ func TestAwsRegionDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected AwsRegion to be equal, but it is not %s %s, %v", a, b, result) } @@ -158,13 +161,13 @@ func TestAwsRegionDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample AwsRegion var result AwsRegion - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Enabled = Ptr(!*sample.Enabled) result.RetryTimeout = Ptr(*sample.RetryTimeout + 1) @@ -181,11 +184,11 @@ func TestAwsRegionDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected AwsRegion to be different in 14 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/aws_regions.go b/models/aws_regions.go index bf1df8b3..490a2244 100644 --- a/models/aws_regions.go +++ b/models/aws_regions.go @@ -71,6 +71,11 @@ func (m AwsRegions) ContextValidate(ctx context.Context, formats strfmt.Registry for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/backend_base.go b/models/backend_base.go index ad31613d..b4950796 100644 --- a/models/backend_base.go +++ b/models/backend_base.go @@ -52,22 +52,22 @@ type BackendBase struct { IgnorePersistList []*IgnorePersist `json:"ignore_persist_list,omitempty"` // abortonclose - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Abortonclose string `json:"abortonclose,omitempty"` // accept invalid http response - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; AcceptInvalidHTTPResponse string `json:"accept_invalid_http_response,omitempty"` // adv check - // Enum: [httpchk ldap-check mysql-check pgsql-check redis-check smtpchk ssl-hello-chk tcp-check] + // Enum: ["httpchk","ldap-check","mysql-check","pgsql-check","redis-check","smtpchk","ssl-hello-chk","tcp-check"] // +kubebuilder:validation:Enum=httpchk;ldap-check;mysql-check;pgsql-check;redis-check;smtpchk;ssl-hello-chk;tcp-check; AdvCheck string `json:"adv_check,omitempty"` // allbackups - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Allbackups string `json:"allbackups,omitempty"` @@ -78,7 +78,7 @@ type BackendBase struct { CheckTimeout *int64 `json:"check_timeout,omitempty"` // checkcache - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Checkcache string `json:"checkcache,omitempty"` @@ -120,7 +120,7 @@ type BackendBase struct { Errorloc303 *Errorloc `json:"errorloc303,omitempty"` // external check - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ExternalCheck string `json:"external_check,omitempty"` @@ -154,7 +154,7 @@ type BackendBase struct { GUID string `json:"guid,omitempty"` // h1 case adjust bogus server - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; H1CaseAdjustBogusServer string `json:"h1_case_adjust_bogus_server,omitempty"` @@ -165,24 +165,24 @@ type BackendBase struct { HashType *HashType `json:"hash_type,omitempty"` // http buffer request - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; HTTPBufferRequest string `json:"http-buffer-request,omitempty"` // http no delay - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; HTTPNoDelay string `json:"http-no-delay,omitempty"` // http use htx // Pattern: ^[^\s]+$ - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Pattern=`^[^\s]+$` // +kubebuilder:validation:Enum=enabled;disabled; HTTPUseHtx string `json:"http-use-htx,omitempty"` // http connection mode - // Enum: [httpclose http-server-close http-keep-alive] + // Enum: ["httpclose","http-server-close","http-keep-alive"] // +kubebuilder:validation:Enum=httpclose;http-server-close;http-keep-alive; HTTPConnectionMode string `json:"http_connection_mode,omitempty"` @@ -192,12 +192,12 @@ type BackendBase struct { HTTPKeepAliveTimeout *int64 `json:"http_keep_alive_timeout,omitempty"` // http pretend keepalive - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; HTTPPretendKeepalive string `json:"http_pretend_keepalive,omitempty"` // http proxy - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; HTTPProxy string `json:"http_proxy,omitempty"` @@ -207,12 +207,12 @@ type BackendBase struct { HTTPRequestTimeout *int64 `json:"http_request_timeout,omitempty"` // http restrict req hdr names - // Enum: [preserve delete reject] + // Enum: ["preserve","delete","reject"] // +kubebuilder:validation:Enum=preserve;delete;reject; HTTPRestrictReqHdrNames string `json:"http_restrict_req_hdr_names,omitempty"` // http reuse - // Enum: [aggressive always never safe] + // Enum: ["aggressive","always","never","safe"] // +kubebuilder:validation:Enum=aggressive;always;never;safe; HTTPReuse string `json:"http_reuse,omitempty"` @@ -229,17 +229,17 @@ type BackendBase struct { IgnorePersist *BackendIgnorePersist `json:"ignore_persist,omitempty"` // independent streams - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; IndependentStreams string `json:"independent_streams,omitempty"` // load server state from file - // Enum: [global local none] + // Enum: ["global","local","none"] // +kubebuilder:validation:Enum=global;local;none; LoadServerStateFromFile string `json:"load_server_state_from_file,omitempty"` // log health checks - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; LogHealthChecks string `json:"log_health_checks,omitempty"` @@ -252,7 +252,7 @@ type BackendBase struct { MaxKeepAliveQueue *int64 `json:"max_keep_alive_queue,omitempty"` // mode - // Enum: [http tcp log] + // Enum: ["http","tcp","log"] // +kubebuilder:validation:Enum=http;tcp;log; Mode string `json:"mode,omitempty"` @@ -266,7 +266,7 @@ type BackendBase struct { Name string `json:"name"` // nolinger - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Nolinger string `json:"nolinger,omitempty"` @@ -274,7 +274,7 @@ type BackendBase struct { Originalto *Originalto `json:"originalto,omitempty"` // persist - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Persist string `json:"persist,omitempty"` @@ -285,7 +285,7 @@ type BackendBase struct { PgsqlCheckParams *PgsqlCheckParams `json:"pgsql_check_params,omitempty"` // prefer last server - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; PreferLastServer string `json:"prefer_last_server,omitempty"` @@ -323,27 +323,27 @@ type BackendBase struct { Source *Source `json:"source,omitempty"` // splice auto - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SpliceAuto string `json:"splice_auto,omitempty"` // splice request - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SpliceRequest string `json:"splice_request,omitempty"` // splice response - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SpliceResponse string `json:"splice_response,omitempty"` // spop check - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SpopCheck string `json:"spop_check,omitempty"` // srvtcpka - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Srvtcpka string `json:"srvtcpka,omitempty"` @@ -368,17 +368,17 @@ type BackendBase struct { TarpitTimeout *int64 `json:"tarpit_timeout,omitempty"` // tcp smart connect - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; TCPSmartConnect string `json:"tcp_smart_connect,omitempty"` // tcpka - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Tcpka string `json:"tcpka,omitempty"` // transparent - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Transparent string `json:"transparent,omitempty"` @@ -2780,6 +2780,11 @@ func (m *BackendBase) contextValidateErrorFiles(ctx context.Context, formats str for i := 0; i < len(m.ErrorFiles); i++ { if m.ErrorFiles[i] != nil { + + if swag.IsZero(m.ErrorFiles[i]) { // not required + return nil + } + if err := m.ErrorFiles[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("error_files" + "." + strconv.Itoa(i)) @@ -2800,6 +2805,11 @@ func (m *BackendBase) contextValidateErrorFilesFromHTTPErrors(ctx context.Contex for i := 0; i < len(m.ErrorFilesFromHTTPErrors); i++ { if m.ErrorFilesFromHTTPErrors[i] != nil { + + if swag.IsZero(m.ErrorFilesFromHTTPErrors[i]) { // not required + return nil + } + if err := m.ErrorFilesFromHTTPErrors[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("errorfiles_from_http_errors" + "." + strconv.Itoa(i)) @@ -2820,6 +2830,11 @@ func (m *BackendBase) contextValidateForcePersistList(ctx context.Context, forma for i := 0; i < len(m.ForcePersistList); i++ { if m.ForcePersistList[i] != nil { + + if swag.IsZero(m.ForcePersistList[i]) { // not required + return nil + } + if err := m.ForcePersistList[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("force_persist_list" + "." + strconv.Itoa(i)) @@ -2840,6 +2855,11 @@ func (m *BackendBase) contextValidateIgnorePersistList(ctx context.Context, form for i := 0; i < len(m.IgnorePersistList); i++ { if m.IgnorePersistList[i] != nil { + + if swag.IsZero(m.IgnorePersistList[i]) { // not required + return nil + } + if err := m.IgnorePersistList[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("ignore_persist_list" + "." + strconv.Itoa(i)) @@ -2858,6 +2878,11 @@ func (m *BackendBase) contextValidateIgnorePersistList(ctx context.Context, form func (m *BackendBase) contextValidateBalance(ctx context.Context, formats strfmt.Registry) error { if m.Balance != nil { + + if swag.IsZero(m.Balance) { // not required + return nil + } + if err := m.Balance.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("balance") @@ -2874,6 +2899,11 @@ func (m *BackendBase) contextValidateBalance(ctx context.Context, formats strfmt func (m *BackendBase) contextValidateCompression(ctx context.Context, formats strfmt.Registry) error { if m.Compression != nil { + + if swag.IsZero(m.Compression) { // not required + return nil + } + if err := m.Compression.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("compression") @@ -2890,6 +2920,11 @@ func (m *BackendBase) contextValidateCompression(ctx context.Context, formats st func (m *BackendBase) contextValidateCookie(ctx context.Context, formats strfmt.Registry) error { if m.Cookie != nil { + + if swag.IsZero(m.Cookie) { // not required + return nil + } + if err := m.Cookie.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("cookie") @@ -2906,6 +2941,11 @@ func (m *BackendBase) contextValidateCookie(ctx context.Context, formats strfmt. func (m *BackendBase) contextValidateDefaultServer(ctx context.Context, formats strfmt.Registry) error { if m.DefaultServer != nil { + + if swag.IsZero(m.DefaultServer) { // not required + return nil + } + if err := m.DefaultServer.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("default_server") @@ -2922,6 +2962,11 @@ func (m *BackendBase) contextValidateDefaultServer(ctx context.Context, formats func (m *BackendBase) contextValidateEmailAlert(ctx context.Context, formats strfmt.Registry) error { if m.EmailAlert != nil { + + if swag.IsZero(m.EmailAlert) { // not required + return nil + } + if err := m.EmailAlert.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("email_alert") @@ -2938,6 +2983,11 @@ func (m *BackendBase) contextValidateEmailAlert(ctx context.Context, formats str func (m *BackendBase) contextValidateErrorloc302(ctx context.Context, formats strfmt.Registry) error { if m.Errorloc302 != nil { + + if swag.IsZero(m.Errorloc302) { // not required + return nil + } + if err := m.Errorloc302.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("errorloc302") @@ -2954,6 +3004,11 @@ func (m *BackendBase) contextValidateErrorloc302(ctx context.Context, formats st func (m *BackendBase) contextValidateErrorloc303(ctx context.Context, formats strfmt.Registry) error { if m.Errorloc303 != nil { + + if swag.IsZero(m.Errorloc303) { // not required + return nil + } + if err := m.Errorloc303.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("errorloc303") @@ -2970,6 +3025,11 @@ func (m *BackendBase) contextValidateErrorloc303(ctx context.Context, formats st func (m *BackendBase) contextValidateForcePersist(ctx context.Context, formats strfmt.Registry) error { if m.ForcePersist != nil { + + if swag.IsZero(m.ForcePersist) { // not required + return nil + } + if err := m.ForcePersist.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("force_persist") @@ -2986,6 +3046,11 @@ func (m *BackendBase) contextValidateForcePersist(ctx context.Context, formats s func (m *BackendBase) contextValidateForwardfor(ctx context.Context, formats strfmt.Registry) error { if m.Forwardfor != nil { + + if swag.IsZero(m.Forwardfor) { // not required + return nil + } + if err := m.Forwardfor.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("forwardfor") @@ -3002,6 +3067,11 @@ func (m *BackendBase) contextValidateForwardfor(ctx context.Context, formats str func (m *BackendBase) contextValidateHashType(ctx context.Context, formats strfmt.Registry) error { if m.HashType != nil { + + if swag.IsZero(m.HashType) { // not required + return nil + } + if err := m.HashType.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("hash_type") @@ -3018,6 +3088,11 @@ func (m *BackendBase) contextValidateHashType(ctx context.Context, formats strfm func (m *BackendBase) contextValidateHttpchkParams(ctx context.Context, formats strfmt.Registry) error { if m.HttpchkParams != nil { + + if swag.IsZero(m.HttpchkParams) { // not required + return nil + } + if err := m.HttpchkParams.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("httpchk_params") @@ -3034,6 +3109,11 @@ func (m *BackendBase) contextValidateHttpchkParams(ctx context.Context, formats func (m *BackendBase) contextValidateIgnorePersist(ctx context.Context, formats strfmt.Registry) error { if m.IgnorePersist != nil { + + if swag.IsZero(m.IgnorePersist) { // not required + return nil + } + if err := m.IgnorePersist.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("ignore_persist") @@ -3050,6 +3130,11 @@ func (m *BackendBase) contextValidateIgnorePersist(ctx context.Context, formats func (m *BackendBase) contextValidateMysqlCheckParams(ctx context.Context, formats strfmt.Registry) error { if m.MysqlCheckParams != nil { + + if swag.IsZero(m.MysqlCheckParams) { // not required + return nil + } + if err := m.MysqlCheckParams.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("mysql_check_params") @@ -3066,6 +3151,11 @@ func (m *BackendBase) contextValidateMysqlCheckParams(ctx context.Context, forma func (m *BackendBase) contextValidateOriginalto(ctx context.Context, formats strfmt.Registry) error { if m.Originalto != nil { + + if swag.IsZero(m.Originalto) { // not required + return nil + } + if err := m.Originalto.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("originalto") @@ -3082,6 +3172,11 @@ func (m *BackendBase) contextValidateOriginalto(ctx context.Context, formats str func (m *BackendBase) contextValidatePersistRule(ctx context.Context, formats strfmt.Registry) error { if m.PersistRule != nil { + + if swag.IsZero(m.PersistRule) { // not required + return nil + } + if err := m.PersistRule.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("persist_rule") @@ -3098,6 +3193,11 @@ func (m *BackendBase) contextValidatePersistRule(ctx context.Context, formats st func (m *BackendBase) contextValidatePgsqlCheckParams(ctx context.Context, formats strfmt.Registry) error { if m.PgsqlCheckParams != nil { + + if swag.IsZero(m.PgsqlCheckParams) { // not required + return nil + } + if err := m.PgsqlCheckParams.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("pgsql_check_params") @@ -3114,6 +3214,11 @@ func (m *BackendBase) contextValidatePgsqlCheckParams(ctx context.Context, forma func (m *BackendBase) contextValidateRedispatch(ctx context.Context, formats strfmt.Registry) error { if m.Redispatch != nil { + + if swag.IsZero(m.Redispatch) { // not required + return nil + } + if err := m.Redispatch.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("redispatch") @@ -3130,6 +3235,11 @@ func (m *BackendBase) contextValidateRedispatch(ctx context.Context, formats str func (m *BackendBase) contextValidateSmtpchkParams(ctx context.Context, formats strfmt.Registry) error { if m.SmtpchkParams != nil { + + if swag.IsZero(m.SmtpchkParams) { // not required + return nil + } + if err := m.SmtpchkParams.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("smtpchk_params") @@ -3146,6 +3256,11 @@ func (m *BackendBase) contextValidateSmtpchkParams(ctx context.Context, formats func (m *BackendBase) contextValidateSource(ctx context.Context, formats strfmt.Registry) error { if m.Source != nil { + + if swag.IsZero(m.Source) { // not required + return nil + } + if err := m.Source.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("source") @@ -3162,6 +3277,11 @@ func (m *BackendBase) contextValidateSource(ctx context.Context, formats strfmt. func (m *BackendBase) contextValidateStatsOptions(ctx context.Context, formats strfmt.Registry) error { if m.StatsOptions != nil { + + if swag.IsZero(m.StatsOptions) { // not required + return nil + } + if err := m.StatsOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("stats_options") @@ -3178,6 +3298,11 @@ func (m *BackendBase) contextValidateStatsOptions(ctx context.Context, formats s func (m *BackendBase) contextValidateStickTable(ctx context.Context, formats strfmt.Registry) error { if m.StickTable != nil { + + if swag.IsZero(m.StickTable) { // not required + return nil + } + if err := m.StickTable.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("stick_table") @@ -3215,7 +3340,7 @@ func (m *BackendBase) UnmarshalBinary(b []byte) error { type BackendForcePersist struct { // cond // Required: true - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond *string `json:"cond"` @@ -3323,7 +3448,7 @@ func (m *BackendForcePersist) UnmarshalBinary(b []byte) error { type ForcePersist struct { // cond // Required: true - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond *string `json:"cond"` @@ -3431,7 +3556,7 @@ func (m *ForcePersist) UnmarshalBinary(b []byte) error { type BackendIgnorePersist struct { // cond // Required: true - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond *string `json:"cond"` @@ -3539,7 +3664,7 @@ func (m *BackendIgnorePersist) UnmarshalBinary(b []byte) error { type IgnorePersist struct { // cond // Required: true - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond *string `json:"cond"` diff --git a/models/backend_base_compare_test.go b/models/backend_base_compare_test.go index 2ac4d79e..48dd8c65 100644 --- a/models/backend_base_compare_test.go +++ b/models/backend_base_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestBackendBaseEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendBase var result BackendBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestBackendBaseEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendBase to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestBackendBaseEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendBase var result BackendBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CheckTimeout = Ptr(*sample.CheckTimeout + 1) result.ConnectTimeout = Ptr(*sample.ConnectTimeout + 1) @@ -113,11 +116,11 @@ func TestBackendBaseEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendBase to be different, but it is not %s %s", a, b) } @@ -131,17 +134,17 @@ func TestBackendBaseDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendBase var result BackendBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -155,11 +158,11 @@ func TestBackendBaseDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendBase to be equal, but it is not %s %s, %v", a, b, result) } @@ -173,13 +176,13 @@ func TestBackendBaseDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendBase var result BackendBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CheckTimeout = Ptr(*sample.CheckTimeout + 1) result.ConnectTimeout = Ptr(*sample.ConnectTimeout + 1) @@ -211,11 +214,11 @@ func TestBackendBaseDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendBase to be different in 86 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -229,17 +232,17 @@ func TestBackendForcePersistEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendForcePersist var result BackendForcePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -253,11 +256,11 @@ func TestBackendForcePersistEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendForcePersist to be equal, but it is not %s %s", a, b) } @@ -271,13 +274,13 @@ func TestBackendForcePersistEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendForcePersist var result BackendForcePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b BackendForcePersist @@ -290,11 +293,11 @@ func TestBackendForcePersistEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendForcePersist to be different, but it is not %s %s", a, b) } @@ -308,17 +311,17 @@ func TestBackendForcePersistDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendForcePersist var result BackendForcePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -332,11 +335,11 @@ func TestBackendForcePersistDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendForcePersist to be equal, but it is not %s %s, %v", a, b, result) } @@ -350,13 +353,13 @@ func TestBackendForcePersistDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendForcePersist var result BackendForcePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b BackendForcePersist @@ -369,11 +372,11 @@ func TestBackendForcePersistDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendForcePersist to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -387,17 +390,17 @@ func TestForcePersistEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ForcePersist var result ForcePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -411,11 +414,11 @@ func TestForcePersistEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ForcePersist to be equal, but it is not %s %s", a, b) } @@ -429,13 +432,13 @@ func TestForcePersistEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ForcePersist var result ForcePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ForcePersist @@ -448,11 +451,11 @@ func TestForcePersistEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ForcePersist to be different, but it is not %s %s", a, b) } @@ -466,17 +469,17 @@ func TestForcePersistDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ForcePersist var result ForcePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -490,11 +493,11 @@ func TestForcePersistDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ForcePersist to be equal, but it is not %s %s, %v", a, b, result) } @@ -508,13 +511,13 @@ func TestForcePersistDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ForcePersist var result ForcePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ForcePersist @@ -527,11 +530,11 @@ func TestForcePersistDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ForcePersist to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -545,17 +548,17 @@ func TestBackendIgnorePersistEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendIgnorePersist var result BackendIgnorePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -569,11 +572,11 @@ func TestBackendIgnorePersistEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendIgnorePersist to be equal, but it is not %s %s", a, b) } @@ -587,13 +590,13 @@ func TestBackendIgnorePersistEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendIgnorePersist var result BackendIgnorePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b BackendIgnorePersist @@ -606,11 +609,11 @@ func TestBackendIgnorePersistEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendIgnorePersist to be different, but it is not %s %s", a, b) } @@ -624,17 +627,17 @@ func TestBackendIgnorePersistDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendIgnorePersist var result BackendIgnorePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -648,11 +651,11 @@ func TestBackendIgnorePersistDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendIgnorePersist to be equal, but it is not %s %s, %v", a, b, result) } @@ -666,13 +669,13 @@ func TestBackendIgnorePersistDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendIgnorePersist var result BackendIgnorePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b BackendIgnorePersist @@ -685,11 +688,11 @@ func TestBackendIgnorePersistDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendIgnorePersist to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -703,17 +706,17 @@ func TestIgnorePersistEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample IgnorePersist var result IgnorePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -727,11 +730,11 @@ func TestIgnorePersistEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected IgnorePersist to be equal, but it is not %s %s", a, b) } @@ -745,13 +748,13 @@ func TestIgnorePersistEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample IgnorePersist var result IgnorePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b IgnorePersist @@ -764,11 +767,11 @@ func TestIgnorePersistEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected IgnorePersist to be different, but it is not %s %s", a, b) } @@ -782,17 +785,17 @@ func TestIgnorePersistDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample IgnorePersist var result IgnorePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -806,11 +809,11 @@ func TestIgnorePersistDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected IgnorePersist to be equal, but it is not %s %s, %v", a, b, result) } @@ -824,13 +827,13 @@ func TestIgnorePersistDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample IgnorePersist var result IgnorePersist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b IgnorePersist @@ -843,11 +846,11 @@ func TestIgnorePersistDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected IgnorePersist to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/backend_compare_test.go b/models/backend_compare_test.go index bff8d2a8..0289f668 100644 --- a/models/backend_compare_test.go +++ b/models/backend_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestBackendEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Backend var result Backend - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestBackendEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Backend to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestBackendEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Backend var result Backend - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Backend @@ -94,11 +97,11 @@ func TestBackendEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Backend to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestBackendDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Backend var result Backend - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestBackendDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Backend to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestBackendDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Backend var result Backend - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Backend @@ -173,11 +176,11 @@ func TestBackendDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Backend to be different in 16 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/backend_switching_rule.go b/models/backend_switching_rule.go index 177f9e6d..4db42f00 100644 --- a/models/backend_switching_rule.go +++ b/models/backend_switching_rule.go @@ -33,12 +33,12 @@ import ( // BackendSwitchingRule Backend Switching Rule // // HAProxy backend switching rule configuration (corresponds to use_backend directive) -// Example: {"cond":"if","cond_test":"{ req_ssl_sni -i www.example.com }","index":0,"name":"test_backend"} +// Example: {"cond":"if","cond_test":"{ req.ssl_sni -i www.example.com }","index":0,"name":"test_backend"} // // swagger:model backend_switching_rule type BackendSwitchingRule struct { // cond - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond string `json:"cond,omitempty"` diff --git a/models/backend_switching_rule_compare_test.go b/models/backend_switching_rule_compare_test.go index 6f3f94b9..f2aaf8d8 100644 --- a/models/backend_switching_rule_compare_test.go +++ b/models/backend_switching_rule_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestBackendSwitchingRuleEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendSwitchingRule var result BackendSwitchingRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestBackendSwitchingRuleEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendSwitchingRule to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestBackendSwitchingRuleEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendSwitchingRule var result BackendSwitchingRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b BackendSwitchingRule @@ -94,11 +97,11 @@ func TestBackendSwitchingRuleEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendSwitchingRule to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestBackendSwitchingRuleDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendSwitchingRule var result BackendSwitchingRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestBackendSwitchingRuleDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendSwitchingRule to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestBackendSwitchingRuleDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample BackendSwitchingRule var result BackendSwitchingRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b BackendSwitchingRule @@ -173,11 +176,11 @@ func TestBackendSwitchingRuleDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BackendSwitchingRule to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/backend_switching_rules.go b/models/backend_switching_rules.go index d9d7e832..f42c59be 100644 --- a/models/backend_switching_rules.go +++ b/models/backend_switching_rules.go @@ -71,6 +71,11 @@ func (m BackendSwitchingRules) ContextValidate(ctx context.Context, formats strf for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/backends.go b/models/backends.go index 2a5677d8..8c530270 100644 --- a/models/backends.go +++ b/models/backends.go @@ -71,6 +71,11 @@ func (m Backends) ContextValidate(ctx context.Context, formats strfmt.Registry) for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/balance.go b/models/balance.go index b60da1e3..4387bb4c 100644 --- a/models/balance.go +++ b/models/balance.go @@ -36,7 +36,7 @@ import ( type Balance struct { // algorithm // Required: true - // Enum: [first hash hdr leastconn random rdp-cookie roundrobin source static-rr uri url_param] + // Enum: ["first","hash","hdr","leastconn","random","rdp-cookie","roundrobin","source","static-rr","uri","url_param"] // +kubebuilder:validation:Enum=first;hash;hdr;leastconn;random;rdp-cookie;roundrobin;source;static-rr;uri;url_param; Algorithm *string `json:"algorithm"` diff --git a/models/balance_compare_test.go b/models/balance_compare_test.go index f779c9ed..a99ca113 100644 --- a/models/balance_compare_test.go +++ b/models/balance_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestBalanceEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Balance var result Balance - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestBalanceEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Balance to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestBalanceEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Balance var result Balance - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.HdrUseDomainOnly = !sample.HdrUseDomainOnly result.RandomDraws = sample.RandomDraws + 1 @@ -102,11 +105,11 @@ func TestBalanceEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Balance to be different, but it is not %s %s", a, b) } @@ -120,17 +123,17 @@ func TestBalanceDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Balance var result Balance - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -144,11 +147,11 @@ func TestBalanceDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Balance to be equal, but it is not %s %s, %v", a, b, result) } @@ -162,13 +165,13 @@ func TestBalanceDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Balance var result Balance - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.HdrUseDomainOnly = !sample.HdrUseDomainOnly result.RandomDraws = sample.RandomDraws + 1 @@ -189,11 +192,11 @@ func TestBalanceDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Balance to be different in 13 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/bind_compare_test.go b/models/bind_compare_test.go index 8533aed9..f7555db3 100644 --- a/models/bind_compare_test.go +++ b/models/bind_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestBindEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Bind var result Bind - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestBindEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Bind to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestBindEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Bind var result Bind - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) result.PortRangeEnd = Ptr(*sample.PortRangeEnd + 1) @@ -96,11 +99,11 @@ func TestBindEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Bind to be different, but it is not %s %s", a, b) } @@ -114,17 +117,17 @@ func TestBindDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Bind var result Bind - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -138,11 +141,11 @@ func TestBindDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Bind to be equal, but it is not %s %s, %v", a, b, result) } @@ -156,13 +159,13 @@ func TestBindDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Bind var result Bind - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) result.PortRangeEnd = Ptr(*sample.PortRangeEnd + 1) @@ -177,11 +180,11 @@ func TestBindDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Bind to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/bind_params.go b/models/bind_params.go index cbe270aa..76699080 100644 --- a/models/bind_params.go +++ b/models/bind_params.go @@ -135,7 +135,7 @@ type BindParams struct { // level // Example: user - // Enum: [user operator admin] + // Enum: ["user","operator","admin"] // +kubebuilder:validation:Enum=user;operator;admin; Level string `json:"level,omitempty"` @@ -199,7 +199,7 @@ type BindParams struct { Proto string `json:"proto,omitempty"` // quic cc algo - // Enum: [cubic newreno] + // Enum: ["cubic","newreno"] // +kubebuilder:validation:Enum=cubic;newreno; QuicCcAlgo string `json:"quic-cc-algo,omitempty"` @@ -207,13 +207,13 @@ type BindParams struct { QuicForceRetry bool `json:"quic-force-retry,omitempty"` // quic socket - // Enum: [connection listener] + // Enum: ["connection","listener"] // +kubebuilder:validation:Enum=connection;listener; QuicSocket string `json:"quic-socket,omitempty"` // severity output // Example: none - // Enum: [none number string] + // Enum: ["none","number","string"] // +kubebuilder:validation:Enum=none;number;string; SeverityOutput string `json:"severity_output,omitempty"` @@ -234,12 +234,12 @@ type BindParams struct { SslCertificate string `json:"ssl_certificate,omitempty"` // ssl max ver - // Enum: [SSLv3 TLSv1.0 TLSv1.1 TLSv1.2 TLSv1.3] + // Enum: ["SSLv3","TLSv1.0","TLSv1.1","TLSv1.2","TLSv1.3"] // +kubebuilder:validation:Enum=SSLv3;TLSv1.0;TLSv1.1;TLSv1.2;TLSv1.3; SslMaxVer string `json:"ssl_max_ver,omitempty"` // ssl min ver - // Enum: [SSLv3 TLSv1.0 TLSv1.1 TLSv1.2 TLSv1.3] + // Enum: ["SSLv3","TLSv1.0","TLSv1.1","TLSv1.2","TLSv1.3"] // +kubebuilder:validation:Enum=SSLv3;TLSv1.0;TLSv1.1;TLSv1.2;TLSv1.3; SslMinVer string `json:"ssl_min_ver,omitempty"` @@ -275,7 +275,7 @@ type BindParams struct { // verify // Example: none - // Enum: [none optional required] + // Enum: ["none","optional","required"] // +kubebuilder:validation:Enum=none;optional;required; Verify string `json:"verify,omitempty"` } diff --git a/models/bind_params_compare_test.go b/models/bind_params_compare_test.go index cb2084b8..494c49ee 100644 --- a/models/bind_params_compare_test.go +++ b/models/bind_params_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestBindParamsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample BindParams var result BindParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestBindParamsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BindParams to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestBindParamsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample BindParams var result BindParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.AcceptNetscalerCip = sample.AcceptNetscalerCip + 1 result.AcceptProxy = !sample.AcceptProxy @@ -126,11 +129,11 @@ func TestBindParamsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BindParams to be different, but it is not %s %s", a, b) } @@ -144,17 +147,17 @@ func TestBindParamsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample BindParams var result BindParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -168,11 +171,11 @@ func TestBindParamsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BindParams to be equal, but it is not %s %s, %v", a, b, result) } @@ -186,13 +189,13 @@ func TestBindParamsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample BindParams var result BindParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.AcceptNetscalerCip = sample.AcceptNetscalerCip + 1 result.AcceptProxy = !sample.AcceptProxy @@ -237,11 +240,11 @@ func TestBindParamsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected BindParams to be different in 71 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/binds.go b/models/binds.go index f063d8a5..ebf923aa 100644 --- a/models/binds.go +++ b/models/binds.go @@ -71,6 +71,11 @@ func (m Binds) ContextValidate(ctx context.Context, formats strfmt.Registry) err for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/cache_compare_test.go b/models/cache_compare_test.go index 42080847..cbfd2b7c 100644 --- a/models/cache_compare_test.go +++ b/models/cache_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestCacheEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Cache var result Cache - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestCacheEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Cache to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestCacheEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Cache var result Cache - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.MaxAge = sample.MaxAge + 1 result.MaxObjectSize = sample.MaxObjectSize + 1 @@ -99,11 +102,11 @@ func TestCacheEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Cache to be different, but it is not %s %s", a, b) } @@ -117,17 +120,17 @@ func TestCacheDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Cache var result Cache - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -141,11 +144,11 @@ func TestCacheDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Cache to be equal, but it is not %s %s, %v", a, b, result) } @@ -159,13 +162,13 @@ func TestCacheDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Cache var result Cache - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.MaxAge = sample.MaxAge + 1 result.MaxObjectSize = sample.MaxObjectSize + 1 @@ -183,11 +186,11 @@ func TestCacheDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Cache to be different in 6 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/caches.go b/models/caches.go index b8f4051d..aaa8aec6 100644 --- a/models/caches.go +++ b/models/caches.go @@ -71,6 +71,11 @@ func (m Caches) ContextValidate(ctx context.Context, formats strfmt.Registry) er for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/capture.go b/models/capture.go index e156ba61..d12a8d8d 100644 --- a/models/capture.go +++ b/models/capture.go @@ -41,7 +41,7 @@ type Capture struct { // type // Required: true - // Enum: [request response] + // Enum: ["request","response"] // +kubebuilder:validation:Enum=request;response; Type string `json:"type"` } diff --git a/models/capture_compare_test.go b/models/capture_compare_test.go index 83e2d498..dc800021 100644 --- a/models/capture_compare_test.go +++ b/models/capture_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestCaptureEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Capture var result Capture - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestCaptureEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Capture to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestCaptureEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Capture var result Capture - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Length = sample.Length + 1 samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestCaptureEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Capture to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestCaptureDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Capture var result Capture - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestCaptureDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Capture to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestCaptureDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Capture var result Capture - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Length = sample.Length + 1 samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestCaptureDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Capture to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/captures.go b/models/captures.go index 78c70589..0fe12741 100644 --- a/models/captures.go +++ b/models/captures.go @@ -69,6 +69,11 @@ func (m Captures) ContextValidate(ctx context.Context, formats strfmt.Registry) for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/cluster_settings.go b/models/cluster_settings.go index 42e8eee3..c5e7b896 100644 --- a/models/cluster_settings.go +++ b/models/cluster_settings.go @@ -45,13 +45,13 @@ type ClusterSettings struct { Cluster *ClusterSettingsCluster `json:"cluster,omitempty"` // mode - // Enum: [single cluster] + // Enum: ["single","cluster"] // +kubebuilder:validation:Enum=single;cluster; Mode string `json:"mode,omitempty"` // status // Read Only: true - // Enum: [active unreachable waiting_approval] + // Enum: ["active","unreachable","waiting_approval"] // +kubebuilder:validation:Enum=active;unreachable;waiting_approval; Status string `json:"status,omitempty"` } @@ -205,6 +205,11 @@ func (m *ClusterSettings) ContextValidate(ctx context.Context, formats strfmt.Re func (m *ClusterSettings) contextValidateCluster(ctx context.Context, formats strfmt.Registry) error { if m.Cluster != nil { + + if swag.IsZero(m.Cluster) { // not required + return nil + } + if err := m.Cluster.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("cluster") @@ -398,6 +403,11 @@ func (m *ClusterSettingsCluster) contextValidateClusterLogTargets(ctx context.Co for i := 0; i < len(m.ClusterLogTargets); i++ { if m.ClusterLogTargets[i] != nil { + + if swag.IsZero(m.ClusterLogTargets[i]) { // not required + return nil + } + if err := m.ClusterLogTargets[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("cluster" + "." + "log_targets" + "." + strconv.Itoa(i)) @@ -498,7 +508,7 @@ type ClusterLogTarget struct { // protocol // Required: true - // Enum: [tcp udp] + // Enum: ["tcp","udp"] // +kubebuilder:validation:Enum=tcp;udp; Protocol *string `json:"protocol"` } diff --git a/models/cluster_settings_compare_test.go b/models/cluster_settings_compare_test.go index e2f56318..f09bf5fc 100644 --- a/models/cluster_settings_compare_test.go +++ b/models/cluster_settings_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestClusterSettingsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ClusterSettings var result ClusterSettings - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestClusterSettingsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ClusterSettings to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestClusterSettingsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ClusterSettings var result ClusterSettings - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ClusterSettings @@ -94,11 +97,11 @@ func TestClusterSettingsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ClusterSettings to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestClusterSettingsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ClusterSettings var result ClusterSettings - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestClusterSettingsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ClusterSettings to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestClusterSettingsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ClusterSettings var result ClusterSettings - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ClusterSettings @@ -173,11 +176,11 @@ func TestClusterSettingsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ClusterSettings to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -191,17 +194,17 @@ func TestClusterSettingsClusterEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ClusterSettingsCluster var result ClusterSettingsCluster - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -215,11 +218,11 @@ func TestClusterSettingsClusterEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ClusterSettingsCluster to be equal, but it is not %s %s", a, b) } @@ -233,13 +236,13 @@ func TestClusterSettingsClusterEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ClusterSettingsCluster var result ClusterSettingsCluster - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) samples = append(samples, struct { @@ -253,11 +256,11 @@ func TestClusterSettingsClusterEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ClusterSettingsCluster to be different, but it is not %s %s", a, b) } @@ -271,17 +274,17 @@ func TestClusterSettingsClusterDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ClusterSettingsCluster var result ClusterSettingsCluster - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -295,11 +298,11 @@ func TestClusterSettingsClusterDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ClusterSettingsCluster to be equal, but it is not %s %s, %v", a, b, result) } @@ -313,13 +316,13 @@ func TestClusterSettingsClusterDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ClusterSettingsCluster var result ClusterSettingsCluster - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) samples = append(samples, struct { @@ -333,11 +336,11 @@ func TestClusterSettingsClusterDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ClusterSettingsCluster to be different in 7 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -351,17 +354,17 @@ func TestClusterLogTargetEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ClusterLogTarget var result ClusterLogTarget - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -375,11 +378,11 @@ func TestClusterLogTargetEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ClusterLogTarget to be equal, but it is not %s %s", a, b) } @@ -393,13 +396,13 @@ func TestClusterLogTargetEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ClusterLogTarget var result ClusterLogTarget - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) samples = append(samples, struct { @@ -413,11 +416,11 @@ func TestClusterLogTargetEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ClusterLogTarget to be different, but it is not %s %s", a, b) } @@ -431,17 +434,17 @@ func TestClusterLogTargetDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ClusterLogTarget var result ClusterLogTarget - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -455,11 +458,11 @@ func TestClusterLogTargetDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ClusterLogTarget to be equal, but it is not %s %s, %v", a, b, result) } @@ -473,13 +476,13 @@ func TestClusterLogTargetDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ClusterLogTarget var result ClusterLogTarget - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) samples = append(samples, struct { @@ -493,11 +496,11 @@ func TestClusterLogTargetDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ClusterLogTarget to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/compression.go b/models/compression.go index 46e6c7aa..5655300e 100644 --- a/models/compression.go +++ b/models/compression.go @@ -36,7 +36,7 @@ import ( // swagger:model compression type Compression struct { // algo req - // Enum: [identity gzip deflate raw-deflate] + // Enum: ["identity","gzip","deflate","raw-deflate"] // +kubebuilder:validation:Enum=identity;gzip;deflate;raw-deflate; AlgoReq string `json:"algo-req,omitempty"` @@ -47,7 +47,7 @@ type Compression struct { AlgosRes []string `json:"algos-res,omitempty"` // direction - // Enum: [request response both] + // Enum: ["request","response","both"] // +kubebuilder:validation:Enum=request;response;both; Direction string `json:"direction,omitempty"` diff --git a/models/compression_compare_test.go b/models/compression_compare_test.go index d80f5711..09c21317 100644 --- a/models/compression_compare_test.go +++ b/models/compression_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestCompressionEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Compression var result Compression - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestCompressionEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Compression to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestCompressionEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Compression var result Compression - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Offload = !sample.Offload samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestCompressionEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Compression to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestCompressionDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Compression var result Compression - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestCompressionDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Compression to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestCompressionDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Compression var result Compression - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Offload = !sample.Offload samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestCompressionDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Compression to be different in 8 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/config_stick_table.go b/models/config_stick_table.go index 5d4e55f4..82b8f9da 100644 --- a/models/config_stick_table.go +++ b/models/config_stick_table.go @@ -56,7 +56,7 @@ type ConfigStickTable struct { Size *int64 `json:"size,omitempty"` // srvkey - // Enum: [addr name] + // Enum: ["addr","name"] // +kubebuilder:validation:Enum=addr;name; Srvkey *string `json:"srvkey,omitempty"` @@ -66,7 +66,7 @@ type ConfigStickTable struct { Store string `json:"store,omitempty"` // type - // Enum: [ip ipv6 integer string binary] + // Enum: ["ip","ipv6","integer","string","binary"] // +kubebuilder:validation:Enum=ip;ipv6;integer;string;binary; Type string `json:"type,omitempty"` diff --git a/models/config_stick_table_compare_test.go b/models/config_stick_table_compare_test.go index f8730728..02182cf2 100644 --- a/models/config_stick_table_compare_test.go +++ b/models/config_stick_table_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestConfigStickTableEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ConfigStickTable var result ConfigStickTable - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestConfigStickTableEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ConfigStickTable to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestConfigStickTableEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ConfigStickTable var result ConfigStickTable - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Expire = Ptr(*sample.Expire + 1) result.Keylen = Ptr(*sample.Keylen + 1) @@ -98,11 +101,11 @@ func TestConfigStickTableEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ConfigStickTable to be different, but it is not %s %s", a, b) } @@ -116,17 +119,17 @@ func TestConfigStickTableDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ConfigStickTable var result ConfigStickTable - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -140,11 +143,11 @@ func TestConfigStickTableDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ConfigStickTable to be equal, but it is not %s %s, %v", a, b, result) } @@ -158,13 +161,13 @@ func TestConfigStickTableDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ConfigStickTable var result ConfigStickTable - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Expire = Ptr(*sample.Expire + 1) result.Keylen = Ptr(*sample.Keylen + 1) @@ -181,11 +184,11 @@ func TestConfigStickTableDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ConfigStickTable to be different in 9 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/consul.go b/models/consul.go index 45f376d0..7a79e2c6 100644 --- a/models/consul.go +++ b/models/consul.go @@ -60,7 +60,7 @@ type Consul struct { // all: a node is considered valid if all health checks are 'passing' // min: a node is considered valid if the number of 'passing' checks is greater or equal to the 'health_check_policy_min' value. // If the node has less health checks configured then 'health_check_policy_min' it is considered invalid. - // Enum: [none any all min] + // Enum: ["none","any","all","min"] // +kubebuilder:validation:Enum=none;any;all;min; HealthCheckPolicy *string `json:"health_check_policy,omitempty"` @@ -73,7 +73,7 @@ type Consul struct { ID *string `json:"id,omitempty"` // mode - // Enum: [http https] + // Enum: ["http","https"] // +kubebuilder:validation:Enum=http;https; Mode *string `json:"mode,omitempty"` @@ -104,7 +104,7 @@ type Consul struct { ServerSlotsGrowthIncrement int64 `json:"server_slots_growth_increment,omitempty"` // server slots growth type - // Enum: [linear exponential] + // Enum: ["linear","exponential"] // +kubebuilder:validation:Enum=linear;exponential; ServerSlotsGrowthType *string `json:"server_slots_growth_type,omitempty"` diff --git a/models/consul_compare_test.go b/models/consul_compare_test.go index a665d215..54ab1672 100644 --- a/models/consul_compare_test.go +++ b/models/consul_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestConsulEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Consul var result Consul - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestConsulEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Consul to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestConsulEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Consul var result Consul - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Enabled = Ptr(!*sample.Enabled) result.HealthCheckPolicyMin = sample.HealthCheckPolicyMin + 1 @@ -100,11 +103,11 @@ func TestConsulEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Consul to be different, but it is not %s %s", a, b) } @@ -118,17 +121,17 @@ func TestConsulDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Consul var result Consul - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -142,11 +145,11 @@ func TestConsulDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Consul to be equal, but it is not %s %s, %v", a, b, result) } @@ -160,13 +163,13 @@ func TestConsulDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Consul var result Consul - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Enabled = Ptr(!*sample.Enabled) result.HealthCheckPolicyMin = sample.HealthCheckPolicyMin + 1 @@ -185,11 +188,11 @@ func TestConsulDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Consul to be different in 19 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/consuls.go b/models/consuls.go index 9426ef85..ebe3b71d 100644 --- a/models/consuls.go +++ b/models/consuls.go @@ -71,6 +71,11 @@ func (m Consuls) ContextValidate(ctx context.Context, formats strfmt.Registry) e for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/cookie.go b/models/cookie.go index 2ca1c2c8..4f7407a3 100644 --- a/models/cookie.go +++ b/models/cookie.go @@ -76,7 +76,7 @@ type Cookie struct { Secure bool `json:"secure,omitempty"` // type - // Enum: [rewrite insert prefix] + // Enum: ["rewrite","insert","prefix"] // +kubebuilder:validation:Enum=rewrite;insert;prefix; Type string `json:"type,omitempty"` } @@ -240,6 +240,11 @@ func (m *Cookie) contextValidateAttrs(ctx context.Context, formats strfmt.Regist for i := 0; i < len(m.Attrs); i++ { if m.Attrs[i] != nil { + + if swag.IsZero(m.Attrs[i]) { // not required + return nil + } + if err := m.Attrs[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("attr" + "." + strconv.Itoa(i)) @@ -260,6 +265,11 @@ func (m *Cookie) contextValidateDomains(ctx context.Context, formats strfmt.Regi for i := 0; i < len(m.Domains); i++ { if m.Domains[i] != nil { + + if swag.IsZero(m.Domains[i]) { // not required + return nil + } + if err := m.Domains[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("domain" + "." + strconv.Itoa(i)) diff --git a/models/cookie_compare_test.go b/models/cookie_compare_test.go index ee021d49..d50b3dbf 100644 --- a/models/cookie_compare_test.go +++ b/models/cookie_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestCookieEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Cookie var result Cookie - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestCookieEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Cookie to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestCookieEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Cookie var result Cookie - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Dynamic = !sample.Dynamic result.Httponly = !sample.Httponly @@ -103,11 +106,11 @@ func TestCookieEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Cookie to be different, but it is not %s %s", a, b) } @@ -121,17 +124,17 @@ func TestCookieDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Cookie var result Cookie - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -145,11 +148,11 @@ func TestCookieDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Cookie to be equal, but it is not %s %s, %v", a, b, result) } @@ -163,13 +166,13 @@ func TestCookieDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Cookie var result Cookie - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Dynamic = !sample.Dynamic result.Httponly = !sample.Httponly @@ -191,11 +194,11 @@ func TestCookieDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Cookie to be different in 13 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -209,17 +212,17 @@ func TestAttrEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Attr var result Attr - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -233,11 +236,11 @@ func TestAttrEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Attr to be equal, but it is not %s %s", a, b) } @@ -251,13 +254,13 @@ func TestAttrEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Attr var result Attr - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Attr @@ -270,11 +273,11 @@ func TestAttrEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Attr to be different, but it is not %s %s", a, b) } @@ -288,17 +291,17 @@ func TestAttrDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Attr var result Attr - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -312,11 +315,11 @@ func TestAttrDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Attr to be equal, but it is not %s %s, %v", a, b, result) } @@ -330,13 +333,13 @@ func TestAttrDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Attr var result Attr - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Attr @@ -349,11 +352,11 @@ func TestAttrDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Attr to be different in 1 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -367,17 +370,17 @@ func TestDomainEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Domain var result Domain - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -391,11 +394,11 @@ func TestDomainEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Domain to be equal, but it is not %s %s", a, b) } @@ -409,13 +412,13 @@ func TestDomainEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Domain var result Domain - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Domain @@ -428,11 +431,11 @@ func TestDomainEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Domain to be different, but it is not %s %s", a, b) } @@ -446,17 +449,17 @@ func TestDomainDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Domain var result Domain - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -470,11 +473,11 @@ func TestDomainDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Domain to be equal, but it is not %s %s, %v", a, b, result) } @@ -488,13 +491,13 @@ func TestDomainDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Domain var result Domain - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Domain @@ -507,11 +510,11 @@ func TestDomainDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Domain to be different in 1 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/crt_load.go b/models/crt_load.go index 2768564b..ae70f482 100644 --- a/models/crt_load.go +++ b/models/crt_load.go @@ -54,7 +54,7 @@ type CrtLoad struct { Ocsp string `json:"ocsp,omitempty"` // Automatic OCSP response update - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; OcspUpdate string `json:"ocsp_update,omitempty"` diff --git a/models/crt_load_compare_test.go b/models/crt_load_compare_test.go index bb078af6..c34fd9a7 100644 --- a/models/crt_load_compare_test.go +++ b/models/crt_load_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestCrtLoadEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample CrtLoad var result CrtLoad - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestCrtLoadEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected CrtLoad to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestCrtLoadEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample CrtLoad var result CrtLoad - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b CrtLoad @@ -94,11 +97,11 @@ func TestCrtLoadEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected CrtLoad to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestCrtLoadDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample CrtLoad var result CrtLoad - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestCrtLoadDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected CrtLoad to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestCrtLoadDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample CrtLoad var result CrtLoad - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b CrtLoad @@ -173,11 +176,11 @@ func TestCrtLoadDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected CrtLoad to be different in 7 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/crt_loads.go b/models/crt_loads.go index 705f00d8..fb758b7e 100644 --- a/models/crt_loads.go +++ b/models/crt_loads.go @@ -69,6 +69,11 @@ func (m CrtLoads) ContextValidate(ctx context.Context, formats strfmt.Registry) for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/crt_store_compare_test.go b/models/crt_store_compare_test.go index 8bc90286..84db6cb6 100644 --- a/models/crt_store_compare_test.go +++ b/models/crt_store_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestCrtStoreEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample CrtStore var result CrtStore - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestCrtStoreEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected CrtStore to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestCrtStoreEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample CrtStore var result CrtStore - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b CrtStore @@ -94,11 +97,11 @@ func TestCrtStoreEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected CrtStore to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestCrtStoreDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample CrtStore var result CrtStore - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestCrtStoreDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected CrtStore to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestCrtStoreDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample CrtStore var result CrtStore - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b CrtStore @@ -173,11 +176,11 @@ func TestCrtStoreDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected CrtStore to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/crt_stores.go b/models/crt_stores.go index cc6c3e0d..793f12de 100644 --- a/models/crt_stores.go +++ b/models/crt_stores.go @@ -69,6 +69,11 @@ func (m CrtStores) ContextValidate(ctx context.Context, formats strfmt.Registry) for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/debug_options_compare_test.go b/models/debug_options_compare_test.go index 0bcf34f8..0dc42f51 100644 --- a/models/debug_options_compare_test.go +++ b/models/debug_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestDebugOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample DebugOptions var result DebugOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestDebugOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DebugOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestDebugOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample DebugOptions var result DebugOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Anonkey = Ptr(*sample.Anonkey + 1) result.Quiet = !sample.Quiet @@ -97,11 +100,11 @@ func TestDebugOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DebugOptions to be different, but it is not %s %s", a, b) } @@ -115,17 +118,17 @@ func TestDebugOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample DebugOptions var result DebugOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -139,11 +142,11 @@ func TestDebugOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DebugOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -157,13 +160,13 @@ func TestDebugOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample DebugOptions var result DebugOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Anonkey = Ptr(*sample.Anonkey + 1) result.Quiet = !sample.Quiet @@ -179,11 +182,11 @@ func TestDebugOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DebugOptions to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/default_bind_compare_test.go b/models/default_bind_compare_test.go index 59101434..f5dc4a1a 100644 --- a/models/default_bind_compare_test.go +++ b/models/default_bind_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestDefaultBindEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample DefaultBind var result DefaultBind - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestDefaultBindEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DefaultBind to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestDefaultBindEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample DefaultBind var result DefaultBind - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b DefaultBind @@ -94,11 +97,11 @@ func TestDefaultBindEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DefaultBind to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestDefaultBindDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample DefaultBind var result DefaultBind - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestDefaultBindDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DefaultBind to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestDefaultBindDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample DefaultBind var result DefaultBind - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b DefaultBind @@ -173,11 +176,11 @@ func TestDefaultBindDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DefaultBind to be different in 1 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/default_server_compare_test.go b/models/default_server_compare_test.go index c97a8fac..b98e97d5 100644 --- a/models/default_server_compare_test.go +++ b/models/default_server_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestDefaultServerEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample DefaultServer var result DefaultServer - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestDefaultServerEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DefaultServer to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestDefaultServerEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample DefaultServer var result DefaultServer - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b DefaultServer @@ -94,11 +97,11 @@ func TestDefaultServerEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DefaultServer to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestDefaultServerDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample DefaultServer var result DefaultServer - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestDefaultServerDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DefaultServer to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestDefaultServerDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample DefaultServer var result DefaultServer - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b DefaultServer @@ -173,11 +176,11 @@ func TestDefaultServerDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DefaultServer to be different in 1 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/defaults_base.go b/models/defaults_base.go index e835be96..ce0cb074 100644 --- a/models/defaults_base.go +++ b/models/defaults_base.go @@ -45,27 +45,27 @@ type DefaultsBase struct { ErrorFilesFromHTTPErrors []*Errorfiles `json:"errorfiles_from_http_errors,omitempty"` // abortonclose - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Abortonclose string `json:"abortonclose,omitempty"` // accept invalid http request - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; AcceptInvalidHTTPRequest string `json:"accept_invalid_http_request,omitempty"` // accept invalid http response - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; AcceptInvalidHTTPResponse string `json:"accept_invalid_http_response,omitempty"` // adv check - // Enum: [httpchk ldap-check mysql-check pgsql-check redis-check smtpchk ssl-hello-chk tcp-check] + // Enum: ["httpchk","ldap-check","mysql-check","pgsql-check","redis-check","smtpchk","ssl-hello-chk","tcp-check"] // +kubebuilder:validation:Enum=httpchk;ldap-check;mysql-check;pgsql-check;redis-check;smtpchk;ssl-hello-chk;tcp-check; AdvCheck string `json:"adv_check,omitempty"` // allbackups - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Allbackups string `json:"allbackups,omitempty"` @@ -79,7 +79,7 @@ type DefaultsBase struct { CheckTimeout *int64 `json:"check_timeout,omitempty"` // checkcache - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Checkcache string `json:"checkcache,omitempty"` @@ -97,7 +97,7 @@ type DefaultsBase struct { ClientTimeout *int64 `json:"client_timeout,omitempty"` // clitcpka - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Clitcpka string `json:"clitcpka,omitempty"` @@ -119,7 +119,7 @@ type DefaultsBase struct { ConnectTimeout *int64 `json:"connect_timeout,omitempty"` // contstats - // Enum: [enabled] + // Enum: ["enabled"] // +kubebuilder:validation:Enum=enabled; Contstats string `json:"contstats,omitempty"` @@ -135,7 +135,7 @@ type DefaultsBase struct { DefaultServer *DefaultServer `json:"default_server,omitempty"` // disable h2 upgrade - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; DisableH2Upgrade string `json:"disable_h2_upgrade,omitempty"` @@ -143,12 +143,12 @@ type DefaultsBase struct { Disabled bool `json:"disabled,omitempty"` // dontlog normal - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; DontlogNormal string `json:"dontlog_normal,omitempty"` // dontlognull - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Dontlognull string `json:"dontlognull,omitempty"` @@ -173,7 +173,7 @@ type DefaultsBase struct { Errorloc303 *Errorloc `json:"errorloc303,omitempty"` // external check - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ExternalCheck string `json:"external_check,omitempty"` @@ -199,12 +199,12 @@ type DefaultsBase struct { Fullconn *int64 `json:"fullconn,omitempty"` // h1 case adjust bogus client - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; H1CaseAdjustBogusClient string `json:"h1_case_adjust_bogus_client,omitempty"` // h1 case adjust bogus server - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; H1CaseAdjustBogusServer string `json:"h1_case_adjust_bogus_server,omitempty"` @@ -215,22 +215,22 @@ type DefaultsBase struct { HashType *HashType `json:"hash_type,omitempty"` // http buffer request - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; HTTPBufferRequest string `json:"http-buffer-request,omitempty"` // http use htx - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; HTTPUseHtx string `json:"http-use-htx,omitempty"` // http connection mode - // Enum: [httpclose http-server-close http-keep-alive] + // Enum: ["httpclose","http-server-close","http-keep-alive"] // +kubebuilder:validation:Enum=httpclose;http-server-close;http-keep-alive; HTTPConnectionMode string `json:"http_connection_mode,omitempty"` // http ignore probes - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; HTTPIgnoreProbes string `json:"http_ignore_probes,omitempty"` @@ -240,12 +240,12 @@ type DefaultsBase struct { HTTPKeepAliveTimeout *int64 `json:"http_keep_alive_timeout,omitempty"` // http no delay - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; HTTPNoDelay string `json:"http_no_delay,omitempty"` // http pretend keepalive - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; HTTPPretendKeepalive string `json:"http_pretend_keepalive,omitempty"` @@ -255,12 +255,12 @@ type DefaultsBase struct { HTTPRequestTimeout *int64 `json:"http_request_timeout,omitempty"` // http restrict req hdr names - // Enum: [preserve delete reject] + // Enum: ["preserve","delete","reject"] // +kubebuilder:validation:Enum=preserve;delete;reject; HTTPRestrictReqHdrNames string `json:"http_restrict_req_hdr_names,omitempty"` // http reuse - // Enum: [aggressive always never safe] + // Enum: ["aggressive","always","never","safe"] // +kubebuilder:validation:Enum=aggressive;always;never;safe; HTTPReuse string `json:"http_reuse,omitempty"` @@ -268,7 +268,7 @@ type DefaultsBase struct { HTTPSendNameHeader *string `json:"http_send_name_header,omitempty"` // http use proxy header - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; HTTPUseProxyHeader string `json:"http_use_proxy_header,omitempty"` @@ -279,22 +279,22 @@ type DefaultsBase struct { Httplog bool `json:"httplog,omitempty"` // httpslog - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Httpslog string `json:"httpslog,omitempty"` // idle close on response - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; IdleCloseOnResponse string `json:"idle_close_on_response,omitempty"` // independent streams - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; IndependentStreams string `json:"independent_streams,omitempty"` // load server state from file - // Enum: [global local none] + // Enum: ["global","local","none"] // +kubebuilder:validation:Enum=global;local;none; LoadServerStateFromFile string `json:"load_server_state_from_file,omitempty"` @@ -305,12 +305,12 @@ type DefaultsBase struct { LogFormatSd string `json:"log_format_sd,omitempty"` // log health checks - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; LogHealthChecks string `json:"log_health_checks,omitempty"` // log separate errors - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; LogSeparateErrors string `json:"log_separate_errors,omitempty"` @@ -320,7 +320,7 @@ type DefaultsBase struct { LogTag string `json:"log_tag,omitempty"` // logasap - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Logasap string `json:"logasap,omitempty"` @@ -331,7 +331,7 @@ type DefaultsBase struct { Maxconn *int64 `json:"maxconn,omitempty"` // mode - // Enum: [tcp http log] + // Enum: ["tcp","http","log"] // +kubebuilder:validation:Enum=tcp;http;log; Mode string `json:"mode,omitempty"` @@ -347,7 +347,7 @@ type DefaultsBase struct { Name string `json:"name,omitempty"` // nolinger - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Nolinger string `json:"nolinger,omitempty"` @@ -355,7 +355,7 @@ type DefaultsBase struct { Originalto *Originalto `json:"originalto,omitempty"` // persist - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Persist string `json:"persist,omitempty"` @@ -366,7 +366,7 @@ type DefaultsBase struct { PgsqlCheckParams *PgsqlCheckParams `json:"pgsql_check_params,omitempty"` // prefer last server - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; PreferLastServer string `json:"prefer_last_server,omitempty"` @@ -398,7 +398,7 @@ type DefaultsBase struct { SmtpchkParams *SmtpchkParams `json:"smtpchk_params,omitempty"` // socket stats - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SocketStats string `json:"socket_stats,omitempty"` @@ -406,22 +406,22 @@ type DefaultsBase struct { Source *Source `json:"source,omitempty"` // splice auto - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SpliceAuto string `json:"splice_auto,omitempty"` // splice request - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SpliceRequest string `json:"splice_request,omitempty"` // splice response - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SpliceResponse string `json:"splice_response,omitempty"` // srvtcpka - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Srvtcpka string `json:"srvtcpka,omitempty"` @@ -443,17 +443,17 @@ type DefaultsBase struct { TarpitTimeout *int64 `json:"tarpit_timeout,omitempty"` // tcp smart accept - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; TCPSmartAccept string `json:"tcp_smart_accept,omitempty"` // tcp smart connect - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; TCPSmartConnect string `json:"tcp_smart_connect,omitempty"` // tcpka - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Tcpka string `json:"tcpka,omitempty"` @@ -461,7 +461,7 @@ type DefaultsBase struct { Tcplog bool `json:"tcplog,omitempty"` // transparent - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Transparent string `json:"transparent,omitempty"` @@ -3364,6 +3364,11 @@ func (m *DefaultsBase) contextValidateErrorFiles(ctx context.Context, formats st for i := 0; i < len(m.ErrorFiles); i++ { if m.ErrorFiles[i] != nil { + + if swag.IsZero(m.ErrorFiles[i]) { // not required + return nil + } + if err := m.ErrorFiles[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("error_files" + "." + strconv.Itoa(i)) @@ -3384,6 +3389,11 @@ func (m *DefaultsBase) contextValidateErrorFilesFromHTTPErrors(ctx context.Conte for i := 0; i < len(m.ErrorFilesFromHTTPErrors); i++ { if m.ErrorFilesFromHTTPErrors[i] != nil { + + if swag.IsZero(m.ErrorFilesFromHTTPErrors[i]) { // not required + return nil + } + if err := m.ErrorFilesFromHTTPErrors[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("errorfiles_from_http_errors" + "." + strconv.Itoa(i)) @@ -3402,6 +3412,11 @@ func (m *DefaultsBase) contextValidateErrorFilesFromHTTPErrors(ctx context.Conte func (m *DefaultsBase) contextValidateBalance(ctx context.Context, formats strfmt.Registry) error { if m.Balance != nil { + + if swag.IsZero(m.Balance) { // not required + return nil + } + if err := m.Balance.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("balance") @@ -3418,6 +3433,11 @@ func (m *DefaultsBase) contextValidateBalance(ctx context.Context, formats strfm func (m *DefaultsBase) contextValidateCompression(ctx context.Context, formats strfmt.Registry) error { if m.Compression != nil { + + if swag.IsZero(m.Compression) { // not required + return nil + } + if err := m.Compression.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("compression") @@ -3434,6 +3454,11 @@ func (m *DefaultsBase) contextValidateCompression(ctx context.Context, formats s func (m *DefaultsBase) contextValidateCookie(ctx context.Context, formats strfmt.Registry) error { if m.Cookie != nil { + + if swag.IsZero(m.Cookie) { // not required + return nil + } + if err := m.Cookie.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("cookie") @@ -3450,6 +3475,11 @@ func (m *DefaultsBase) contextValidateCookie(ctx context.Context, formats strfmt func (m *DefaultsBase) contextValidateDefaultServer(ctx context.Context, formats strfmt.Registry) error { if m.DefaultServer != nil { + + if swag.IsZero(m.DefaultServer) { // not required + return nil + } + if err := m.DefaultServer.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("default_server") @@ -3466,6 +3496,11 @@ func (m *DefaultsBase) contextValidateDefaultServer(ctx context.Context, formats func (m *DefaultsBase) contextValidateEmailAlert(ctx context.Context, formats strfmt.Registry) error { if m.EmailAlert != nil { + + if swag.IsZero(m.EmailAlert) { // not required + return nil + } + if err := m.EmailAlert.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("email_alert") @@ -3482,6 +3517,11 @@ func (m *DefaultsBase) contextValidateEmailAlert(ctx context.Context, formats st func (m *DefaultsBase) contextValidateErrorloc302(ctx context.Context, formats strfmt.Registry) error { if m.Errorloc302 != nil { + + if swag.IsZero(m.Errorloc302) { // not required + return nil + } + if err := m.Errorloc302.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("errorloc302") @@ -3498,6 +3538,11 @@ func (m *DefaultsBase) contextValidateErrorloc302(ctx context.Context, formats s func (m *DefaultsBase) contextValidateErrorloc303(ctx context.Context, formats strfmt.Registry) error { if m.Errorloc303 != nil { + + if swag.IsZero(m.Errorloc303) { // not required + return nil + } + if err := m.Errorloc303.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("errorloc303") @@ -3514,6 +3559,11 @@ func (m *DefaultsBase) contextValidateErrorloc303(ctx context.Context, formats s func (m *DefaultsBase) contextValidateForwardfor(ctx context.Context, formats strfmt.Registry) error { if m.Forwardfor != nil { + + if swag.IsZero(m.Forwardfor) { // not required + return nil + } + if err := m.Forwardfor.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("forwardfor") @@ -3530,6 +3580,11 @@ func (m *DefaultsBase) contextValidateForwardfor(ctx context.Context, formats st func (m *DefaultsBase) contextValidateHashType(ctx context.Context, formats strfmt.Registry) error { if m.HashType != nil { + + if swag.IsZero(m.HashType) { // not required + return nil + } + if err := m.HashType.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("hash_type") @@ -3546,6 +3601,11 @@ func (m *DefaultsBase) contextValidateHashType(ctx context.Context, formats strf func (m *DefaultsBase) contextValidateHttpchkParams(ctx context.Context, formats strfmt.Registry) error { if m.HttpchkParams != nil { + + if swag.IsZero(m.HttpchkParams) { // not required + return nil + } + if err := m.HttpchkParams.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("httpchk_params") @@ -3561,6 +3621,10 @@ func (m *DefaultsBase) contextValidateHttpchkParams(ctx context.Context, formats func (m *DefaultsBase) contextValidateMonitorURI(ctx context.Context, formats strfmt.Registry) error { + if swag.IsZero(m.MonitorURI) { // not required + return nil + } + if err := m.MonitorURI.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("monitor_uri") @@ -3576,6 +3640,11 @@ func (m *DefaultsBase) contextValidateMonitorURI(ctx context.Context, formats st func (m *DefaultsBase) contextValidateMysqlCheckParams(ctx context.Context, formats strfmt.Registry) error { if m.MysqlCheckParams != nil { + + if swag.IsZero(m.MysqlCheckParams) { // not required + return nil + } + if err := m.MysqlCheckParams.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("mysql_check_params") @@ -3592,6 +3661,11 @@ func (m *DefaultsBase) contextValidateMysqlCheckParams(ctx context.Context, form func (m *DefaultsBase) contextValidateOriginalto(ctx context.Context, formats strfmt.Registry) error { if m.Originalto != nil { + + if swag.IsZero(m.Originalto) { // not required + return nil + } + if err := m.Originalto.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("originalto") @@ -3608,6 +3682,11 @@ func (m *DefaultsBase) contextValidateOriginalto(ctx context.Context, formats st func (m *DefaultsBase) contextValidatePersistRule(ctx context.Context, formats strfmt.Registry) error { if m.PersistRule != nil { + + if swag.IsZero(m.PersistRule) { // not required + return nil + } + if err := m.PersistRule.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("persist_rule") @@ -3624,6 +3703,11 @@ func (m *DefaultsBase) contextValidatePersistRule(ctx context.Context, formats s func (m *DefaultsBase) contextValidatePgsqlCheckParams(ctx context.Context, formats strfmt.Registry) error { if m.PgsqlCheckParams != nil { + + if swag.IsZero(m.PgsqlCheckParams) { // not required + return nil + } + if err := m.PgsqlCheckParams.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("pgsql_check_params") @@ -3640,6 +3724,11 @@ func (m *DefaultsBase) contextValidatePgsqlCheckParams(ctx context.Context, form func (m *DefaultsBase) contextValidateRedispatch(ctx context.Context, formats strfmt.Registry) error { if m.Redispatch != nil { + + if swag.IsZero(m.Redispatch) { // not required + return nil + } + if err := m.Redispatch.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("redispatch") @@ -3656,6 +3745,11 @@ func (m *DefaultsBase) contextValidateRedispatch(ctx context.Context, formats st func (m *DefaultsBase) contextValidateSmtpchkParams(ctx context.Context, formats strfmt.Registry) error { if m.SmtpchkParams != nil { + + if swag.IsZero(m.SmtpchkParams) { // not required + return nil + } + if err := m.SmtpchkParams.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("smtpchk_params") @@ -3672,6 +3766,11 @@ func (m *DefaultsBase) contextValidateSmtpchkParams(ctx context.Context, formats func (m *DefaultsBase) contextValidateSource(ctx context.Context, formats strfmt.Registry) error { if m.Source != nil { + + if swag.IsZero(m.Source) { // not required + return nil + } + if err := m.Source.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("source") @@ -3688,6 +3787,11 @@ func (m *DefaultsBase) contextValidateSource(ctx context.Context, formats strfmt func (m *DefaultsBase) contextValidateStatsOptions(ctx context.Context, formats strfmt.Registry) error { if m.StatsOptions != nil { + + if swag.IsZero(m.StatsOptions) { // not required + return nil + } + if err := m.StatsOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("stats_options") diff --git a/models/defaults_base_compare_test.go b/models/defaults_base_compare_test.go index 783065c9..cc0fc34e 100644 --- a/models/defaults_base_compare_test.go +++ b/models/defaults_base_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestDefaultsBaseEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample DefaultsBase var result DefaultsBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestDefaultsBaseEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DefaultsBase to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestDefaultsBaseEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample DefaultsBase var result DefaultsBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Backlog = Ptr(*sample.Backlog + 1) result.CheckTimeout = Ptr(*sample.CheckTimeout + 1) @@ -122,11 +125,11 @@ func TestDefaultsBaseEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DefaultsBase to be different, but it is not %s %s", a, b) } @@ -140,17 +143,17 @@ func TestDefaultsBaseDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample DefaultsBase var result DefaultsBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -164,11 +167,11 @@ func TestDefaultsBaseDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DefaultsBase to be equal, but it is not %s %s, %v", a, b, result) } @@ -182,13 +185,13 @@ func TestDefaultsBaseDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample DefaultsBase var result DefaultsBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Backlog = Ptr(*sample.Backlog + 1) result.CheckTimeout = Ptr(*sample.CheckTimeout + 1) @@ -229,11 +232,11 @@ func TestDefaultsBaseDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DefaultsBase to be different in 106 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/defaults_compare_test.go b/models/defaults_compare_test.go index bcd9cb1c..80b98150 100644 --- a/models/defaults_compare_test.go +++ b/models/defaults_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestDefaultsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Defaults var result Defaults - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestDefaultsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Defaults to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestDefaultsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Defaults var result Defaults - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Defaults @@ -94,11 +97,11 @@ func TestDefaultsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Defaults to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestDefaultsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Defaults var result Defaults - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestDefaultsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Defaults to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestDefaultsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Defaults var result Defaults - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Defaults @@ -173,11 +176,11 @@ func TestDefaultsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Defaults to be different in 5 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/defaults_sections.go b/models/defaults_sections.go index 48231a77..93d14e66 100644 --- a/models/defaults_sections.go +++ b/models/defaults_sections.go @@ -71,6 +71,11 @@ func (m DefaultsSections) ContextValidate(ctx context.Context, formats strfmt.Re for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/device_atlas_options_compare_test.go b/models/device_atlas_options_compare_test.go index c83780d6..80c8a0d3 100644 --- a/models/device_atlas_options_compare_test.go +++ b/models/device_atlas_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestDeviceAtlasOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample DeviceAtlasOptions var result DeviceAtlasOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestDeviceAtlasOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DeviceAtlasOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestDeviceAtlasOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample DeviceAtlasOptions var result DeviceAtlasOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b DeviceAtlasOptions @@ -94,11 +97,11 @@ func TestDeviceAtlasOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DeviceAtlasOptions to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestDeviceAtlasOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample DeviceAtlasOptions var result DeviceAtlasOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestDeviceAtlasOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DeviceAtlasOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestDeviceAtlasOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample DeviceAtlasOptions var result DeviceAtlasOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b DeviceAtlasOptions @@ -173,11 +176,11 @@ func TestDeviceAtlasOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DeviceAtlasOptions to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/dgram_bind_compare_test.go b/models/dgram_bind_compare_test.go index 2e8d6fd9..cc12a1e7 100644 --- a/models/dgram_bind_compare_test.go +++ b/models/dgram_bind_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestDgramBindEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample DgramBind var result DgramBind - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestDgramBindEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DgramBind to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestDgramBindEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample DgramBind var result DgramBind - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) result.PortRangeEnd = Ptr(*sample.PortRangeEnd + 1) @@ -97,11 +100,11 @@ func TestDgramBindEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DgramBind to be different, but it is not %s %s", a, b) } @@ -115,17 +118,17 @@ func TestDgramBindDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample DgramBind var result DgramBind - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -139,11 +142,11 @@ func TestDgramBindDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DgramBind to be equal, but it is not %s %s, %v", a, b, result) } @@ -157,13 +160,13 @@ func TestDgramBindDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample DgramBind var result DgramBind - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) result.PortRangeEnd = Ptr(*sample.PortRangeEnd + 1) @@ -179,11 +182,11 @@ func TestDgramBindDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected DgramBind to be different in 7 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/dgram_binds.go b/models/dgram_binds.go index f7583b2b..4a4a038e 100644 --- a/models/dgram_binds.go +++ b/models/dgram_binds.go @@ -71,6 +71,11 @@ func (m DgramBinds) ContextValidate(ctx context.Context, formats strfmt.Registry for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/email_alert.go b/models/email_alert.go index 58ba8a22..ff064171 100644 --- a/models/email_alert.go +++ b/models/email_alert.go @@ -43,7 +43,7 @@ type EmailAlert struct { From *string `json:"from"` // level - // Enum: [emerg alert crit err warning notice info debug] + // Enum: ["emerg","alert","crit","err","warning","notice","info","debug"] // +kubebuilder:validation:Enum=emerg;alert;crit;err;warning;notice;info;debug; Level string `json:"level,omitempty"` diff --git a/models/email_alert_compare_test.go b/models/email_alert_compare_test.go index 98fd94f2..81269b74 100644 --- a/models/email_alert_compare_test.go +++ b/models/email_alert_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestEmailAlertEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample EmailAlert var result EmailAlert - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestEmailAlertEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected EmailAlert to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestEmailAlertEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample EmailAlert var result EmailAlert - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b EmailAlert @@ -94,11 +97,11 @@ func TestEmailAlertEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected EmailAlert to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestEmailAlertDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample EmailAlert var result EmailAlert - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestEmailAlertDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected EmailAlert to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestEmailAlertDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample EmailAlert var result EmailAlert - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b EmailAlert @@ -173,11 +176,11 @@ func TestEmailAlertDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected EmailAlert to be different in 5 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/email_alerts.go b/models/email_alerts.go index cea6f428..0fa6c8cc 100644 --- a/models/email_alerts.go +++ b/models/email_alerts.go @@ -71,6 +71,11 @@ func (m EmailAlerts) ContextValidate(ctx context.Context, formats strfmt.Registr for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/endpoint_compare_test.go b/models/endpoint_compare_test.go index 13233e1d..64ffec9b 100644 --- a/models/endpoint_compare_test.go +++ b/models/endpoint_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestEndpointEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Endpoint var result Endpoint - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestEndpointEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Endpoint to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestEndpointEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Endpoint var result Endpoint - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Endpoint @@ -94,11 +97,11 @@ func TestEndpointEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Endpoint to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestEndpointDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Endpoint var result Endpoint - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestEndpointDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Endpoint to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestEndpointDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Endpoint var result Endpoint - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Endpoint @@ -173,11 +176,11 @@ func TestEndpointDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Endpoint to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/endpoints.go b/models/endpoints.go index f648ef6c..78586959 100644 --- a/models/endpoints.go +++ b/models/endpoints.go @@ -71,6 +71,11 @@ func (m Endpoints) ContextValidate(ctx context.Context, formats strfmt.Registry) for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/environment_options.go b/models/environment_options.go index e910817c..3a2377eb 100644 --- a/models/environment_options.go +++ b/models/environment_options.go @@ -141,6 +141,11 @@ func (m *EnvironmentOptions) contextValidatePresetEnvs(ctx context.Context, form for i := 0; i < len(m.PresetEnvs); i++ { if m.PresetEnvs[i] != nil { + + if swag.IsZero(m.PresetEnvs[i]) { // not required + return nil + } + if err := m.PresetEnvs[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("presetenv" + "." + strconv.Itoa(i)) @@ -161,6 +166,11 @@ func (m *EnvironmentOptions) contextValidateSetEnvs(ctx context.Context, formats for i := 0; i < len(m.SetEnvs); i++ { if m.SetEnvs[i] != nil { + + if swag.IsZero(m.SetEnvs[i]) { // not required + return nil + } + if err := m.SetEnvs[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("setenv" + "." + strconv.Itoa(i)) diff --git a/models/environment_options_compare_test.go b/models/environment_options_compare_test.go index 08aad481..1512056a 100644 --- a/models/environment_options_compare_test.go +++ b/models/environment_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestEnvironmentOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample EnvironmentOptions var result EnvironmentOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestEnvironmentOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected EnvironmentOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestEnvironmentOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample EnvironmentOptions var result EnvironmentOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b EnvironmentOptions @@ -94,11 +97,11 @@ func TestEnvironmentOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected EnvironmentOptions to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestEnvironmentOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample EnvironmentOptions var result EnvironmentOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestEnvironmentOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected EnvironmentOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestEnvironmentOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample EnvironmentOptions var result EnvironmentOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b EnvironmentOptions @@ -173,11 +176,11 @@ func TestEnvironmentOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected EnvironmentOptions to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -191,17 +194,17 @@ func TestPresetEnvEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample PresetEnv var result PresetEnv - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -215,11 +218,11 @@ func TestPresetEnvEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PresetEnv to be equal, but it is not %s %s", a, b) } @@ -233,13 +236,13 @@ func TestPresetEnvEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample PresetEnv var result PresetEnv - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b PresetEnv @@ -252,11 +255,11 @@ func TestPresetEnvEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PresetEnv to be different, but it is not %s %s", a, b) } @@ -270,17 +273,17 @@ func TestPresetEnvDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample PresetEnv var result PresetEnv - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -294,11 +297,11 @@ func TestPresetEnvDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PresetEnv to be equal, but it is not %s %s, %v", a, b, result) } @@ -312,13 +315,13 @@ func TestPresetEnvDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample PresetEnv var result PresetEnv - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b PresetEnv @@ -331,11 +334,11 @@ func TestPresetEnvDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PresetEnv to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -349,17 +352,17 @@ func TestSetEnvEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SetEnv var result SetEnv - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -373,11 +376,11 @@ func TestSetEnvEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SetEnv to be equal, but it is not %s %s", a, b) } @@ -391,13 +394,13 @@ func TestSetEnvEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SetEnv var result SetEnv - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SetEnv @@ -410,11 +413,11 @@ func TestSetEnvEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SetEnv to be different, but it is not %s %s", a, b) } @@ -428,17 +431,17 @@ func TestSetEnvDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SetEnv var result SetEnv - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -452,11 +455,11 @@ func TestSetEnvDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SetEnv to be equal, but it is not %s %s, %v", a, b, result) } @@ -470,13 +473,13 @@ func TestSetEnvDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SetEnv var result SetEnv - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SetEnv @@ -489,11 +492,11 @@ func TestSetEnvDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SetEnv to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/error_compare_test.go b/models/error_compare_test.go index 077e25f0..c5a0f815 100644 --- a/models/error_compare_test.go +++ b/models/error_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestErrorEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Error var result Error - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestErrorEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Error to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestErrorEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Error var result Error - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Code = Ptr(*sample.Code + 1) samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestErrorEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Error to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestErrorDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Error var result Error - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestErrorDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Error to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestErrorDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Error var result Error - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Code = Ptr(*sample.Code + 1) samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestErrorDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Error to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/errorfile.go b/models/errorfile.go index f0ec9fb2..24840562 100644 --- a/models/errorfile.go +++ b/models/errorfile.go @@ -35,7 +35,7 @@ import ( // swagger:model errorfile type Errorfile struct { // code - // Enum: [200 400 401 403 404 405 407 408 410 413 425 429 500 501 502 503 504] + // Enum: [200,400,401,403,404,405,407,408,410,413,425,429,500,501,502,503,504] // +kubebuilder:validation:Enum=200;400;401;403;404;405;407;408;410;413;425;429;500;501;502;503;504; Code int64 `json:"code,omitempty"` diff --git a/models/errorfile_compare_test.go b/models/errorfile_compare_test.go index 20d1b429..252b968b 100644 --- a/models/errorfile_compare_test.go +++ b/models/errorfile_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestErrorfileEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Errorfile var result Errorfile - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestErrorfileEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Errorfile to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestErrorfileEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Errorfile var result Errorfile - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Code = sample.Code + 1 samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestErrorfileEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Errorfile to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestErrorfileDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Errorfile var result Errorfile - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestErrorfileDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Errorfile to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestErrorfileDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Errorfile var result Errorfile - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Code = sample.Code + 1 samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestErrorfileDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Errorfile to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/errorfiles_compare_test.go b/models/errorfiles_compare_test.go index df382146..0c260bf1 100644 --- a/models/errorfiles_compare_test.go +++ b/models/errorfiles_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestErrorfilesEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Errorfiles var result Errorfiles - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestErrorfilesEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Errorfiles to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestErrorfilesEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Errorfiles var result Errorfiles - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Errorfiles @@ -94,11 +97,11 @@ func TestErrorfilesEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Errorfiles to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestErrorfilesDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Errorfiles var result Errorfiles - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestErrorfilesDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Errorfiles to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestErrorfilesDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Errorfiles var result Errorfiles - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Errorfiles @@ -173,11 +176,11 @@ func TestErrorfilesDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Errorfiles to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/errorloc.go b/models/errorloc.go index a5e80e0b..62df9587 100644 --- a/models/errorloc.go +++ b/models/errorloc.go @@ -36,7 +36,7 @@ import ( type Errorloc struct { // code // Required: true - // Enum: [200 400 401 403 404 405 407 408 410 413 425 429 500 501 502 503 504] + // Enum: [200,400,401,403,404,405,407,408,410,413,425,429,500,501,502,503,504] // +kubebuilder:validation:Enum=200;400;401;403;404;405;407;408;410;413;425;429;500;501;502;503;504; Code *int64 `json:"code"` diff --git a/models/errorloc_compare_test.go b/models/errorloc_compare_test.go index 3d8750c0..cf37738c 100644 --- a/models/errorloc_compare_test.go +++ b/models/errorloc_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestErrorlocEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Errorloc var result Errorloc - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestErrorlocEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Errorloc to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestErrorlocEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Errorloc var result Errorloc - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Code = Ptr(*sample.Code + 1) samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestErrorlocEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Errorloc to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestErrorlocDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Errorloc var result Errorloc - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestErrorlocDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Errorloc to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestErrorlocDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Errorloc var result Errorloc - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Code = Ptr(*sample.Code + 1) samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestErrorlocDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Errorloc to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/fcgi_app_base.go b/models/fcgi_app_base.go index d641678c..bc6b4efe 100644 --- a/models/fcgi_app_base.go +++ b/models/fcgi_app_base.go @@ -43,7 +43,7 @@ type FCGIAppBase struct { Docroot *string `json:"docroot"` // Enables or disables the retrieval of variables related to connection management. - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; GetValues string `json:"get_values,omitempty"` @@ -51,7 +51,7 @@ type FCGIAppBase struct { Index string `json:"index,omitempty"` // Tells the FastCGI application whether or not to keep the connection open after it sends a response. If disabled, the FastCGI application closes the connection after responding to this request. - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; KeepConn string `json:"keep_conn,omitempty"` @@ -64,7 +64,7 @@ type FCGIAppBase struct { MaxReqs int64 `json:"max_reqs,omitempty"` // Enables or disables the support of connection multiplexing. If the FastCGI application retrieves the variable FCGI_MPXS_CONNS during connection establishment, it can override this option. - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; MpxsConns string `json:"mpxs_conns,omitempty"` @@ -397,6 +397,11 @@ func (m *FCGIAppBase) contextValidateLogStderrs(ctx context.Context, formats str for i := 0; i < len(m.LogStderrs); i++ { if m.LogStderrs[i] != nil { + + if swag.IsZero(m.LogStderrs[i]) { // not required + return nil + } + if err := m.LogStderrs[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("log_stderrs" + "." + strconv.Itoa(i)) @@ -417,6 +422,11 @@ func (m *FCGIAppBase) contextValidatePassHeaders(ctx context.Context, formats st for i := 0; i < len(m.PassHeaders); i++ { if m.PassHeaders[i] != nil { + + if swag.IsZero(m.PassHeaders[i]) { // not required + return nil + } + if err := m.PassHeaders[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("pass_headers" + "." + strconv.Itoa(i)) @@ -437,6 +447,11 @@ func (m *FCGIAppBase) contextValidateSetParams(ctx context.Context, formats strf for i := 0; i < len(m.SetParams); i++ { if m.SetParams[i] != nil { + + if swag.IsZero(m.SetParams[i]) { // not required + return nil + } + if err := m.SetParams[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("set_params" + "." + strconv.Itoa(i)) diff --git a/models/fcgi_app_base_compare_test.go b/models/fcgi_app_base_compare_test.go index 0fca117d..4c753515 100644 --- a/models/fcgi_app_base_compare_test.go +++ b/models/fcgi_app_base_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestFCGIAppBaseEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGIAppBase var result FCGIAppBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestFCGIAppBaseEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGIAppBase to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestFCGIAppBaseEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGIAppBase var result FCGIAppBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.MaxReqs = sample.MaxReqs + 1 samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestFCGIAppBaseEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGIAppBase to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestFCGIAppBaseDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGIAppBase var result FCGIAppBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestFCGIAppBaseDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGIAppBase to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestFCGIAppBaseDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGIAppBase var result FCGIAppBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.MaxReqs = sample.MaxReqs + 1 samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestFCGIAppBaseDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGIAppBase to be different in 11 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/fcgi_app_compare_test.go b/models/fcgi_app_compare_test.go index e6e880f6..1e583d33 100644 --- a/models/fcgi_app_compare_test.go +++ b/models/fcgi_app_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestFCGIAppEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGIApp var result FCGIApp - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestFCGIAppEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGIApp to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestFCGIAppEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGIApp var result FCGIApp - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b FCGIApp @@ -94,11 +97,11 @@ func TestFCGIAppEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGIApp to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestFCGIAppDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGIApp var result FCGIApp - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestFCGIAppDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGIApp to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestFCGIAppDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGIApp var result FCGIApp - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b FCGIApp @@ -173,11 +176,11 @@ func TestFCGIAppDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGIApp to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/fcgi_apps.go b/models/fcgi_apps.go index 051fd552..0b757e6b 100644 --- a/models/fcgi_apps.go +++ b/models/fcgi_apps.go @@ -69,6 +69,11 @@ func (m FCGIApps) ContextValidate(ctx context.Context, formats strfmt.Registry) for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/fcgi_log_stderr.go b/models/fcgi_log_stderr.go index 573fea93..f8bf6f47 100644 --- a/models/fcgi_log_stderr.go +++ b/models/fcgi_log_stderr.go @@ -110,6 +110,11 @@ func (m *FCGILogStderr) ContextValidate(ctx context.Context, formats strfmt.Regi func (m *FCGILogStderr) contextValidateSample(ctx context.Context, formats strfmt.Registry) error { if m.Sample != nil { + + if swag.IsZero(m.Sample) { // not required + return nil + } + if err := m.Sample.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("sample") diff --git a/models/fcgi_log_stderr_compare_test.go b/models/fcgi_log_stderr_compare_test.go index 27a1a49f..a71616ac 100644 --- a/models/fcgi_log_stderr_compare_test.go +++ b/models/fcgi_log_stderr_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestFCGILogStderrEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGILogStderr var result FCGILogStderr - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestFCGILogStderrEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGILogStderr to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestFCGILogStderrEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGILogStderr var result FCGILogStderr - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Global = !sample.Global result.Len = sample.Len + 1 @@ -96,11 +99,11 @@ func TestFCGILogStderrEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGILogStderr to be different, but it is not %s %s", a, b) } @@ -114,17 +117,17 @@ func TestFCGILogStderrDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGILogStderr var result FCGILogStderr - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -138,11 +141,11 @@ func TestFCGILogStderrDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGILogStderr to be equal, but it is not %s %s, %v", a, b, result) } @@ -156,13 +159,13 @@ func TestFCGILogStderrDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGILogStderr var result FCGILogStderr - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Global = !sample.Global result.Len = sample.Len + 1 @@ -177,11 +180,11 @@ func TestFCGILogStderrDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGILogStderr to be different in 8 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -195,17 +198,17 @@ func TestFCGILogStderrSampleEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGILogStderrSample var result FCGILogStderrSample - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -219,11 +222,11 @@ func TestFCGILogStderrSampleEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGILogStderrSample to be equal, but it is not %s %s", a, b) } @@ -237,13 +240,13 @@ func TestFCGILogStderrSampleEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGILogStderrSample var result FCGILogStderrSample - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Size = Ptr(*sample.Size + 1) samples = append(samples, struct { @@ -257,11 +260,11 @@ func TestFCGILogStderrSampleEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGILogStderrSample to be different, but it is not %s %s", a, b) } @@ -275,17 +278,17 @@ func TestFCGILogStderrSampleDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGILogStderrSample var result FCGILogStderrSample - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -299,11 +302,11 @@ func TestFCGILogStderrSampleDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGILogStderrSample to be equal, but it is not %s %s, %v", a, b, result) } @@ -317,13 +320,13 @@ func TestFCGILogStderrSampleDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGILogStderrSample var result FCGILogStderrSample - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Size = Ptr(*sample.Size + 1) samples = append(samples, struct { @@ -337,11 +340,11 @@ func TestFCGILogStderrSampleDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGILogStderrSample to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/fcgi_pass_header.go b/models/fcgi_pass_header.go index 65c93ecf..109d5dd1 100644 --- a/models/fcgi_pass_header.go +++ b/models/fcgi_pass_header.go @@ -40,7 +40,7 @@ import ( // swagger:model fcgiPassHeader type FCGIPassHeader struct { // cond - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond string `json:"cond,omitempty"` diff --git a/models/fcgi_pass_header_compare_test.go b/models/fcgi_pass_header_compare_test.go index 44660d3c..94331e3a 100644 --- a/models/fcgi_pass_header_compare_test.go +++ b/models/fcgi_pass_header_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestFCGIPassHeaderEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGIPassHeader var result FCGIPassHeader - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestFCGIPassHeaderEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGIPassHeader to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestFCGIPassHeaderEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGIPassHeader var result FCGIPassHeader - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b FCGIPassHeader @@ -94,11 +97,11 @@ func TestFCGIPassHeaderEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGIPassHeader to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestFCGIPassHeaderDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGIPassHeader var result FCGIPassHeader - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestFCGIPassHeaderDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGIPassHeader to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestFCGIPassHeaderDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGIPassHeader var result FCGIPassHeader - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b FCGIPassHeader @@ -173,11 +176,11 @@ func TestFCGIPassHeaderDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGIPassHeader to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/fcgi_set_param.go b/models/fcgi_set_param.go index f0ab539e..253076fc 100644 --- a/models/fcgi_set_param.go +++ b/models/fcgi_set_param.go @@ -37,7 +37,7 @@ import ( // swagger:model fcgiSetParam type FCGISetParam struct { // cond - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond string `json:"cond,omitempty"` diff --git a/models/fcgi_set_param_compare_test.go b/models/fcgi_set_param_compare_test.go index 387f676f..95bc5b62 100644 --- a/models/fcgi_set_param_compare_test.go +++ b/models/fcgi_set_param_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestFCGISetParamEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGISetParam var result FCGISetParam - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestFCGISetParamEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGISetParam to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestFCGISetParamEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGISetParam var result FCGISetParam - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b FCGISetParam @@ -94,11 +97,11 @@ func TestFCGISetParamEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGISetParam to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestFCGISetParamDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGISetParam var result FCGISetParam - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestFCGISetParamDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGISetParam to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestFCGISetParamDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FCGISetParam var result FCGISetParam - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b FCGISetParam @@ -173,11 +176,11 @@ func TestFCGISetParamDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FCGISetParam to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/fifty_one_degrees_options_compare_test.go b/models/fifty_one_degrees_options_compare_test.go index b3d58837..16980b06 100644 --- a/models/fifty_one_degrees_options_compare_test.go +++ b/models/fifty_one_degrees_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestFiftyOneDegreesOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample FiftyOneDegreesOptions var result FiftyOneDegreesOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestFiftyOneDegreesOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FiftyOneDegreesOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestFiftyOneDegreesOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FiftyOneDegreesOptions var result FiftyOneDegreesOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CacheSize = sample.CacheSize + 1 samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestFiftyOneDegreesOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FiftyOneDegreesOptions to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestFiftyOneDegreesOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample FiftyOneDegreesOptions var result FiftyOneDegreesOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestFiftyOneDegreesOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FiftyOneDegreesOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestFiftyOneDegreesOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FiftyOneDegreesOptions var result FiftyOneDegreesOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CacheSize = sample.CacheSize + 1 samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestFiftyOneDegreesOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FiftyOneDegreesOptions to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/filter.go b/models/filter.go index 5dd9c2b6..80023498 100644 --- a/models/filter.go +++ b/models/filter.go @@ -107,7 +107,7 @@ type Filter struct { // type // Required: true - // Enum: [bwlim-in bwlim-out cache compression fcgi-app spoe trace] + // Enum: ["bwlim-in","bwlim-out","cache","compression","fcgi-app","spoe","trace"] // +kubebuilder:validation:Enum=bwlim-in;bwlim-out;cache;compression;fcgi-app;spoe;trace; Type string `json:"type"` } diff --git a/models/filter_compare_test.go b/models/filter_compare_test.go index 6ebbd0a9..fe83e588 100644 --- a/models/filter_compare_test.go +++ b/models/filter_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestFilterEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Filter var result Filter - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestFilterEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Filter to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestFilterEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Filter var result Filter - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.DefaultLimit = sample.DefaultLimit + 1 result.DefaultPeriod = sample.DefaultPeriod + 1 @@ -101,11 +104,11 @@ func TestFilterEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Filter to be different, but it is not %s %s", a, b) } @@ -119,17 +122,17 @@ func TestFilterDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Filter var result Filter - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -143,11 +146,11 @@ func TestFilterDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Filter to be equal, but it is not %s %s, %v", a, b, result) } @@ -161,13 +164,13 @@ func TestFilterDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Filter var result Filter - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.DefaultLimit = sample.DefaultLimit + 1 result.DefaultPeriod = sample.DefaultPeriod + 1 @@ -187,11 +190,11 @@ func TestFilterDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Filter to be different in 16 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/filters.go b/models/filters.go index 46145ecc..870c98d5 100644 --- a/models/filters.go +++ b/models/filters.go @@ -71,6 +71,11 @@ func (m Filters) ContextValidate(ctx context.Context, formats strfmt.Registry) e for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/forwardfor.go b/models/forwardfor.go index fa25c05d..68da0124 100644 --- a/models/forwardfor.go +++ b/models/forwardfor.go @@ -36,7 +36,7 @@ import ( type Forwardfor struct { // enabled // Required: true - // Enum: [enabled] + // Enum: ["enabled"] // +kubebuilder:validation:Enum=enabled; Enabled *string `json:"enabled"` diff --git a/models/forwardfor_compare_test.go b/models/forwardfor_compare_test.go index bbf6dcae..fe6f6e39 100644 --- a/models/forwardfor_compare_test.go +++ b/models/forwardfor_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestForwardforEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Forwardfor var result Forwardfor - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestForwardforEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Forwardfor to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestForwardforEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Forwardfor var result Forwardfor - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Ifnone = !sample.Ifnone samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestForwardforEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Forwardfor to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestForwardforDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Forwardfor var result Forwardfor - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestForwardforDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Forwardfor to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestForwardforDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Forwardfor var result Forwardfor - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Ifnone = !sample.Ifnone samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestForwardforDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Forwardfor to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/frontend_base.go b/models/frontend_base.go index 5704680e..3e05a596 100644 --- a/models/frontend_base.go +++ b/models/frontend_base.go @@ -46,7 +46,7 @@ type FrontendBase struct { ErrorFilesFromHTTPErrors []*Errorfiles `json:"errorfiles_from_http_errors,omitempty"` // accept invalid http request - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; AcceptInvalidHTTPRequest string `json:"accept_invalid_http_request,omitempty"` @@ -67,7 +67,7 @@ type FrontendBase struct { ClientTimeout *int64 `json:"client_timeout,omitempty"` // clitcpka - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Clitcpka string `json:"clitcpka,omitempty"` @@ -84,7 +84,7 @@ type FrontendBase struct { Compression *Compression `json:"compression,omitempty"` // contstats - // Enum: [enabled] + // Enum: ["enabled"] // +kubebuilder:validation:Enum=enabled; Contstats string `json:"contstats,omitempty"` @@ -97,7 +97,7 @@ type FrontendBase struct { Description string `json:"description,omitempty"` // disable h2 upgrade - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; DisableH2Upgrade string `json:"disable_h2_upgrade,omitempty"` @@ -105,12 +105,12 @@ type FrontendBase struct { Disabled bool `json:"disabled,omitempty"` // dontlog normal - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; DontlogNormal string `json:"dontlog_normal,omitempty"` // dontlognull - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Dontlognull string `json:"dontlognull,omitempty"` @@ -143,27 +143,27 @@ type FrontendBase struct { GUID string `json:"guid,omitempty"` // h1 case adjust bogus client - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; H1CaseAdjustBogusClient string `json:"h1_case_adjust_bogus_client,omitempty"` // http buffer request - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; HTTPBufferRequest string `json:"http-buffer-request,omitempty"` // http use htx - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; HTTPUseHtx string `json:"http-use-htx,omitempty"` // http connection mode - // Enum: [httpclose http-server-close http-keep-alive] + // Enum: ["httpclose","http-server-close","http-keep-alive"] // +kubebuilder:validation:Enum=httpclose;http-server-close;http-keep-alive; HTTPConnectionMode string `json:"http_connection_mode,omitempty"` // http ignore probes - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; HTTPIgnoreProbes string `json:"http_ignore_probes,omitempty"` @@ -173,7 +173,7 @@ type FrontendBase struct { HTTPKeepAliveTimeout *int64 `json:"http_keep_alive_timeout,omitempty"` // http no delay - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; HTTPNoDelay string `json:"http_no_delay,omitempty"` @@ -183,12 +183,12 @@ type FrontendBase struct { HTTPRequestTimeout *int64 `json:"http_request_timeout,omitempty"` // http restrict req hdr names - // Enum: [preserve delete reject] + // Enum: ["preserve","delete","reject"] // +kubebuilder:validation:Enum=preserve;delete;reject; HTTPRestrictReqHdrNames string `json:"http_restrict_req_hdr_names,omitempty"` // http use proxy header - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; HTTPUseProxyHeader string `json:"http_use_proxy_header,omitempty"` @@ -196,7 +196,7 @@ type FrontendBase struct { Httplog bool `json:"httplog,omitempty"` // httpslog - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Httpslog string `json:"httpslog,omitempty"` @@ -204,12 +204,12 @@ type FrontendBase struct { ID *int64 `json:"id,omitempty"` // idle close on response - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; IdleCloseOnResponse string `json:"idle_close_on_response,omitempty"` // independent streams - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; IndependentStreams string `json:"independent_streams,omitempty"` @@ -220,7 +220,7 @@ type FrontendBase struct { LogFormatSd string `json:"log_format_sd,omitempty"` // log separate errors - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; LogSeparateErrors string `json:"log_separate_errors,omitempty"` @@ -230,7 +230,7 @@ type FrontendBase struct { LogTag string `json:"log_tag,omitempty"` // logasap - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Logasap string `json:"logasap,omitempty"` @@ -238,7 +238,7 @@ type FrontendBase struct { Maxconn *int64 `json:"maxconn,omitempty"` // mode - // Enum: [http tcp] + // Enum: ["http","tcp"] // +kubebuilder:validation:Enum=http;tcp; Mode string `json:"mode,omitempty"` @@ -255,7 +255,7 @@ type FrontendBase struct { Name string `json:"name"` // nolinger - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Nolinger string `json:"nolinger,omitempty"` @@ -263,22 +263,22 @@ type FrontendBase struct { Originalto *Originalto `json:"originalto,omitempty"` // socket stats - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SocketStats string `json:"socket_stats,omitempty"` // splice auto - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SpliceAuto string `json:"splice_auto,omitempty"` // splice request - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SpliceRequest string `json:"splice_request,omitempty"` // splice response - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SpliceResponse string `json:"splice_response,omitempty"` @@ -294,12 +294,12 @@ type FrontendBase struct { TarpitTimeout *int64 `json:"tarpit_timeout,omitempty"` // tcp smart accept - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; TCPSmartAccept string `json:"tcp_smart_accept,omitempty"` // tcpka - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Tcpka string `json:"tcpka,omitempty"` @@ -2080,6 +2080,11 @@ func (m *FrontendBase) contextValidateErrorFiles(ctx context.Context, formats st for i := 0; i < len(m.ErrorFiles); i++ { if m.ErrorFiles[i] != nil { + + if swag.IsZero(m.ErrorFiles[i]) { // not required + return nil + } + if err := m.ErrorFiles[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("error_files" + "." + strconv.Itoa(i)) @@ -2100,6 +2105,11 @@ func (m *FrontendBase) contextValidateErrorFilesFromHTTPErrors(ctx context.Conte for i := 0; i < len(m.ErrorFilesFromHTTPErrors); i++ { if m.ErrorFilesFromHTTPErrors[i] != nil { + + if swag.IsZero(m.ErrorFilesFromHTTPErrors[i]) { // not required + return nil + } + if err := m.ErrorFilesFromHTTPErrors[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("errorfiles_from_http_errors" + "." + strconv.Itoa(i)) @@ -2118,6 +2128,11 @@ func (m *FrontendBase) contextValidateErrorFilesFromHTTPErrors(ctx context.Conte func (m *FrontendBase) contextValidateCompression(ctx context.Context, formats strfmt.Registry) error { if m.Compression != nil { + + if swag.IsZero(m.Compression) { // not required + return nil + } + if err := m.Compression.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("compression") @@ -2134,6 +2149,11 @@ func (m *FrontendBase) contextValidateCompression(ctx context.Context, formats s func (m *FrontendBase) contextValidateEmailAlert(ctx context.Context, formats strfmt.Registry) error { if m.EmailAlert != nil { + + if swag.IsZero(m.EmailAlert) { // not required + return nil + } + if err := m.EmailAlert.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("email_alert") @@ -2150,6 +2170,11 @@ func (m *FrontendBase) contextValidateEmailAlert(ctx context.Context, formats st func (m *FrontendBase) contextValidateErrorloc302(ctx context.Context, formats strfmt.Registry) error { if m.Errorloc302 != nil { + + if swag.IsZero(m.Errorloc302) { // not required + return nil + } + if err := m.Errorloc302.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("errorloc302") @@ -2166,6 +2191,11 @@ func (m *FrontendBase) contextValidateErrorloc302(ctx context.Context, formats s func (m *FrontendBase) contextValidateErrorloc303(ctx context.Context, formats strfmt.Registry) error { if m.Errorloc303 != nil { + + if swag.IsZero(m.Errorloc303) { // not required + return nil + } + if err := m.Errorloc303.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("errorloc303") @@ -2182,6 +2212,11 @@ func (m *FrontendBase) contextValidateErrorloc303(ctx context.Context, formats s func (m *FrontendBase) contextValidateForwardfor(ctx context.Context, formats strfmt.Registry) error { if m.Forwardfor != nil { + + if swag.IsZero(m.Forwardfor) { // not required + return nil + } + if err := m.Forwardfor.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("forwardfor") @@ -2198,6 +2233,11 @@ func (m *FrontendBase) contextValidateForwardfor(ctx context.Context, formats st func (m *FrontendBase) contextValidateMonitorFail(ctx context.Context, formats strfmt.Registry) error { if m.MonitorFail != nil { + + if swag.IsZero(m.MonitorFail) { // not required + return nil + } + if err := m.MonitorFail.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("monitor_fail") @@ -2213,6 +2253,10 @@ func (m *FrontendBase) contextValidateMonitorFail(ctx context.Context, formats s func (m *FrontendBase) contextValidateMonitorURI(ctx context.Context, formats strfmt.Registry) error { + if swag.IsZero(m.MonitorURI) { // not required + return nil + } + if err := m.MonitorURI.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("monitor_uri") @@ -2228,6 +2272,11 @@ func (m *FrontendBase) contextValidateMonitorURI(ctx context.Context, formats st func (m *FrontendBase) contextValidateOriginalto(ctx context.Context, formats strfmt.Registry) error { if m.Originalto != nil { + + if swag.IsZero(m.Originalto) { // not required + return nil + } + if err := m.Originalto.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("originalto") @@ -2244,6 +2293,11 @@ func (m *FrontendBase) contextValidateOriginalto(ctx context.Context, formats st func (m *FrontendBase) contextValidateStatsOptions(ctx context.Context, formats strfmt.Registry) error { if m.StatsOptions != nil { + + if swag.IsZero(m.StatsOptions) { // not required + return nil + } + if err := m.StatsOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("stats_options") @@ -2260,6 +2314,11 @@ func (m *FrontendBase) contextValidateStatsOptions(ctx context.Context, formats func (m *FrontendBase) contextValidateStickTable(ctx context.Context, formats strfmt.Registry) error { if m.StickTable != nil { + + if swag.IsZero(m.StickTable) { // not required + return nil + } + if err := m.StickTable.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("stick_table") diff --git a/models/frontend_base_compare_test.go b/models/frontend_base_compare_test.go index 0c53b822..a3f254c1 100644 --- a/models/frontend_base_compare_test.go +++ b/models/frontend_base_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestFrontendBaseEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample FrontendBase var result FrontendBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestFrontendBaseEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FrontendBase to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestFrontendBaseEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FrontendBase var result FrontendBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Backlog = Ptr(*sample.Backlog + 1) result.Clflog = !sample.Clflog @@ -110,11 +113,11 @@ func TestFrontendBaseEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FrontendBase to be different, but it is not %s %s", a, b) } @@ -128,17 +131,17 @@ func TestFrontendBaseDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample FrontendBase var result FrontendBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -152,11 +155,11 @@ func TestFrontendBaseDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FrontendBase to be equal, but it is not %s %s, %v", a, b, result) } @@ -170,13 +173,13 @@ func TestFrontendBaseDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample FrontendBase var result FrontendBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Backlog = Ptr(*sample.Backlog + 1) result.Clflog = !sample.Clflog @@ -205,11 +208,11 @@ func TestFrontendBaseDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected FrontendBase to be different in 66 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/frontend_compare_test.go b/models/frontend_compare_test.go index 5acfd924..6b106bc2 100644 --- a/models/frontend_compare_test.go +++ b/models/frontend_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestFrontendEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Frontend var result Frontend - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestFrontendEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Frontend to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestFrontendEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Frontend var result Frontend - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Frontend @@ -94,11 +97,11 @@ func TestFrontendEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Frontend to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestFrontendDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Frontend var result Frontend - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestFrontendDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Frontend to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestFrontendDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Frontend var result Frontend - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Frontend @@ -173,11 +176,11 @@ func TestFrontendDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Frontend to be different in 12 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/frontends.go b/models/frontends.go index 70481e10..8dade53c 100644 --- a/models/frontends.go +++ b/models/frontends.go @@ -71,6 +71,11 @@ func (m Frontends) ContextValidate(ctx context.Context, formats strfmt.Registry) for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/general_file_compare_test.go b/models/general_file_compare_test.go index 1aaba66d..2113049a 100644 --- a/models/general_file_compare_test.go +++ b/models/general_file_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestGeneralFileEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample GeneralFile var result GeneralFile - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestGeneralFileEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GeneralFile to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestGeneralFileEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample GeneralFile var result GeneralFile - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Size = Ptr(*sample.Size + 1) samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestGeneralFileEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GeneralFile to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestGeneralFileDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample GeneralFile var result GeneralFile - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestGeneralFileDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GeneralFile to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestGeneralFileDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample GeneralFile var result GeneralFile - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Size = Ptr(*sample.Size + 1) samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestGeneralFileDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GeneralFile to be different in 5 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/general_files.go b/models/general_files.go index 9ecd3b06..87ba33fd 100644 --- a/models/general_files.go +++ b/models/general_files.go @@ -71,6 +71,11 @@ func (m GeneralFiles) ContextValidate(ctx context.Context, formats strfmt.Regist for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/global_base.go b/models/global_base.go index 080d3d5c..aa5ea180 100644 --- a/models/global_base.go +++ b/models/global_base.go @@ -109,9 +109,15 @@ type GlobalBase struct { // +kubebuilder:validation:Pattern=`^[^\s]+$` Group string `json:"group,omitempty"` + // h1 accept payload with any method + H1AcceptPayloadWithAnyMethod bool `json:"h1_accept_payload_with_any_method,omitempty"` + // h1 case adjust file H1CaseAdjustFile string `json:"h1_case_adjust_file,omitempty"` + // h1 do not close on insecure transfer encoding + H1DoNotCloseOnInsecureTransferEncoding bool `json:"h1_do_not_close_on_insecure_transfer_encoding,omitempty"` + // h2 workaround bogus websocket clients H2WorkaroundBogusWebsocketClients bool `json:"h2_workaround_bogus_websocket_clients,omitempty"` @@ -170,7 +176,7 @@ type GlobalBase struct { Node string `json:"node,omitempty"` // numa cpu mapping - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; NumaCPUMapping string `json:"numa_cpu_mapping,omitempty"` @@ -200,6 +206,9 @@ type GlobalBase struct { // ssl options SslOptions *SslOptions `json:"ssl_options,omitempty"` + // stats file + StatsFile string `json:"stats_file,omitempty"` + // stats maxconn StatsMaxconn *int64 `json:"stats_maxconn,omitempty"` @@ -1293,6 +1302,11 @@ func (m *GlobalBase) contextValidateCPUMaps(ctx context.Context, formats strfmt. for i := 0; i < len(m.CPUMaps); i++ { if m.CPUMaps[i] != nil { + + if swag.IsZero(m.CPUMaps[i]) { // not required + return nil + } + if err := m.CPUMaps[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("cpu_maps" + "." + strconv.Itoa(i)) @@ -1313,6 +1327,11 @@ func (m *GlobalBase) contextValidateH1CaseAdjusts(ctx context.Context, formats s for i := 0; i < len(m.H1CaseAdjusts); i++ { if m.H1CaseAdjusts[i] != nil { + + if swag.IsZero(m.H1CaseAdjusts[i]) { // not required + return nil + } + if err := m.H1CaseAdjusts[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("h1_case_adjust" + "." + strconv.Itoa(i)) @@ -1333,6 +1352,11 @@ func (m *GlobalBase) contextValidateRuntimeAPIs(ctx context.Context, formats str for i := 0; i < len(m.RuntimeAPIs); i++ { if m.RuntimeAPIs[i] != nil { + + if swag.IsZero(m.RuntimeAPIs[i]) { // not required + return nil + } + if err := m.RuntimeAPIs[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("runtime_apis" + "." + strconv.Itoa(i)) @@ -1353,6 +1377,11 @@ func (m *GlobalBase) contextValidateSetVarFmts(ctx context.Context, formats strf for i := 0; i < len(m.SetVarFmts); i++ { if m.SetVarFmts[i] != nil { + + if swag.IsZero(m.SetVarFmts[i]) { // not required + return nil + } + if err := m.SetVarFmts[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("set_var_fmt" + "." + strconv.Itoa(i)) @@ -1373,6 +1402,11 @@ func (m *GlobalBase) contextValidateSetVars(ctx context.Context, formats strfmt. for i := 0; i < len(m.SetVars); i++ { if m.SetVars[i] != nil { + + if swag.IsZero(m.SetVars[i]) { // not required + return nil + } + if err := m.SetVars[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("set_var" + "." + strconv.Itoa(i)) @@ -1393,6 +1427,11 @@ func (m *GlobalBase) contextValidateThreadGroupLines(ctx context.Context, format for i := 0; i < len(m.ThreadGroupLines); i++ { if m.ThreadGroupLines[i] != nil { + + if swag.IsZero(m.ThreadGroupLines[i]) { // not required + return nil + } + if err := m.ThreadGroupLines[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("thread_group_lines" + "." + strconv.Itoa(i)) @@ -1411,6 +1450,11 @@ func (m *GlobalBase) contextValidateThreadGroupLines(ctx context.Context, format func (m *GlobalBase) contextValidateDebugOptions(ctx context.Context, formats strfmt.Registry) error { if m.DebugOptions != nil { + + if swag.IsZero(m.DebugOptions) { // not required + return nil + } + if err := m.DebugOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("debug_options") @@ -1427,6 +1471,11 @@ func (m *GlobalBase) contextValidateDebugOptions(ctx context.Context, formats st func (m *GlobalBase) contextValidateDefaultPath(ctx context.Context, formats strfmt.Registry) error { if m.DefaultPath != nil { + + if swag.IsZero(m.DefaultPath) { // not required + return nil + } + if err := m.DefaultPath.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("default_path") @@ -1443,6 +1492,11 @@ func (m *GlobalBase) contextValidateDefaultPath(ctx context.Context, formats str func (m *GlobalBase) contextValidateDeviceAtlasOptions(ctx context.Context, formats strfmt.Registry) error { if m.DeviceAtlasOptions != nil { + + if swag.IsZero(m.DeviceAtlasOptions) { // not required + return nil + } + if err := m.DeviceAtlasOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("device_atlas_options") @@ -1459,6 +1513,11 @@ func (m *GlobalBase) contextValidateDeviceAtlasOptions(ctx context.Context, form func (m *GlobalBase) contextValidateEnvironmentOptions(ctx context.Context, formats strfmt.Registry) error { if m.EnvironmentOptions != nil { + + if swag.IsZero(m.EnvironmentOptions) { // not required + return nil + } + if err := m.EnvironmentOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("environment_options") @@ -1475,6 +1534,11 @@ func (m *GlobalBase) contextValidateEnvironmentOptions(ctx context.Context, form func (m *GlobalBase) contextValidateFiftyOneDegreesOptions(ctx context.Context, formats strfmt.Registry) error { if m.FiftyOneDegreesOptions != nil { + + if swag.IsZero(m.FiftyOneDegreesOptions) { // not required + return nil + } + if err := m.FiftyOneDegreesOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("fifty_one_degrees_options") @@ -1491,6 +1555,11 @@ func (m *GlobalBase) contextValidateFiftyOneDegreesOptions(ctx context.Context, func (m *GlobalBase) contextValidateHarden(ctx context.Context, formats strfmt.Registry) error { if m.Harden != nil { + + if swag.IsZero(m.Harden) { // not required + return nil + } + if err := m.Harden.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("harden") @@ -1507,6 +1576,11 @@ func (m *GlobalBase) contextValidateHarden(ctx context.Context, formats strfmt.R func (m *GlobalBase) contextValidateHTTPClientOptions(ctx context.Context, formats strfmt.Registry) error { if m.HTTPClientOptions != nil { + + if swag.IsZero(m.HTTPClientOptions) { // not required + return nil + } + if err := m.HTTPClientOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("http_client_options") @@ -1525,6 +1599,11 @@ func (m *GlobalBase) contextValidateHTTPErrCodes(ctx context.Context, formats st for i := 0; i < len(m.HTTPErrCodes); i++ { if m.HTTPErrCodes[i] != nil { + + if swag.IsZero(m.HTTPErrCodes[i]) { // not required + return nil + } + if err := m.HTTPErrCodes[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("http_err_codes" + "." + strconv.Itoa(i)) @@ -1545,6 +1624,11 @@ func (m *GlobalBase) contextValidateHTTPFailCodes(ctx context.Context, formats s for i := 0; i < len(m.HTTPFailCodes); i++ { if m.HTTPFailCodes[i] != nil { + + if swag.IsZero(m.HTTPFailCodes[i]) { // not required + return nil + } + if err := m.HTTPFailCodes[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("http_fail_codes" + "." + strconv.Itoa(i)) @@ -1563,6 +1647,11 @@ func (m *GlobalBase) contextValidateHTTPFailCodes(ctx context.Context, formats s func (m *GlobalBase) contextValidateLogSendHostname(ctx context.Context, formats strfmt.Registry) error { if m.LogSendHostname != nil { + + if swag.IsZero(m.LogSendHostname) { // not required + return nil + } + if err := m.LogSendHostname.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("log_send_hostname") @@ -1579,6 +1668,11 @@ func (m *GlobalBase) contextValidateLogSendHostname(ctx context.Context, formats func (m *GlobalBase) contextValidateLuaOptions(ctx context.Context, formats strfmt.Registry) error { if m.LuaOptions != nil { + + if swag.IsZero(m.LuaOptions) { // not required + return nil + } + if err := m.LuaOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("lua_options") @@ -1595,6 +1689,11 @@ func (m *GlobalBase) contextValidateLuaOptions(ctx context.Context, formats strf func (m *GlobalBase) contextValidateOcspUpdateOptions(ctx context.Context, formats strfmt.Registry) error { if m.OcspUpdateOptions != nil { + + if swag.IsZero(m.OcspUpdateOptions) { // not required + return nil + } + if err := m.OcspUpdateOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("ocsp_update_options") @@ -1611,6 +1710,11 @@ func (m *GlobalBase) contextValidateOcspUpdateOptions(ctx context.Context, forma func (m *GlobalBase) contextValidatePerformanceOptions(ctx context.Context, formats strfmt.Registry) error { if m.PerformanceOptions != nil { + + if swag.IsZero(m.PerformanceOptions) { // not required + return nil + } + if err := m.PerformanceOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("performance_options") @@ -1627,6 +1731,11 @@ func (m *GlobalBase) contextValidatePerformanceOptions(ctx context.Context, form func (m *GlobalBase) contextValidateSslOptions(ctx context.Context, formats strfmt.Registry) error { if m.SslOptions != nil { + + if swag.IsZero(m.SslOptions) { // not required + return nil + } + if err := m.SslOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("ssl_options") @@ -1643,6 +1752,11 @@ func (m *GlobalBase) contextValidateSslOptions(ctx context.Context, formats strf func (m *GlobalBase) contextValidateTuneBufferOptions(ctx context.Context, formats strfmt.Registry) error { if m.TuneBufferOptions != nil { + + if swag.IsZero(m.TuneBufferOptions) { // not required + return nil + } + if err := m.TuneBufferOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("tune_buffer_options") @@ -1659,6 +1773,11 @@ func (m *GlobalBase) contextValidateTuneBufferOptions(ctx context.Context, forma func (m *GlobalBase) contextValidateTuneLuaOptions(ctx context.Context, formats strfmt.Registry) error { if m.TuneLuaOptions != nil { + + if swag.IsZero(m.TuneLuaOptions) { // not required + return nil + } + if err := m.TuneLuaOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("tune_lua_options") @@ -1675,6 +1794,11 @@ func (m *GlobalBase) contextValidateTuneLuaOptions(ctx context.Context, formats func (m *GlobalBase) contextValidateTuneOptions(ctx context.Context, formats strfmt.Registry) error { if m.TuneOptions != nil { + + if swag.IsZero(m.TuneOptions) { // not required + return nil + } + if err := m.TuneOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("tune_options") @@ -1691,6 +1815,11 @@ func (m *GlobalBase) contextValidateTuneOptions(ctx context.Context, formats str func (m *GlobalBase) contextValidateTuneQuicOptions(ctx context.Context, formats strfmt.Registry) error { if m.TuneQuicOptions != nil { + + if swag.IsZero(m.TuneQuicOptions) { // not required + return nil + } + if err := m.TuneQuicOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("tune_quic_options") @@ -1707,6 +1836,11 @@ func (m *GlobalBase) contextValidateTuneQuicOptions(ctx context.Context, formats func (m *GlobalBase) contextValidateTuneSslOptions(ctx context.Context, formats strfmt.Registry) error { if m.TuneSslOptions != nil { + + if swag.IsZero(m.TuneSslOptions) { // not required + return nil + } + if err := m.TuneSslOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("tune_ssl_options") @@ -1723,6 +1857,11 @@ func (m *GlobalBase) contextValidateTuneSslOptions(ctx context.Context, formats func (m *GlobalBase) contextValidateTuneVarsOptions(ctx context.Context, formats strfmt.Registry) error { if m.TuneVarsOptions != nil { + + if swag.IsZero(m.TuneVarsOptions) { // not required + return nil + } + if err := m.TuneVarsOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("tune_vars_options") @@ -1739,6 +1878,11 @@ func (m *GlobalBase) contextValidateTuneVarsOptions(ctx context.Context, formats func (m *GlobalBase) contextValidateTuneZlibOptions(ctx context.Context, formats strfmt.Registry) error { if m.TuneZlibOptions != nil { + + if swag.IsZero(m.TuneZlibOptions) { // not required + return nil + } + if err := m.TuneZlibOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("tune_zlib_options") @@ -1755,6 +1899,11 @@ func (m *GlobalBase) contextValidateTuneZlibOptions(ctx context.Context, formats func (m *GlobalBase) contextValidateWurflOptions(ctx context.Context, formats strfmt.Registry) error { if m.WurflOptions != nil { + + if swag.IsZero(m.WurflOptions) { // not required + return nil + } + if err := m.WurflOptions.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("wurfl_options") @@ -1870,7 +2019,7 @@ type GlobalDefaultPath struct { // type // Required: true - // Enum: [current config parent origin] + // Enum: ["current","config","parent","origin"] // +kubebuilder:validation:Enum=current;config;parent;origin; Type string `json:"type"` } @@ -2109,6 +2258,11 @@ func (m *GlobalHarden) ContextValidate(ctx context.Context, formats strfmt.Regis func (m *GlobalHarden) contextValidateRejectPrivilegedPorts(ctx context.Context, formats strfmt.Registry) error { if m.RejectPrivilegedPorts != nil { + + if swag.IsZero(m.RejectPrivilegedPorts) { // not required + return nil + } + if err := m.RejectPrivilegedPorts.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("harden" + "." + "reject_privileged_ports") @@ -2145,12 +2299,12 @@ func (m *GlobalHarden) UnmarshalBinary(b []byte) error { // swagger:model GlobalHardenRejectPrivilegedPorts type GlobalHardenRejectPrivilegedPorts struct { // quic - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Quic string `json:"quic,omitempty"` // tcp - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; TCP string `json:"tcp,omitempty"` } @@ -2286,7 +2440,7 @@ func (m *GlobalHardenRejectPrivilegedPorts) UnmarshalBinary(b []byte) error { type GlobalLogSendHostname struct { // enabled // Required: true - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Enabled *string `json:"enabled"` diff --git a/models/global_base_compare.go b/models/global_base_compare.go index 82ed1490..ef9a07ea 100644 --- a/models/global_base_compare.go +++ b/models/global_base_compare.go @@ -247,10 +247,18 @@ func (s GlobalBase) Equal(t GlobalBase, opts ...Options) bool { return false } + if s.H1AcceptPayloadWithAnyMethod != t.H1AcceptPayloadWithAnyMethod { + return false + } + if s.H1CaseAdjustFile != t.H1CaseAdjustFile { return false } + if s.H1DoNotCloseOnInsecureTransferEncoding != t.H1DoNotCloseOnInsecureTransferEncoding { + return false + } + if s.H2WorkaroundBogusWebsocketClients != t.H2WorkaroundBogusWebsocketClients { return false } @@ -493,6 +501,10 @@ func (s GlobalBase) Equal(t GlobalBase, opts ...Options) bool { return false } + if s.StatsFile != t.StatsFile { + return false + } + if !equalPointers(s.StatsMaxconn, t.StatsMaxconn) { return false } @@ -969,10 +981,18 @@ func (s GlobalBase) Diff(t GlobalBase, opts ...Options) map[string][]interface{} diff["Group"] = []interface{}{s.Group, t.Group} } + if s.H1AcceptPayloadWithAnyMethod != t.H1AcceptPayloadWithAnyMethod { + diff["H1AcceptPayloadWithAnyMethod"] = []interface{}{s.H1AcceptPayloadWithAnyMethod, t.H1AcceptPayloadWithAnyMethod} + } + if s.H1CaseAdjustFile != t.H1CaseAdjustFile { diff["H1CaseAdjustFile"] = []interface{}{s.H1CaseAdjustFile, t.H1CaseAdjustFile} } + if s.H1DoNotCloseOnInsecureTransferEncoding != t.H1DoNotCloseOnInsecureTransferEncoding { + diff["H1DoNotCloseOnInsecureTransferEncoding"] = []interface{}{s.H1DoNotCloseOnInsecureTransferEncoding, t.H1DoNotCloseOnInsecureTransferEncoding} + } + if s.H2WorkaroundBogusWebsocketClients != t.H2WorkaroundBogusWebsocketClients { diff["H2WorkaroundBogusWebsocketClients"] = []interface{}{s.H2WorkaroundBogusWebsocketClients, t.H2WorkaroundBogusWebsocketClients} } @@ -1229,6 +1249,10 @@ func (s GlobalBase) Diff(t GlobalBase, opts ...Options) map[string][]interface{} diff["SslOptions"] = []interface{}{ValueOrNil(s.SslOptions), ValueOrNil(t.SslOptions)} } + if s.StatsFile != t.StatsFile { + diff["StatsFile"] = []interface{}{s.StatsFile, t.StatsFile} + } + if !equalPointers(s.StatsMaxconn, t.StatsMaxconn) { diff["StatsMaxconn"] = []interface{}{ValueOrNil(s.StatsMaxconn), ValueOrNil(t.StatsMaxconn)} } diff --git a/models/global_base_compare_test.go b/models/global_base_compare_test.go index c371109c..a3a510fc 100644 --- a/models/global_base_compare_test.go +++ b/models/global_base_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestGlobalBaseEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalBase var result GlobalBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestGlobalBaseEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalBase to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestGlobalBaseEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalBase var result GlobalBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CloseSpreadTime = Ptr(*sample.CloseSpreadTime + 1) result.Daemon = !sample.Daemon @@ -89,6 +92,8 @@ func TestGlobalBaseEqualFalse(t *testing.T) { result.ExternalCheck = !sample.ExternalCheck result.Gid = sample.Gid + 1 result.Grace = Ptr(*sample.Grace + 1) + result.H1AcceptPayloadWithAnyMethod = !sample.H1AcceptPayloadWithAnyMethod + result.H1DoNotCloseOnInsecureTransferEncoding = !sample.H1DoNotCloseOnInsecureTransferEncoding result.H2WorkaroundBogusWebsocketClients = !sample.H2WorkaroundBogusWebsocketClients result.HardStopAfter = Ptr(*sample.HardStopAfter + 1) result.InsecureForkWanted = !sample.InsecureForkWanted @@ -118,11 +123,11 @@ func TestGlobalBaseEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalBase to be different, but it is not %s %s", a, b) } @@ -136,17 +141,17 @@ func TestGlobalBaseDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalBase var result GlobalBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -160,11 +165,11 @@ func TestGlobalBaseDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalBase to be equal, but it is not %s %s, %v", a, b, result) } @@ -178,13 +183,13 @@ func TestGlobalBaseDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalBase var result GlobalBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CloseSpreadTime = Ptr(*sample.CloseSpreadTime + 1) result.Daemon = !sample.Daemon @@ -192,6 +197,8 @@ func TestGlobalBaseDiffFalse(t *testing.T) { result.ExternalCheck = !sample.ExternalCheck result.Gid = sample.Gid + 1 result.Grace = Ptr(*sample.Grace + 1) + result.H1AcceptPayloadWithAnyMethod = !sample.H1AcceptPayloadWithAnyMethod + result.H1DoNotCloseOnInsecureTransferEncoding = !sample.H1DoNotCloseOnInsecureTransferEncoding result.H2WorkaroundBogusWebsocketClients = !sample.H2WorkaroundBogusWebsocketClients result.HardStopAfter = Ptr(*sample.HardStopAfter + 1) result.InsecureForkWanted = !sample.InsecureForkWanted @@ -217,17 +224,17 @@ func TestGlobalBaseDiffFalse(t *testing.T) { for _, sample := range samples { result := sample.a.Diff(sample.b) - if len(result) != 63 { + if len(result) != 66 { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - t.Errorf("Expected GlobalBase to be different in 63 cases, but it is not (%d) %s %s", len(result), a, b) + t.Errorf("Expected GlobalBase to be different in 66 cases, but it is not (%d) %s %s", len(result), a, b) } } } @@ -239,17 +246,17 @@ func TestCPUMapEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample CPUMap var result CPUMap - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -263,11 +270,11 @@ func TestCPUMapEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected CPUMap to be equal, but it is not %s %s", a, b) } @@ -281,13 +288,13 @@ func TestCPUMapEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample CPUMap var result CPUMap - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b CPUMap @@ -300,11 +307,11 @@ func TestCPUMapEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected CPUMap to be different, but it is not %s %s", a, b) } @@ -318,17 +325,17 @@ func TestCPUMapDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample CPUMap var result CPUMap - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -342,11 +349,11 @@ func TestCPUMapDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected CPUMap to be equal, but it is not %s %s, %v", a, b, result) } @@ -360,13 +367,13 @@ func TestCPUMapDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample CPUMap var result CPUMap - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b CPUMap @@ -379,11 +386,11 @@ func TestCPUMapDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected CPUMap to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -397,17 +404,17 @@ func TestGlobalDefaultPathEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalDefaultPath var result GlobalDefaultPath - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -421,11 +428,11 @@ func TestGlobalDefaultPathEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalDefaultPath to be equal, but it is not %s %s", a, b) } @@ -439,13 +446,13 @@ func TestGlobalDefaultPathEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalDefaultPath var result GlobalDefaultPath - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b GlobalDefaultPath @@ -458,11 +465,11 @@ func TestGlobalDefaultPathEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalDefaultPath to be different, but it is not %s %s", a, b) } @@ -476,17 +483,17 @@ func TestGlobalDefaultPathDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalDefaultPath var result GlobalDefaultPath - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -500,11 +507,11 @@ func TestGlobalDefaultPathDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalDefaultPath to be equal, but it is not %s %s, %v", a, b, result) } @@ -518,13 +525,13 @@ func TestGlobalDefaultPathDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalDefaultPath var result GlobalDefaultPath - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b GlobalDefaultPath @@ -537,11 +544,11 @@ func TestGlobalDefaultPathDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalDefaultPath to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -555,17 +562,17 @@ func TestH1CaseAdjustEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample H1CaseAdjust var result H1CaseAdjust - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -579,11 +586,11 @@ func TestH1CaseAdjustEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected H1CaseAdjust to be equal, but it is not %s %s", a, b) } @@ -597,13 +604,13 @@ func TestH1CaseAdjustEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample H1CaseAdjust var result H1CaseAdjust - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b H1CaseAdjust @@ -616,11 +623,11 @@ func TestH1CaseAdjustEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected H1CaseAdjust to be different, but it is not %s %s", a, b) } @@ -634,17 +641,17 @@ func TestH1CaseAdjustDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample H1CaseAdjust var result H1CaseAdjust - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -658,11 +665,11 @@ func TestH1CaseAdjustDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected H1CaseAdjust to be equal, but it is not %s %s, %v", a, b, result) } @@ -676,13 +683,13 @@ func TestH1CaseAdjustDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample H1CaseAdjust var result H1CaseAdjust - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b H1CaseAdjust @@ -695,11 +702,11 @@ func TestH1CaseAdjustDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected H1CaseAdjust to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -713,17 +720,17 @@ func TestGlobalHardenEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalHarden var result GlobalHarden - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -737,11 +744,11 @@ func TestGlobalHardenEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalHarden to be equal, but it is not %s %s", a, b) } @@ -755,13 +762,13 @@ func TestGlobalHardenEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalHarden var result GlobalHarden - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b GlobalHarden @@ -774,11 +781,11 @@ func TestGlobalHardenEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalHarden to be different, but it is not %s %s", a, b) } @@ -792,17 +799,17 @@ func TestGlobalHardenDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalHarden var result GlobalHarden - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -816,11 +823,11 @@ func TestGlobalHardenDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalHarden to be equal, but it is not %s %s, %v", a, b, result) } @@ -834,13 +841,13 @@ func TestGlobalHardenDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalHarden var result GlobalHarden - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b GlobalHarden @@ -853,11 +860,11 @@ func TestGlobalHardenDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalHarden to be different in 1 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -871,17 +878,17 @@ func TestGlobalHardenRejectPrivilegedPortsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalHardenRejectPrivilegedPorts var result GlobalHardenRejectPrivilegedPorts - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -895,11 +902,11 @@ func TestGlobalHardenRejectPrivilegedPortsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalHardenRejectPrivilegedPorts to be equal, but it is not %s %s", a, b) } @@ -913,13 +920,13 @@ func TestGlobalHardenRejectPrivilegedPortsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalHardenRejectPrivilegedPorts var result GlobalHardenRejectPrivilegedPorts - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b GlobalHardenRejectPrivilegedPorts @@ -932,11 +939,11 @@ func TestGlobalHardenRejectPrivilegedPortsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalHardenRejectPrivilegedPorts to be different, but it is not %s %s", a, b) } @@ -950,17 +957,17 @@ func TestGlobalHardenRejectPrivilegedPortsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalHardenRejectPrivilegedPorts var result GlobalHardenRejectPrivilegedPorts - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -974,11 +981,11 @@ func TestGlobalHardenRejectPrivilegedPortsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalHardenRejectPrivilegedPorts to be equal, but it is not %s %s, %v", a, b, result) } @@ -992,13 +999,13 @@ func TestGlobalHardenRejectPrivilegedPortsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalHardenRejectPrivilegedPorts var result GlobalHardenRejectPrivilegedPorts - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b GlobalHardenRejectPrivilegedPorts @@ -1011,11 +1018,11 @@ func TestGlobalHardenRejectPrivilegedPortsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalHardenRejectPrivilegedPorts to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -1029,17 +1036,17 @@ func TestGlobalLogSendHostnameEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalLogSendHostname var result GlobalLogSendHostname - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -1053,11 +1060,11 @@ func TestGlobalLogSendHostnameEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalLogSendHostname to be equal, but it is not %s %s", a, b) } @@ -1071,13 +1078,13 @@ func TestGlobalLogSendHostnameEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalLogSendHostname var result GlobalLogSendHostname - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b GlobalLogSendHostname @@ -1090,11 +1097,11 @@ func TestGlobalLogSendHostnameEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalLogSendHostname to be different, but it is not %s %s", a, b) } @@ -1108,17 +1115,17 @@ func TestGlobalLogSendHostnameDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalLogSendHostname var result GlobalLogSendHostname - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -1132,11 +1139,11 @@ func TestGlobalLogSendHostnameDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalLogSendHostname to be equal, but it is not %s %s, %v", a, b, result) } @@ -1150,13 +1157,13 @@ func TestGlobalLogSendHostnameDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample GlobalLogSendHostname var result GlobalLogSendHostname - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b GlobalLogSendHostname @@ -1169,11 +1176,11 @@ func TestGlobalLogSendHostnameDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected GlobalLogSendHostname to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -1187,17 +1194,17 @@ func TestRuntimeAPIEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample RuntimeAPI var result RuntimeAPI - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -1211,11 +1218,11 @@ func TestRuntimeAPIEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RuntimeAPI to be equal, but it is not %s %s", a, b) } @@ -1229,13 +1236,13 @@ func TestRuntimeAPIEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample RuntimeAPI var result RuntimeAPI - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b RuntimeAPI @@ -1248,11 +1255,11 @@ func TestRuntimeAPIEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RuntimeAPI to be different, but it is not %s %s", a, b) } @@ -1266,17 +1273,17 @@ func TestRuntimeAPIDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample RuntimeAPI var result RuntimeAPI - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -1290,11 +1297,11 @@ func TestRuntimeAPIDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RuntimeAPI to be equal, but it is not %s %s, %v", a, b, result) } @@ -1308,13 +1315,13 @@ func TestRuntimeAPIDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample RuntimeAPI var result RuntimeAPI - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b RuntimeAPI @@ -1327,11 +1334,11 @@ func TestRuntimeAPIDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RuntimeAPI to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -1345,17 +1352,17 @@ func TestSetVarFmtEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SetVarFmt var result SetVarFmt - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -1369,11 +1376,11 @@ func TestSetVarFmtEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SetVarFmt to be equal, but it is not %s %s", a, b) } @@ -1387,13 +1394,13 @@ func TestSetVarFmtEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SetVarFmt var result SetVarFmt - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SetVarFmt @@ -1406,11 +1413,11 @@ func TestSetVarFmtEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SetVarFmt to be different, but it is not %s %s", a, b) } @@ -1424,17 +1431,17 @@ func TestSetVarFmtDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SetVarFmt var result SetVarFmt - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -1448,11 +1455,11 @@ func TestSetVarFmtDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SetVarFmt to be equal, but it is not %s %s, %v", a, b, result) } @@ -1466,13 +1473,13 @@ func TestSetVarFmtDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SetVarFmt var result SetVarFmt - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SetVarFmt @@ -1485,11 +1492,11 @@ func TestSetVarFmtDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SetVarFmt to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -1503,17 +1510,17 @@ func TestSetVarEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SetVar var result SetVar - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -1527,11 +1534,11 @@ func TestSetVarEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SetVar to be equal, but it is not %s %s", a, b) } @@ -1545,13 +1552,13 @@ func TestSetVarEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SetVar var result SetVar - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SetVar @@ -1564,11 +1571,11 @@ func TestSetVarEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SetVar to be different, but it is not %s %s", a, b) } @@ -1582,17 +1589,17 @@ func TestSetVarDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SetVar var result SetVar - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -1606,11 +1613,11 @@ func TestSetVarDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SetVar to be equal, but it is not %s %s, %v", a, b, result) } @@ -1624,13 +1631,13 @@ func TestSetVarDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SetVar var result SetVar - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SetVar @@ -1643,11 +1650,11 @@ func TestSetVarDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SetVar to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -1661,17 +1668,17 @@ func TestThreadGroupEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ThreadGroup var result ThreadGroup - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -1685,11 +1692,11 @@ func TestThreadGroupEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ThreadGroup to be equal, but it is not %s %s", a, b) } @@ -1703,13 +1710,13 @@ func TestThreadGroupEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ThreadGroup var result ThreadGroup - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ThreadGroup @@ -1722,11 +1729,11 @@ func TestThreadGroupEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ThreadGroup to be different, but it is not %s %s", a, b) } @@ -1740,17 +1747,17 @@ func TestThreadGroupDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ThreadGroup var result ThreadGroup - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -1764,11 +1771,11 @@ func TestThreadGroupDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ThreadGroup to be equal, but it is not %s %s, %v", a, b, result) } @@ -1782,13 +1789,13 @@ func TestThreadGroupDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ThreadGroup var result ThreadGroup - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ThreadGroup @@ -1801,11 +1808,11 @@ func TestThreadGroupDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ThreadGroup to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/global_compare_test.go b/models/global_compare_test.go index 3bbd7f87..7c616147 100644 --- a/models/global_compare_test.go +++ b/models/global_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestGlobalEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Global var result Global - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestGlobalEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Global to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestGlobalEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Global var result Global - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Global @@ -94,11 +97,11 @@ func TestGlobalEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Global to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestGlobalDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Global var result Global - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestGlobalDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Global to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestGlobalDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Global var result Global - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Global @@ -173,11 +176,11 @@ func TestGlobalDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Global to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/group_compare_test.go b/models/group_compare_test.go index acd1add5..f0488363 100644 --- a/models/group_compare_test.go +++ b/models/group_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestGroupEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Group var result Group - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestGroupEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Group to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestGroupEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Group var result Group - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Group @@ -94,11 +97,11 @@ func TestGroupEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Group to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestGroupDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Group var result Group - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestGroupDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Group to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestGroupDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Group var result Group - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Group @@ -173,11 +176,11 @@ func TestGroupDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Group to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/groups.go b/models/groups.go index a2371e5d..2d5610ba 100644 --- a/models/groups.go +++ b/models/groups.go @@ -71,6 +71,11 @@ func (m Groups) ContextValidate(ctx context.Context, formats strfmt.Registry) er for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/hash_type.go b/models/hash_type.go index b07f0181..947cb6ec 100644 --- a/models/hash_type.go +++ b/models/hash_type.go @@ -35,17 +35,17 @@ import ( // swagger:model hash_type type HashType struct { // function - // Enum: [sdbm djb2 wt6 crc32 none] + // Enum: ["sdbm","djb2","wt6","crc32","none"] // +kubebuilder:validation:Enum=sdbm;djb2;wt6;crc32;none; Function string `json:"function,omitempty"` // method - // Enum: [map-based consistent] + // Enum: ["map-based","consistent"] // +kubebuilder:validation:Enum=map-based;consistent; Method string `json:"method,omitempty"` // modifier - // Enum: [avalanche] + // Enum: ["avalanche"] // +kubebuilder:validation:Enum=avalanche; Modifier string `json:"modifier,omitempty"` } diff --git a/models/hash_type_compare_test.go b/models/hash_type_compare_test.go index 06613b38..a7593c9f 100644 --- a/models/hash_type_compare_test.go +++ b/models/hash_type_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestHashTypeEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample HashType var result HashType - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestHashTypeEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HashType to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestHashTypeEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HashType var result HashType - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b HashType @@ -94,11 +97,11 @@ func TestHashTypeEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HashType to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestHashTypeDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample HashType var result HashType - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestHashTypeDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HashType to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestHashTypeDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HashType var result HashType - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b HashType @@ -173,11 +176,11 @@ func TestHashTypeDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HashType to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/health.go b/models/health.go index 2b36b6b9..5ed0fd62 100644 --- a/models/health.go +++ b/models/health.go @@ -35,7 +35,7 @@ import ( // swagger:model health type Health struct { // haproxy - // Enum: [up down unknown] + // Enum: ["up","down","unknown"] // +kubebuilder:validation:Enum=up;down;unknown; Haproxy string `json:"haproxy,omitempty"` } diff --git a/models/health_compare_test.go b/models/health_compare_test.go index cbd077ba..0cf2673c 100644 --- a/models/health_compare_test.go +++ b/models/health_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestHealthEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Health var result Health - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestHealthEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Health to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestHealthEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Health var result Health - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Health @@ -94,11 +97,11 @@ func TestHealthEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Health to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestHealthDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Health var result Health - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestHealthDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Health to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestHealthDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Health var result Health - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Health @@ -173,11 +176,11 @@ func TestHealthDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Health to be different in 1 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/http_after_response_rule.go b/models/http_after_response_rule.go index 2912fd2f..dd1495f3 100644 --- a/models/http_after_response_rule.go +++ b/models/http_after_response_rule.go @@ -54,12 +54,12 @@ type HTTPAfterResponseRule struct { CaptureLen int64 `json:"capture_len,omitempty"` // capture sample - // Pattern: ^[^\s]+$ - // +kubebuilder:validation:Pattern=`^[^\s]+$` + // Pattern: ^(?:[A-Za-z]+\("([A-Za-z\s]+)"\)|[A-Za-z]+) + // +kubebuilder:validation:Pattern=`^(?:[A-Za-z]+\("([A-Za-z\s]+)"\)|[A-Za-z]+)` CaptureSample string `json:"capture_sample,omitempty"` // cond - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond string `json:"cond,omitempty"` @@ -79,7 +79,7 @@ type HTTPAfterResponseRule struct { HdrName string `json:"hdr_name,omitempty"` // log level - // Enum: [emerg alert crit err warning notice info debug silent] + // Enum: ["emerg","alert","crit","err","warning","notice","info","debug","silent"] // +kubebuilder:validation:Enum=emerg;alert;crit;err;warning;notice;info;debug;silent; LogLevel string `json:"log_level,omitempty"` @@ -121,13 +121,13 @@ type HTTPAfterResponseRule struct { StatusReason string `json:"status_reason,omitempty"` // strict mode - // Enum: [on off] + // Enum: ["on","off"] // +kubebuilder:validation:Enum=on;off; StrictMode string `json:"strict_mode,omitempty"` // type // Required: true - // Enum: [add-header allow capture del-acl del-header del-map replace-header replace-value sc-add-gpc sc-inc-gpc sc-inc-gpc0 sc-inc-gpc1 sc-set-gpt sc-set-gpt0 set-header set-log-level set-map set-status set-var set-var-fmt strict-mode unset-var] + // Enum: ["add-header","allow","capture","del-acl","del-header","del-map","replace-header","replace-value","sc-add-gpc","sc-inc-gpc","sc-inc-gpc0","sc-inc-gpc1","sc-set-gpt","sc-set-gpt0","set-header","set-log-level","set-map","set-status","set-var","set-var-fmt","strict-mode","unset-var"] // +kubebuilder:validation:Enum=add-header;allow;capture;del-acl;del-header;del-map;replace-header;replace-value;sc-add-gpc;sc-inc-gpc;sc-inc-gpc0;sc-inc-gpc1;sc-set-gpt;sc-set-gpt0;set-header;set-log-level;set-map;set-status;set-var;set-var-fmt;strict-mode;unset-var; Type string `json:"type"` @@ -239,7 +239,7 @@ func (m *HTTPAfterResponseRule) validateCaptureSample(formats strfmt.Registry) e return nil } - if err := validate.Pattern("capture_sample", "body", m.CaptureSample, `^[^\s]+$`); err != nil { + if err := validate.Pattern("capture_sample", "body", m.CaptureSample, `^(?:[A-Za-z]+\("([A-Za-z\s]+)"\)|[A-Za-z]+)`); err != nil { return err } diff --git a/models/http_after_response_rule_compare_test.go b/models/http_after_response_rule_compare_test.go index b23a1114..9d9be7a4 100644 --- a/models/http_after_response_rule_compare_test.go +++ b/models/http_after_response_rule_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestHTTPAfterResponseRuleEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPAfterResponseRule var result HTTPAfterResponseRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestHTTPAfterResponseRuleEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPAfterResponseRule to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestHTTPAfterResponseRuleEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPAfterResponseRule var result HTTPAfterResponseRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CaptureID = Ptr(*sample.CaptureID + 1) result.CaptureLen = sample.CaptureLen + 1 @@ -100,11 +103,11 @@ func TestHTTPAfterResponseRuleEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPAfterResponseRule to be different, but it is not %s %s", a, b) } @@ -118,17 +121,17 @@ func TestHTTPAfterResponseRuleDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPAfterResponseRule var result HTTPAfterResponseRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -142,11 +145,11 @@ func TestHTTPAfterResponseRuleDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPAfterResponseRule to be equal, but it is not %s %s, %v", a, b, result) } @@ -160,13 +163,13 @@ func TestHTTPAfterResponseRuleDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPAfterResponseRule var result HTTPAfterResponseRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CaptureID = Ptr(*sample.CaptureID + 1) result.CaptureLen = sample.CaptureLen + 1 @@ -185,11 +188,11 @@ func TestHTTPAfterResponseRuleDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPAfterResponseRule to be different in 27 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/http_after_response_rules.go b/models/http_after_response_rules.go index 74e72caa..1f95bb34 100644 --- a/models/http_after_response_rules.go +++ b/models/http_after_response_rules.go @@ -71,6 +71,11 @@ func (m HTTPAfterResponseRules) ContextValidate(ctx context.Context, formats str for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/http_check.go b/models/http_check.go index 4e2ca175..50128b23 100644 --- a/models/http_check.go +++ b/models/http_check.go @@ -62,7 +62,7 @@ type HTTPCheck struct { Default bool `json:"default,omitempty"` // error status - // Enum: [L7OKC L7RSP L7STS L6RSP L4CON] + // Enum: ["L7OKC","L7RSP","L7STS","L6RSP","L4CON"] // +kubebuilder:validation:Enum=L7OKC;L7RSP;L7STS;L6RSP;L4CON; ErrorStatus string `json:"error_status,omitempty"` @@ -74,13 +74,13 @@ type HTTPCheck struct { // match // Pattern: ^[^\s]+$ - // Enum: [status rstatus hdr fhdr string rstring] + // Enum: ["status","rstatus","hdr","fhdr","string","rstring"] // +kubebuilder:validation:Pattern=`^[^\s]+$` // +kubebuilder:validation:Enum=status;rstatus;hdr;fhdr;string;rstring; Match string `json:"match,omitempty"` // method - // Enum: [HEAD PUT POST GET TRACE PATCH DELETE CONNECT OPTIONS] + // Enum: ["HEAD","PUT","POST","GET","TRACE","PATCH","DELETE","CONNECT","OPTIONS"] // +kubebuilder:validation:Enum=HEAD;PUT;POST;GET;TRACE;PATCH;DELETE;CONNECT;OPTIONS; Method string `json:"method,omitempty"` @@ -88,7 +88,7 @@ type HTTPCheck struct { MinRecv *int64 `json:"min_recv,omitempty"` // ok status - // Enum: [L7OK L7OKC L6OK L4OK] + // Enum: ["L7OK","L7OKC","L6OK","L4OK"] // +kubebuilder:validation:Enum=L7OK;L7OKC;L6OK;L4OK; OkStatus string `json:"ok_status,omitempty"` @@ -127,13 +127,13 @@ type HTTPCheck struct { StatusCode string `json:"status-code,omitempty"` // tout status - // Enum: [L7TOUT L6TOUT L4TOUT] + // Enum: ["L7TOUT","L6TOUT","L4TOUT"] // +kubebuilder:validation:Enum=L7TOUT;L6TOUT;L4TOUT; ToutStatus string `json:"tout_status,omitempty"` // type // Required: true - // Enum: [comment connect disable-on-404 expect send send-state set-var set-var-fmt unset-var] + // Enum: ["comment","connect","disable-on-404","expect","send","send-state","set-var","set-var-fmt","unset-var"] // +kubebuilder:validation:Enum=comment;connect;disable-on-404;expect;send;send-state;set-var;set-var-fmt;unset-var; Type string `json:"type"` @@ -662,6 +662,11 @@ func (m *HTTPCheck) contextValidateCheckHeaders(ctx context.Context, formats str for i := 0; i < len(m.CheckHeaders); i++ { if m.CheckHeaders[i] != nil { + + if swag.IsZero(m.CheckHeaders[i]) { // not required + return nil + } + if err := m.CheckHeaders[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("headers" + "." + strconv.Itoa(i)) diff --git a/models/http_check_compare_test.go b/models/http_check_compare_test.go index ffac1bdb..56609b99 100644 --- a/models/http_check_compare_test.go +++ b/models/http_check_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestHTTPCheckEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPCheck var result HTTPCheck - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestHTTPCheckEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPCheck to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestHTTPCheckEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPCheck var result HTTPCheck - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Default = !sample.Default result.ExclamationMark = !sample.ExclamationMark @@ -102,11 +105,11 @@ func TestHTTPCheckEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPCheck to be different, but it is not %s %s", a, b) } @@ -120,17 +123,17 @@ func TestHTTPCheckDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPCheck var result HTTPCheck - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -144,11 +147,11 @@ func TestHTTPCheckDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPCheck to be equal, but it is not %s %s, %v", a, b, result) } @@ -162,13 +165,13 @@ func TestHTTPCheckDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPCheck var result HTTPCheck - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Default = !sample.Default result.ExclamationMark = !sample.ExclamationMark @@ -189,11 +192,11 @@ func TestHTTPCheckDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPCheck to be different in 34 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/http_checks.go b/models/http_checks.go index 5265de6c..cad1c352 100644 --- a/models/http_checks.go +++ b/models/http_checks.go @@ -69,6 +69,11 @@ func (m HTTPChecks) ContextValidate(ctx context.Context, formats strfmt.Registry for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/http_client_options.go b/models/http_client_options.go index 1d1023b6..99c00bd3 100644 --- a/models/http_client_options.go +++ b/models/http_client_options.go @@ -35,7 +35,7 @@ import ( // swagger:model http_client_options type HTTPClientOptions struct { // resolvers disabled - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ResolversDisabled string `json:"resolvers_disabled,omitempty"` @@ -43,7 +43,7 @@ type HTTPClientOptions struct { ResolversID string `json:"resolvers_id,omitempty"` // resolvers prefer - // Enum: [ipv4 ipv6] + // Enum: ["ipv4","ipv6"] // +kubebuilder:validation:Enum=ipv4;ipv6; ResolversPrefer string `json:"resolvers_prefer,omitempty"` @@ -54,7 +54,7 @@ type HTTPClientOptions struct { SslCaFile string `json:"ssl_ca_file,omitempty"` // ssl verify - // Enum: [ none required] + // Enum: ["","none","required"] // +kubebuilder:validation:Enum="";none;required; SslVerify *string `json:"ssl_verify,omitempty"` diff --git a/models/http_client_options_compare_test.go b/models/http_client_options_compare_test.go index 4cf7ed24..d741fee1 100644 --- a/models/http_client_options_compare_test.go +++ b/models/http_client_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestHTTPClientOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPClientOptions var result HTTPClientOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestHTTPClientOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPClientOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestHTTPClientOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPClientOptions var result HTTPClientOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Retries = sample.Retries + 1 result.TimeoutConnect = Ptr(*sample.TimeoutConnect + 1) @@ -96,11 +99,11 @@ func TestHTTPClientOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPClientOptions to be different, but it is not %s %s", a, b) } @@ -114,17 +117,17 @@ func TestHTTPClientOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPClientOptions var result HTTPClientOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -138,11 +141,11 @@ func TestHTTPClientOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPClientOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -156,13 +159,13 @@ func TestHTTPClientOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPClientOptions var result HTTPClientOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Retries = sample.Retries + 1 result.TimeoutConnect = Ptr(*sample.TimeoutConnect + 1) @@ -177,11 +180,11 @@ func TestHTTPClientOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPClientOptions to be different in 7 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/http_codes_compare_test.go b/models/http_codes_compare_test.go index 6214f685..88443a08 100644 --- a/models/http_codes_compare_test.go +++ b/models/http_codes_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestHTTPCodesEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPCodes var result HTTPCodes - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestHTTPCodesEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPCodes to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestHTTPCodesEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPCodes var result HTTPCodes - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b HTTPCodes @@ -94,11 +97,11 @@ func TestHTTPCodesEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPCodes to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestHTTPCodesDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPCodes var result HTTPCodes - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestHTTPCodesDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPCodes to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestHTTPCodesDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPCodes var result HTTPCodes - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b HTTPCodes @@ -173,11 +176,11 @@ func TestHTTPCodesDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPCodes to be different in 1 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/http_error_rule.go b/models/http_error_rule.go index 8722320c..c424ff13 100644 --- a/models/http_error_rule.go +++ b/models/http_error_rule.go @@ -46,7 +46,7 @@ type HTTPErrorRule struct { ReturnContent string `json:"return_content,omitempty"` // return content format - // Enum: [default-errorfiles errorfile errorfiles file lf-file string lf-string] + // Enum: ["default-errorfiles","errorfile","errorfiles","file","lf-file","string","lf-string"] // +kubebuilder:validation:Enum=default-errorfiles;errorfile;errorfiles;file;lf-file;string;lf-string; ReturnContentFormat string `json:"return_content_format,omitempty"` @@ -55,13 +55,13 @@ type HTTPErrorRule struct { // status // Required: true - // Enum: [200 400 401 403 404 405 407 408 410 413 425 429 500 501 502 503 504] + // Enum: [200,400,401,403,404,405,407,408,410,413,425,429,500,501,502,503,504] // +kubebuilder:validation:Enum=200;400;401;403;404;405;407;408;410;413;425;429;500;501;502;503;504; Status int64 `json:"status"` // type // Required: true - // Enum: [status] + // Enum: ["status"] // +kubebuilder:validation:Enum=status; Type string `json:"type"` } @@ -268,6 +268,11 @@ func (m *HTTPErrorRule) contextValidateReturnHeaders(ctx context.Context, format for i := 0; i < len(m.ReturnHeaders); i++ { if m.ReturnHeaders[i] != nil { + + if swag.IsZero(m.ReturnHeaders[i]) { // not required + return nil + } + if err := m.ReturnHeaders[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("return_hdrs" + "." + strconv.Itoa(i)) diff --git a/models/http_error_rule_compare_test.go b/models/http_error_rule_compare_test.go index 42c27859..7c9e5130 100644 --- a/models/http_error_rule_compare_test.go +++ b/models/http_error_rule_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestHTTPErrorRuleEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPErrorRule var result HTTPErrorRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestHTTPErrorRuleEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPErrorRule to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestHTTPErrorRuleEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPErrorRule var result HTTPErrorRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Status = sample.Status + 1 samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestHTTPErrorRuleEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPErrorRule to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestHTTPErrorRuleDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPErrorRule var result HTTPErrorRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestHTTPErrorRuleDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPErrorRule to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestHTTPErrorRuleDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPErrorRule var result HTTPErrorRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Status = sample.Status + 1 samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestHTTPErrorRuleDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPErrorRule to be different in 6 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/http_error_rules.go b/models/http_error_rules.go index ad305413..3e5c0e3f 100644 --- a/models/http_error_rules.go +++ b/models/http_error_rules.go @@ -71,6 +71,11 @@ func (m HTTPErrorRules) ContextValidate(ctx context.Context, formats strfmt.Regi for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/http_errors_section.go b/models/http_errors_section.go index 5f049055..3eb7c2da 100644 --- a/models/http_errors_section.go +++ b/models/http_errors_section.go @@ -126,6 +126,11 @@ func (m *HTTPErrorsSection) contextValidateErrorFiles(ctx context.Context, forma for i := 0; i < len(m.ErrorFiles); i++ { if m.ErrorFiles[i] != nil { + + if swag.IsZero(m.ErrorFiles[i]) { // not required + return nil + } + if err := m.ErrorFiles[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("error_files" + "." + strconv.Itoa(i)) diff --git a/models/http_errors_section_compare_test.go b/models/http_errors_section_compare_test.go index 9f8ad60e..7e4b4afb 100644 --- a/models/http_errors_section_compare_test.go +++ b/models/http_errors_section_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestHTTPErrorsSectionEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPErrorsSection var result HTTPErrorsSection - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestHTTPErrorsSectionEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPErrorsSection to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestHTTPErrorsSectionEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPErrorsSection var result HTTPErrorsSection - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b HTTPErrorsSection @@ -94,11 +97,11 @@ func TestHTTPErrorsSectionEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPErrorsSection to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestHTTPErrorsSectionDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPErrorsSection var result HTTPErrorsSection - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestHTTPErrorsSectionDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPErrorsSection to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestHTTPErrorsSectionDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPErrorsSection var result HTTPErrorsSection - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b HTTPErrorsSection @@ -173,11 +176,11 @@ func TestHTTPErrorsSectionDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPErrorsSection to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/http_errors_sections.go b/models/http_errors_sections.go index 603c6fe6..276c71f4 100644 --- a/models/http_errors_sections.go +++ b/models/http_errors_sections.go @@ -71,6 +71,11 @@ func (m HTTPErrorsSections) ContextValidate(ctx context.Context, formats strfmt. for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/http_request_rule.go b/models/http_request_rule.go index f3af0419..6c890f75 100644 --- a/models/http_request_rule.go +++ b/models/http_request_rule.go @@ -78,12 +78,12 @@ type HTTPRequestRule struct { CaptureLen int64 `json:"capture_len,omitempty"` // capture sample - // Pattern: ^[^\s]+$ - // +kubebuilder:validation:Pattern=`^[^\s]+$` + // Pattern: ^(?:[A-Za-z]+\("([A-Za-z\s]+)"\)|[A-Za-z]+) + // +kubebuilder:validation:Pattern=`^(?:[A-Za-z]+\("([A-Za-z\s]+)"\)|[A-Za-z]+)` CaptureSample string `json:"capture_sample,omitempty"` // cond - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond string `json:"cond,omitempty"` @@ -123,7 +123,7 @@ type HTTPRequestRule struct { HintName string `json:"hint_name,omitempty"` // log level - // Enum: [emerg alert crit err warning notice info debug silent] + // Enum: ["emerg","alert","crit","err","warning","notice","info","debug","silent"] // +kubebuilder:validation:Enum=emerg;alert;crit;err;warning;notice;info;debug;silent; LogLevel string `json:"log_level,omitempty"` @@ -168,7 +168,7 @@ type HTTPRequestRule struct { NiceValue int64 `json:"nice_value,omitempty"` // normalizer - // Enum: [fragment-encode fragment-strip path-merge-slashes path-strip-dot path-strip-dotdot percent-decode-unreserved percent-to-uppercase query-sort-by-name] + // Enum: ["fragment-encode","fragment-strip","path-merge-slashes","path-strip-dot","path-strip-dotdot","percent-decode-unreserved","percent-to-uppercase","query-sort-by-name"] // +kubebuilder:validation:Enum=fragment-encode;fragment-strip;path-merge-slashes;path-strip-dot;path-strip-dotdot;percent-decode-unreserved;percent-to-uppercase;query-sort-by-name; Normalizer string `json:"normalizer,omitempty"` @@ -189,7 +189,7 @@ type HTTPRequestRule struct { PathMatch string `json:"path_match,omitempty"` // protocol - // Enum: [ipv4 ipv6] + // Enum: ["ipv4","ipv6"] // +kubebuilder:validation:Enum=ipv4;ipv6; Protocol string `json:"protocol,omitempty"` @@ -197,7 +197,7 @@ type HTTPRequestRule struct { QueryFmt string `json:"query-fmt,omitempty"` // redir code - // Enum: [301 302 303 307 308] + // Enum: [301,302,303,307,308] // +kubebuilder:validation:Enum=301;302;303;307;308; RedirCode *int64 `json:"redir_code,omitempty"` @@ -205,7 +205,7 @@ type HTTPRequestRule struct { RedirOption string `json:"redir_option,omitempty"` // redir type - // Enum: [location prefix scheme] + // Enum: ["location","prefix","scheme"] // +kubebuilder:validation:Enum=location;prefix;scheme; RedirType string `json:"redir_type,omitempty"` @@ -221,7 +221,7 @@ type HTTPRequestRule struct { ReturnContent string `json:"return_content,omitempty"` // return content format - // Enum: [default-errorfiles errorfile errorfiles file lf-file string lf-string] + // Enum: ["default-errorfiles","errorfile","errorfiles","file","lf-file","string","lf-string"] // +kubebuilder:validation:Enum=default-errorfiles;errorfile;errorfiles;file;lf-file;string;lf-string; ReturnContentFormat string `json:"return_content_format,omitempty"` @@ -235,6 +235,9 @@ type HTTPRequestRule struct { // +kubebuilder:validation:Minimum=200 ReturnStatusCode *int64 `json:"return_status_code,omitempty"` + // rst ttl + RstTTL int64 `json:"rst_ttl,omitempty"` + // sc expr ScExpr string `json:"sc_expr,omitempty"` @@ -261,7 +264,7 @@ type HTTPRequestRule struct { SpoeGroup string `json:"spoe_group,omitempty"` // strict mode - // Enum: [on off] + // Enum: ["on","off"] // +kubebuilder:validation:Enum=on;off; StrictMode string `json:"strict_mode,omitempty"` @@ -269,7 +272,7 @@ type HTTPRequestRule struct { Timeout string `json:"timeout,omitempty"` // timeout type - // Enum: [server tunnel client] + // Enum: ["server","tunnel","client"] // +kubebuilder:validation:Enum=server;tunnel;client; TimeoutType string `json:"timeout_type,omitempty"` @@ -293,8 +296,8 @@ type HTTPRequestRule struct { // type // Required: true - // Enum: [add-acl add-header allow auth cache-use capture del-acl del-header del-map deny disable-l7-retry do-resolve early-hint lua normalize-uri redirect reject replace-header replace-path replace-pathq replace-uri replace-value return sc-add-gpc sc-inc-gpc sc-inc-gpc0 sc-inc-gpc1 sc-set-gpt sc-set-gpt0 send-spoe-group set-bc-mark set-bc-tos set-dst set-dst-port set-fc-mark set-fc-tos set-header set-log-level set-map set-mark set-method set-nice set-path set-pathq set-priority-class set-priority-offset set-query set-src set-src-port set-timeout set-tos set-uri set-var silent-drop strict-mode tarpit track-sc0 track-sc1 track-sc2 track-sc unset-var use-service wait-for-body wait-for-handshake set-bandwidth-limit] - // +kubebuilder:validation:Enum=add-acl;add-header;allow;auth;cache-use;capture;del-acl;del-header;del-map;deny;disable-l7-retry;do-resolve;early-hint;lua;normalize-uri;redirect;reject;replace-header;replace-path;replace-pathq;replace-uri;replace-value;return;sc-add-gpc;sc-inc-gpc;sc-inc-gpc0;sc-inc-gpc1;sc-set-gpt;sc-set-gpt0;send-spoe-group;set-bc-mark;set-bc-tos;set-dst;set-dst-port;set-fc-mark;set-fc-tos;set-header;set-log-level;set-map;set-mark;set-method;set-nice;set-path;set-pathq;set-priority-class;set-priority-offset;set-query;set-src;set-src-port;set-timeout;set-tos;set-uri;set-var;silent-drop;strict-mode;tarpit;track-sc0;track-sc1;track-sc2;track-sc;unset-var;use-service;wait-for-body;wait-for-handshake;set-bandwidth-limit; + // Enum: ["add-acl","add-header","allow","auth","cache-use","capture","del-acl","del-header","del-map","deny","disable-l7-retry","do-resolve","early-hint","lua","normalize-uri","redirect","reject","replace-header","replace-path","replace-pathq","replace-uri","replace-value","return","sc-add-gpc","sc-inc-gpc","sc-inc-gpc0","sc-inc-gpc1","sc-set-gpt","sc-set-gpt0","send-spoe-group","set-bc-mark","set-bc-tos","set-dst","set-dst-port","set-fc-mark","set-fc-tos","set-header","set-log-level","set-map","set-mark","set-method","set-nice","set-path","set-pathq","set-priority-class","set-priority-offset","set-query","set-src","set-src-port","set-timeout","set-tos","set-uri","set-var","set-var-fmt","silent-drop","strict-mode","tarpit","track-sc","unset-var","use-service","wait-for-body","wait-for-handshake","set-bandwidth-limit"] + // +kubebuilder:validation:Enum=add-acl;add-header;allow;auth;cache-use;capture;del-acl;del-header;del-map;deny;disable-l7-retry;do-resolve;early-hint;lua;normalize-uri;redirect;reject;replace-header;replace-path;replace-pathq;replace-uri;replace-value;return;sc-add-gpc;sc-inc-gpc;sc-inc-gpc0;sc-inc-gpc1;sc-set-gpt;sc-set-gpt0;send-spoe-group;set-bc-mark;set-bc-tos;set-dst;set-dst-port;set-fc-mark;set-fc-tos;set-header;set-log-level;set-map;set-mark;set-method;set-nice;set-path;set-pathq;set-priority-class;set-priority-offset;set-query;set-src;set-src-port;set-timeout;set-tos;set-uri;set-var;set-var-fmt;silent-drop;strict-mode;tarpit;track-sc;unset-var;use-service;wait-for-body;wait-for-handshake;set-bandwidth-limit; Type string `json:"type"` // uri fmt @@ -569,7 +572,7 @@ func (m *HTTPRequestRule) validateCaptureSample(formats strfmt.Registry) error { return nil } - if err := validate.Pattern("capture_sample", "body", m.CaptureSample, `^[^\s]+$`); err != nil { + if err := validate.Pattern("capture_sample", "body", m.CaptureSample, `^(?:[A-Za-z]+\("([A-Za-z\s]+)"\)|[A-Za-z]+)`); err != nil { return err } @@ -1249,7 +1252,7 @@ var httpRequestRuleTypeTypePropEnum []interface{} func init() { var res []string - if err := json.Unmarshal([]byte(`["add-acl","add-header","allow","auth","cache-use","capture","del-acl","del-header","del-map","deny","disable-l7-retry","do-resolve","early-hint","lua","normalize-uri","redirect","reject","replace-header","replace-path","replace-pathq","replace-uri","replace-value","return","sc-add-gpc","sc-inc-gpc","sc-inc-gpc0","sc-inc-gpc1","sc-set-gpt","sc-set-gpt0","send-spoe-group","set-bc-mark","set-bc-tos","set-dst","set-dst-port","set-fc-mark","set-fc-tos","set-header","set-log-level","set-map","set-mark","set-method","set-nice","set-path","set-pathq","set-priority-class","set-priority-offset","set-query","set-src","set-src-port","set-timeout","set-tos","set-uri","set-var","silent-drop","strict-mode","tarpit","track-sc0","track-sc1","track-sc2","track-sc","unset-var","use-service","wait-for-body","wait-for-handshake","set-bandwidth-limit"]`), &res); err != nil { + if err := json.Unmarshal([]byte(`["add-acl","add-header","allow","auth","cache-use","capture","del-acl","del-header","del-map","deny","disable-l7-retry","do-resolve","early-hint","lua","normalize-uri","redirect","reject","replace-header","replace-path","replace-pathq","replace-uri","replace-value","return","sc-add-gpc","sc-inc-gpc","sc-inc-gpc0","sc-inc-gpc1","sc-set-gpt","sc-set-gpt0","send-spoe-group","set-bc-mark","set-bc-tos","set-dst","set-dst-port","set-fc-mark","set-fc-tos","set-header","set-log-level","set-map","set-mark","set-method","set-nice","set-path","set-pathq","set-priority-class","set-priority-offset","set-query","set-src","set-src-port","set-timeout","set-tos","set-uri","set-var","set-var-fmt","silent-drop","strict-mode","tarpit","track-sc","unset-var","use-service","wait-for-body","wait-for-handshake","set-bandwidth-limit"]`), &res); err != nil { panic(err) } for _, v := range res { @@ -1418,6 +1421,9 @@ const ( // HTTPRequestRuleTypeSetDashVar captures enum value "set-var" HTTPRequestRuleTypeSetDashVar string = "set-var" + // HTTPRequestRuleTypeSetDashVarDashFmt captures enum value "set-var-fmt" + HTTPRequestRuleTypeSetDashVarDashFmt string = "set-var-fmt" + // HTTPRequestRuleTypeSilentDashDrop captures enum value "silent-drop" HTTPRequestRuleTypeSilentDashDrop string = "silent-drop" @@ -1427,15 +1433,6 @@ const ( // HTTPRequestRuleTypeTarpit captures enum value "tarpit" HTTPRequestRuleTypeTarpit string = "tarpit" - // HTTPRequestRuleTypeTrackDashSc0 captures enum value "track-sc0" - HTTPRequestRuleTypeTrackDashSc0 string = "track-sc0" - - // HTTPRequestRuleTypeTrackDashSc1 captures enum value "track-sc1" - HTTPRequestRuleTypeTrackDashSc1 string = "track-sc1" - - // HTTPRequestRuleTypeTrackDashSc2 captures enum value "track-sc2" - HTTPRequestRuleTypeTrackDashSc2 string = "track-sc2" - // HTTPRequestRuleTypeTrackDashSc captures enum value "track-sc" HTTPRequestRuleTypeTrackDashSc string = "track-sc" @@ -1532,6 +1529,11 @@ func (m *HTTPRequestRule) contextValidateReturnHeaders(ctx context.Context, form for i := 0; i < len(m.ReturnHeaders); i++ { if m.ReturnHeaders[i] != nil { + + if swag.IsZero(m.ReturnHeaders[i]) { // not required + return nil + } + if err := m.ReturnHeaders[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("return_hdrs" + "." + strconv.Itoa(i)) diff --git a/models/http_request_rule_compare.go b/models/http_request_rule_compare.go index eb1ce2d3..8df2fed4 100644 --- a/models/http_request_rule_compare.go +++ b/models/http_request_rule_compare.go @@ -227,6 +227,10 @@ func (s HTTPRequestRule) Equal(t HTTPRequestRule, opts ...Options) bool { return false } + if s.RstTTL != t.RstTTL { + return false + } + if s.ScExpr != t.ScExpr { return false } @@ -536,6 +540,10 @@ func (s HTTPRequestRule) Diff(t HTTPRequestRule, opts ...Options) map[string][]i diff["ReturnStatusCode"] = []interface{}{ValueOrNil(s.ReturnStatusCode), ValueOrNil(t.ReturnStatusCode)} } + if s.RstTTL != t.RstTTL { + diff["RstTTL"] = []interface{}{s.RstTTL, t.RstTTL} + } + if s.ScExpr != t.ScExpr { diff["ScExpr"] = []interface{}{s.ScExpr, t.ScExpr} } diff --git a/models/http_request_rule_compare_test.go b/models/http_request_rule_compare_test.go index 69c31c34..6e7565d0 100644 --- a/models/http_request_rule_compare_test.go +++ b/models/http_request_rule_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestHTTPRequestRuleEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPRequestRule var result HTTPRequestRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestHTTPRequestRuleEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPRequestRule to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestHTTPRequestRuleEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPRequestRule var result HTTPRequestRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CaptureID = Ptr(*sample.CaptureID + 1) result.CaptureLen = sample.CaptureLen + 1 @@ -91,6 +94,7 @@ func TestHTTPRequestRuleEqualFalse(t *testing.T) { result.NormalizerStrict = !sample.NormalizerStrict result.RedirCode = Ptr(*sample.RedirCode + 1) result.ReturnStatusCode = Ptr(*sample.ReturnStatusCode + 1) + result.RstTTL = sample.RstTTL + 1 result.ScID = sample.ScID + 1 result.ScIdx = sample.ScIdx + 1 result.ScInt = Ptr(*sample.ScInt + 1) @@ -108,11 +112,11 @@ func TestHTTPRequestRuleEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPRequestRule to be different, but it is not %s %s", a, b) } @@ -126,17 +130,17 @@ func TestHTTPRequestRuleDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPRequestRule var result HTTPRequestRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -150,11 +154,11 @@ func TestHTTPRequestRuleDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPRequestRule to be equal, but it is not %s %s, %v", a, b, result) } @@ -168,13 +172,13 @@ func TestHTTPRequestRuleDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPRequestRule var result HTTPRequestRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CaptureID = Ptr(*sample.CaptureID + 1) result.CaptureLen = sample.CaptureLen + 1 @@ -184,6 +188,7 @@ func TestHTTPRequestRuleDiffFalse(t *testing.T) { result.NormalizerStrict = !sample.NormalizerStrict result.RedirCode = Ptr(*sample.RedirCode + 1) result.ReturnStatusCode = Ptr(*sample.ReturnStatusCode + 1) + result.RstTTL = sample.RstTTL + 1 result.ScID = sample.ScID + 1 result.ScIdx = sample.ScIdx + 1 result.ScInt = Ptr(*sample.ScInt + 1) @@ -197,17 +202,17 @@ func TestHTTPRequestRuleDiffFalse(t *testing.T) { for _, sample := range samples { result := sample.a.Diff(sample.b) - if len(result) != 69 { + if len(result) != 70 { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - t.Errorf("Expected HTTPRequestRule to be different in 69 cases, but it is not (%d) %s %s", len(result), a, b) + t.Errorf("Expected HTTPRequestRule to be different in 70 cases, but it is not (%d) %s %s", len(result), a, b) } } } diff --git a/models/http_request_rules.go b/models/http_request_rules.go index 6962ced2..4dd6b80a 100644 --- a/models/http_request_rules.go +++ b/models/http_request_rules.go @@ -71,6 +71,11 @@ func (m HTTPRequestRules) ContextValidate(ctx context.Context, formats strfmt.Re for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/http_response_rule.go b/models/http_response_rule.go index dab21c81..4deccd57 100644 --- a/models/http_response_rule.go +++ b/models/http_response_rule.go @@ -75,7 +75,7 @@ type HTTPResponseRule struct { CaptureSample string `json:"capture_sample,omitempty"` // cond - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond string `json:"cond,omitempty"` @@ -105,7 +105,7 @@ type HTTPResponseRule struct { HdrName string `json:"hdr_name,omitempty"` // log level - // Enum: [emerg alert crit err warning notice info debug silent] + // Enum: ["emerg","alert","crit","err","warning","notice","info","debug","silent"] // +kubebuilder:validation:Enum=emerg;alert;crit;err;warning;notice;info;debug;silent; LogLevel string `json:"log_level,omitempty"` @@ -145,7 +145,7 @@ type HTTPResponseRule struct { NiceValue int64 `json:"nice_value,omitempty"` // redir code - // Enum: [301 302 303 307 308] + // Enum: [301,302,303,307,308] // +kubebuilder:validation:Enum=301;302;303;307;308; RedirCode *int64 `json:"redir_code,omitempty"` @@ -153,7 +153,7 @@ type HTTPResponseRule struct { RedirOption string `json:"redir_option,omitempty"` // redir type - // Enum: [location prefix scheme] + // Enum: ["location","prefix","scheme"] // +kubebuilder:validation:Enum=location;prefix;scheme; RedirType string `json:"redir_type,omitempty"` @@ -166,7 +166,7 @@ type HTTPResponseRule struct { ReturnContent string `json:"return_content,omitempty"` // return content format - // Enum: [default-errorfiles errorfile errorfiles file lf-file string lf-string] + // Enum: ["default-errorfiles","errorfile","errorfiles","file","lf-file","string","lf-string"] // +kubebuilder:validation:Enum=default-errorfiles;errorfile;errorfiles;file;lf-file;string;lf-string; ReturnContentFormat string `json:"return_content_format,omitempty"` @@ -180,6 +180,9 @@ type HTTPResponseRule struct { // +kubebuilder:validation:Minimum=200 ReturnStatusCode *int64 `json:"return_status_code,omitempty"` + // rst ttl + RstTTL int64 `json:"rst_ttl,omitempty"` + // sc expr ScExpr string `json:"sc_expr,omitempty"` @@ -213,7 +216,7 @@ type HTTPResponseRule struct { StatusReason string `json:"status_reason,omitempty"` // strict mode - // Enum: [on off] + // Enum: ["on","off"] // +kubebuilder:validation:Enum=on;off; StrictMode string `json:"strict_mode,omitempty"` @@ -221,7 +224,7 @@ type HTTPResponseRule struct { Timeout string `json:"timeout,omitempty"` // timeout type - // Enum: [server tunnel client] + // Enum: ["server","tunnel","client"] // +kubebuilder:validation:Enum=server;tunnel;client; TimeoutType string `json:"timeout_type,omitempty"` @@ -245,8 +248,8 @@ type HTTPResponseRule struct { // type // Required: true - // Enum: [add-acl add-header allow cache-store capture del-acl del-header del-map deny lua redirect replace-header replace-value return sc-add-gpc sc-inc-gpc sc-inc-gpc0 sc-inc-gpc1 sc-set-gpt sc-set-gpt0 send-spoe-group set-fc-mark set-fc-tos set-header set-log-level set-map set-mark set-nice set-status set-timeout set-tos set-var set-var-fmt silent-drop strict-mode track-sc0 track-sc1 track-sc2 track-sc unset-var wait-for-body set-bandwidth-limit] - // +kubebuilder:validation:Enum=add-acl;add-header;allow;cache-store;capture;del-acl;del-header;del-map;deny;lua;redirect;replace-header;replace-value;return;sc-add-gpc;sc-inc-gpc;sc-inc-gpc0;sc-inc-gpc1;sc-set-gpt;sc-set-gpt0;send-spoe-group;set-fc-mark;set-fc-tos;set-header;set-log-level;set-map;set-mark;set-nice;set-status;set-timeout;set-tos;set-var;set-var-fmt;silent-drop;strict-mode;track-sc0;track-sc1;track-sc2;track-sc;unset-var;wait-for-body;set-bandwidth-limit; + // Enum: ["add-acl","add-header","allow","cache-store","capture","del-acl","del-header","del-map","deny","lua","redirect","replace-header","replace-value","return","sc-add-gpc","sc-inc-gpc","sc-inc-gpc0","sc-inc-gpc1","sc-set-gpt","sc-set-gpt0","send-spoe-group","set-fc-mark","set-fc-tos","set-header","set-log-level","set-map","set-mark","set-nice","set-status","set-timeout","set-tos","set-var","set-var-fmt","silent-drop","strict-mode","track-sc","unset-var","wait-for-body","set-bandwidth-limit"] + // +kubebuilder:validation:Enum=add-acl;add-header;allow;cache-store;capture;del-acl;del-header;del-map;deny;lua;redirect;replace-header;replace-value;return;sc-add-gpc;sc-inc-gpc;sc-inc-gpc0;sc-inc-gpc1;sc-set-gpt;sc-set-gpt0;send-spoe-group;set-fc-mark;set-fc-tos;set-header;set-log-level;set-map;set-mark;set-nice;set-status;set-timeout;set-tos;set-var;set-var-fmt;silent-drop;strict-mode;track-sc;unset-var;wait-for-body;set-bandwidth-limit; Type string `json:"type"` // var expr @@ -1009,7 +1012,7 @@ var httpResponseRuleTypeTypePropEnum []interface{} func init() { var res []string - if err := json.Unmarshal([]byte(`["add-acl","add-header","allow","cache-store","capture","del-acl","del-header","del-map","deny","lua","redirect","replace-header","replace-value","return","sc-add-gpc","sc-inc-gpc","sc-inc-gpc0","sc-inc-gpc1","sc-set-gpt","sc-set-gpt0","send-spoe-group","set-fc-mark","set-fc-tos","set-header","set-log-level","set-map","set-mark","set-nice","set-status","set-timeout","set-tos","set-var","set-var-fmt","silent-drop","strict-mode","track-sc0","track-sc1","track-sc2","track-sc","unset-var","wait-for-body","set-bandwidth-limit"]`), &res); err != nil { + if err := json.Unmarshal([]byte(`["add-acl","add-header","allow","cache-store","capture","del-acl","del-header","del-map","deny","lua","redirect","replace-header","replace-value","return","sc-add-gpc","sc-inc-gpc","sc-inc-gpc0","sc-inc-gpc1","sc-set-gpt","sc-set-gpt0","send-spoe-group","set-fc-mark","set-fc-tos","set-header","set-log-level","set-map","set-mark","set-nice","set-status","set-timeout","set-tos","set-var","set-var-fmt","silent-drop","strict-mode","track-sc","unset-var","wait-for-body","set-bandwidth-limit"]`), &res); err != nil { panic(err) } for _, v := range res { @@ -1124,15 +1127,6 @@ const ( // HTTPResponseRuleTypeStrictDashMode captures enum value "strict-mode" HTTPResponseRuleTypeStrictDashMode string = "strict-mode" - // HTTPResponseRuleTypeTrackDashSc0 captures enum value "track-sc0" - HTTPResponseRuleTypeTrackDashSc0 string = "track-sc0" - - // HTTPResponseRuleTypeTrackDashSc1 captures enum value "track-sc1" - HTTPResponseRuleTypeTrackDashSc1 string = "track-sc1" - - // HTTPResponseRuleTypeTrackDashSc2 captures enum value "track-sc2" - HTTPResponseRuleTypeTrackDashSc2 string = "track-sc2" - // HTTPResponseRuleTypeTrackDashSc captures enum value "track-sc" HTTPResponseRuleTypeTrackDashSc string = "track-sc" @@ -1223,6 +1217,11 @@ func (m *HTTPResponseRule) contextValidateReturnHeaders(ctx context.Context, for for i := 0; i < len(m.ReturnHeaders); i++ { if m.ReturnHeaders[i] != nil { + + if swag.IsZero(m.ReturnHeaders[i]) { // not required + return nil + } + if err := m.ReturnHeaders[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("return_hdrs" + "." + strconv.Itoa(i)) diff --git a/models/http_response_rule_compare.go b/models/http_response_rule_compare.go index 3d3c07a8..86d206ea 100644 --- a/models/http_response_rule_compare.go +++ b/models/http_response_rule_compare.go @@ -175,6 +175,10 @@ func (s HTTPResponseRule) Equal(t HTTPResponseRule, opts ...Options) bool { return false } + if s.RstTTL != t.RstTTL { + return false + } + if s.ScExpr != t.ScExpr { return false } @@ -428,6 +432,10 @@ func (s HTTPResponseRule) Diff(t HTTPResponseRule, opts ...Options) map[string][ diff["ReturnStatusCode"] = []interface{}{ValueOrNil(s.ReturnStatusCode), ValueOrNil(t.ReturnStatusCode)} } + if s.RstTTL != t.RstTTL { + diff["RstTTL"] = []interface{}{s.RstTTL, t.RstTTL} + } + if s.ScExpr != t.ScExpr { diff["ScExpr"] = []interface{}{s.ScExpr, t.ScExpr} } diff --git a/models/http_response_rule_compare_test.go b/models/http_response_rule_compare_test.go index cc25f9df..58d812f5 100644 --- a/models/http_response_rule_compare_test.go +++ b/models/http_response_rule_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestHTTPResponseRuleEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPResponseRule var result HTTPResponseRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestHTTPResponseRuleEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPResponseRule to be equal, but it is not %s %s", a, b) } @@ -75,19 +78,20 @@ func TestHTTPResponseRuleEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPResponseRule var result HTTPResponseRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CaptureID = Ptr(*sample.CaptureID + 1) result.DenyStatus = Ptr(*sample.DenyStatus + 1) result.NiceValue = sample.NiceValue + 1 result.RedirCode = Ptr(*sample.RedirCode + 1) result.ReturnStatusCode = Ptr(*sample.ReturnStatusCode + 1) + result.RstTTL = sample.RstTTL + 1 result.ScID = sample.ScID + 1 result.ScIdx = sample.ScIdx + 1 result.ScInt = Ptr(*sample.ScInt + 1) @@ -106,11 +110,11 @@ func TestHTTPResponseRuleEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPResponseRule to be different, but it is not %s %s", a, b) } @@ -124,17 +128,17 @@ func TestHTTPResponseRuleDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPResponseRule var result HTTPResponseRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -148,11 +152,11 @@ func TestHTTPResponseRuleDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HTTPResponseRule to be equal, but it is not %s %s, %v", a, b, result) } @@ -166,19 +170,20 @@ func TestHTTPResponseRuleDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HTTPResponseRule var result HTTPResponseRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CaptureID = Ptr(*sample.CaptureID + 1) result.DenyStatus = Ptr(*sample.DenyStatus + 1) result.NiceValue = sample.NiceValue + 1 result.RedirCode = Ptr(*sample.RedirCode + 1) result.ReturnStatusCode = Ptr(*sample.ReturnStatusCode + 1) + result.RstTTL = sample.RstTTL + 1 result.ScID = sample.ScID + 1 result.ScIdx = sample.ScIdx + 1 result.ScInt = Ptr(*sample.ScInt + 1) @@ -193,17 +198,17 @@ func TestHTTPResponseRuleDiffFalse(t *testing.T) { for _, sample := range samples { result := sample.a.Diff(sample.b) - if len(result) != 55 { + if len(result) != 56 { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - t.Errorf("Expected HTTPResponseRule to be different in 55 cases, but it is not (%d) %s %s", len(result), a, b) + t.Errorf("Expected HTTPResponseRule to be different in 56 cases, but it is not (%d) %s %s", len(result), a, b) } } } diff --git a/models/http_response_rules.go b/models/http_response_rules.go index 34e17a91..1de0d943 100644 --- a/models/http_response_rules.go +++ b/models/http_response_rules.go @@ -71,6 +71,11 @@ func (m HTTPResponseRules) ContextValidate(ctx context.Context, formats strfmt.R for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/httpchk_params.go b/models/httpchk_params.go index c4a9ea5e..724da90a 100644 --- a/models/httpchk_params.go +++ b/models/httpchk_params.go @@ -35,7 +35,7 @@ import ( // swagger:model httpchk_params type HttpchkParams struct { // method - // Enum: [HEAD PUT POST GET TRACE PATCH DELETE CONNECT OPTIONS] + // Enum: ["HEAD","PUT","POST","GET","TRACE","PATCH","DELETE","CONNECT","OPTIONS"] // +kubebuilder:validation:Enum=HEAD;PUT;POST;GET;TRACE;PATCH;DELETE;CONNECT;OPTIONS; Method string `json:"method,omitempty"` diff --git a/models/httpchk_params_compare_test.go b/models/httpchk_params_compare_test.go index 5c962367..314bbc52 100644 --- a/models/httpchk_params_compare_test.go +++ b/models/httpchk_params_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestHttpchkParamsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample HttpchkParams var result HttpchkParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestHttpchkParamsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HttpchkParams to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestHttpchkParamsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HttpchkParams var result HttpchkParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b HttpchkParams @@ -94,11 +97,11 @@ func TestHttpchkParamsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HttpchkParams to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestHttpchkParamsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample HttpchkParams var result HttpchkParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestHttpchkParamsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HttpchkParams to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestHttpchkParamsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample HttpchkParams var result HttpchkParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b HttpchkParams @@ -173,11 +176,11 @@ func TestHttpchkParamsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected HttpchkParams to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/info.go b/models/info.go index f1caaaea..b1bbc397 100644 --- a/models/info.go +++ b/models/info.go @@ -121,6 +121,11 @@ func (m *Info) ContextValidate(ctx context.Context, formats strfmt.Registry) err func (m *Info) contextValidateAPI(ctx context.Context, formats strfmt.Registry) error { if m.API != nil { + + if swag.IsZero(m.API) { // not required + return nil + } + if err := m.API.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("api") @@ -137,6 +142,11 @@ func (m *Info) contextValidateAPI(ctx context.Context, formats strfmt.Registry) func (m *Info) contextValidateSystem(ctx context.Context, formats strfmt.Registry) error { if m.System != nil { + + if swag.IsZero(m.System) { // not required + return nil + } + if err := m.System.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("system") @@ -331,6 +341,11 @@ func (m *InfoSystem) ContextValidate(ctx context.Context, formats strfmt.Registr func (m *InfoSystem) contextValidateCPUInfo(ctx context.Context, formats strfmt.Registry) error { if m.CPUInfo != nil { + + if swag.IsZero(m.CPUInfo) { // not required + return nil + } + if err := m.CPUInfo.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("system" + "." + "cpu_info") @@ -347,6 +362,11 @@ func (m *InfoSystem) contextValidateCPUInfo(ctx context.Context, formats strfmt. func (m *InfoSystem) contextValidateMemInfo(ctx context.Context, formats strfmt.Registry) error { if m.MemInfo != nil { + + if swag.IsZero(m.MemInfo) { // not required + return nil + } + if err := m.MemInfo.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("system" + "." + "mem_info") diff --git a/models/info_compare_test.go b/models/info_compare_test.go index 5655c34e..3250c664 100644 --- a/models/info_compare_test.go +++ b/models/info_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -24,6 +26,7 @@ import ( "time" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" "github.com/go-openapi/strfmt" jsoniter "github.com/json-iterator/go" @@ -36,17 +39,17 @@ func TestInfoEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Info var result Info - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -60,11 +63,11 @@ func TestInfoEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Info to be equal, but it is not %s %s", a, b) } @@ -78,13 +81,13 @@ func TestInfoEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Info var result Info - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Info @@ -97,11 +100,11 @@ func TestInfoEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Info to be different, but it is not %s %s", a, b) } @@ -115,17 +118,17 @@ func TestInfoDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Info var result Info - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -139,11 +142,11 @@ func TestInfoDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Info to be equal, but it is not %s %s, %v", a, b, result) } @@ -157,13 +160,13 @@ func TestInfoDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Info var result Info - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Info @@ -176,11 +179,11 @@ func TestInfoDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Info to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -194,17 +197,17 @@ func TestInfoAPIEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoAPI var result InfoAPI - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -218,11 +221,11 @@ func TestInfoAPIEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoAPI to be equal, but it is not %s %s", a, b) } @@ -236,13 +239,13 @@ func TestInfoAPIEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoAPI var result InfoAPI - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.BuildDate = strfmt.DateTime(time.Now().AddDate(rand.Intn(10), rand.Intn(12), rand.Intn(28))) samples = append(samples, struct { @@ -256,11 +259,11 @@ func TestInfoAPIEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoAPI to be different, but it is not %s %s", a, b) } @@ -274,17 +277,17 @@ func TestInfoAPIDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoAPI var result InfoAPI - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -298,11 +301,11 @@ func TestInfoAPIDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoAPI to be equal, but it is not %s %s, %v", a, b, result) } @@ -316,13 +319,13 @@ func TestInfoAPIDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoAPI var result InfoAPI - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.BuildDate = strfmt.DateTime(time.Now().AddDate(rand.Intn(10), rand.Intn(12), rand.Intn(28))) samples = append(samples, struct { @@ -336,11 +339,11 @@ func TestInfoAPIDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoAPI to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -354,17 +357,17 @@ func TestInfoSystemEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoSystem var result InfoSystem - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -378,11 +381,11 @@ func TestInfoSystemEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoSystem to be equal, but it is not %s %s", a, b) } @@ -396,13 +399,13 @@ func TestInfoSystemEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoSystem var result InfoSystem - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Time = sample.Time + 1 result.Uptime = Ptr(*sample.Uptime + 1) @@ -417,11 +420,11 @@ func TestInfoSystemEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoSystem to be different, but it is not %s %s", a, b) } @@ -435,17 +438,17 @@ func TestInfoSystemDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoSystem var result InfoSystem - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -459,11 +462,11 @@ func TestInfoSystemDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoSystem to be equal, but it is not %s %s, %v", a, b, result) } @@ -477,13 +480,13 @@ func TestInfoSystemDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoSystem var result InfoSystem - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Time = sample.Time + 1 result.Uptime = Ptr(*sample.Uptime + 1) @@ -498,11 +501,11 @@ func TestInfoSystemDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoSystem to be different in 6 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -516,17 +519,17 @@ func TestInfoSystemCPUInfoEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoSystemCPUInfo var result InfoSystemCPUInfo - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -540,11 +543,11 @@ func TestInfoSystemCPUInfoEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoSystemCPUInfo to be equal, but it is not %s %s", a, b) } @@ -558,13 +561,13 @@ func TestInfoSystemCPUInfoEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoSystemCPUInfo var result InfoSystemCPUInfo - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.NumCpus = sample.NumCpus + 1 samples = append(samples, struct { @@ -578,11 +581,11 @@ func TestInfoSystemCPUInfoEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoSystemCPUInfo to be different, but it is not %s %s", a, b) } @@ -596,17 +599,17 @@ func TestInfoSystemCPUInfoDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoSystemCPUInfo var result InfoSystemCPUInfo - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -620,11 +623,11 @@ func TestInfoSystemCPUInfoDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoSystemCPUInfo to be equal, but it is not %s %s, %v", a, b, result) } @@ -638,13 +641,13 @@ func TestInfoSystemCPUInfoDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoSystemCPUInfo var result InfoSystemCPUInfo - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.NumCpus = sample.NumCpus + 1 samples = append(samples, struct { @@ -658,11 +661,11 @@ func TestInfoSystemCPUInfoDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoSystemCPUInfo to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -676,17 +679,17 @@ func TestInfoSystemMemInfoEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoSystemMemInfo var result InfoSystemMemInfo - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -700,11 +703,11 @@ func TestInfoSystemMemInfoEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoSystemMemInfo to be equal, but it is not %s %s", a, b) } @@ -718,13 +721,13 @@ func TestInfoSystemMemInfoEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoSystemMemInfo var result InfoSystemMemInfo - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.DataplaneapiMemory = sample.DataplaneapiMemory + 1 result.FreeMemory = sample.FreeMemory + 1 @@ -740,11 +743,11 @@ func TestInfoSystemMemInfoEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoSystemMemInfo to be different, but it is not %s %s", a, b) } @@ -758,17 +761,17 @@ func TestInfoSystemMemInfoDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoSystemMemInfo var result InfoSystemMemInfo - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -782,11 +785,11 @@ func TestInfoSystemMemInfoDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoSystemMemInfo to be equal, but it is not %s %s, %v", a, b, result) } @@ -800,13 +803,13 @@ func TestInfoSystemMemInfoDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample InfoSystemMemInfo var result InfoSystemMemInfo - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.DataplaneapiMemory = sample.DataplaneapiMemory + 1 result.FreeMemory = sample.FreeMemory + 1 @@ -822,11 +825,11 @@ func TestInfoSystemMemInfoDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected InfoSystemMemInfo to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/log_forward_base_compare_test.go b/models/log_forward_base_compare_test.go index a4ff1d95..5679acdf 100644 --- a/models/log_forward_base_compare_test.go +++ b/models/log_forward_base_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestLogForwardBaseEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample LogForwardBase var result LogForwardBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestLogForwardBaseEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LogForwardBase to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestLogForwardBaseEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample LogForwardBase var result LogForwardBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Backlog = Ptr(*sample.Backlog + 1) result.Maxconn = Ptr(*sample.Maxconn + 1) @@ -97,11 +100,11 @@ func TestLogForwardBaseEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LogForwardBase to be different, but it is not %s %s", a, b) } @@ -115,17 +118,17 @@ func TestLogForwardBaseDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample LogForwardBase var result LogForwardBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -139,11 +142,11 @@ func TestLogForwardBaseDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LogForwardBase to be equal, but it is not %s %s, %v", a, b, result) } @@ -157,13 +160,13 @@ func TestLogForwardBaseDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample LogForwardBase var result LogForwardBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Backlog = Ptr(*sample.Backlog + 1) result.Maxconn = Ptr(*sample.Maxconn + 1) @@ -179,11 +182,11 @@ func TestLogForwardBaseDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LogForwardBase to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/log_forward_compare_test.go b/models/log_forward_compare_test.go index cd5766c7..622e2d61 100644 --- a/models/log_forward_compare_test.go +++ b/models/log_forward_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestLogForwardEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample LogForward var result LogForward - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestLogForwardEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LogForward to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestLogForwardEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample LogForward var result LogForward - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b LogForward @@ -94,11 +97,11 @@ func TestLogForwardEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LogForward to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestLogForwardDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample LogForward var result LogForward - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestLogForwardDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LogForward to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestLogForwardDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample LogForward var result LogForward - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b LogForward @@ -173,11 +176,11 @@ func TestLogForwardDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LogForward to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/log_forwards.go b/models/log_forwards.go index 6200f26c..66dd5330 100644 --- a/models/log_forwards.go +++ b/models/log_forwards.go @@ -71,6 +71,11 @@ func (m LogForwards) ContextValidate(ctx context.Context, formats strfmt.Registr for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/log_target.go b/models/log_target.go index 0e71c9ee..e962a04b 100644 --- a/models/log_target.go +++ b/models/log_target.go @@ -42,12 +42,12 @@ type LogTarget struct { Address string `json:"address,omitempty"` // facility - // Enum: [kern user mail daemon auth syslog lpr news uucp cron auth2 ftp ntp audit alert cron2 local0 local1 local2 local3 local4 local5 local6 local7] + // Enum: ["kern","user","mail","daemon","auth","syslog","lpr","news","uucp","cron","auth2","ftp","ntp","audit","alert","cron2","local0","local1","local2","local3","local4","local5","local6","local7"] // +kubebuilder:validation:Enum=kern;user;mail;daemon;auth;syslog;lpr;news;uucp;cron;auth2;ftp;ntp;audit;alert;cron2;local0;local1;local2;local3;local4;local5;local6;local7; Facility string `json:"facility,omitempty"` // format - // Enum: [local rfc3164 rfc5424 priority short timed iso raw] + // Enum: ["local","rfc3164","rfc5424","priority","short","timed","iso","raw"] // +kubebuilder:validation:Enum=local;rfc3164;rfc5424;priority;short;timed;iso;raw; Format string `json:"format,omitempty"` @@ -58,12 +58,12 @@ type LogTarget struct { Length int64 `json:"length,omitempty"` // level - // Enum: [emerg alert crit err warning notice info debug] + // Enum: ["emerg","alert","crit","err","warning","notice","info","debug"] // +kubebuilder:validation:Enum=emerg;alert;crit;err;warning;notice;info;debug; Level string `json:"level,omitempty"` // minlevel - // Enum: [emerg alert crit err warning notice info debug] + // Enum: ["emerg","alert","crit","err","warning","notice","info","debug"] // +kubebuilder:validation:Enum=emerg;alert;crit;err;warning;notice;info;debug; Minlevel string `json:"minlevel,omitempty"` diff --git a/models/log_target_compare_test.go b/models/log_target_compare_test.go index b9acecca..6d6f8cf7 100644 --- a/models/log_target_compare_test.go +++ b/models/log_target_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestLogTargetEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample LogTarget var result LogTarget - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestLogTargetEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LogTarget to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestLogTargetEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample LogTarget var result LogTarget - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Global = !sample.Global result.Length = sample.Length + 1 @@ -98,11 +101,11 @@ func TestLogTargetEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LogTarget to be different, but it is not %s %s", a, b) } @@ -116,17 +119,17 @@ func TestLogTargetDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample LogTarget var result LogTarget - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -140,11 +143,11 @@ func TestLogTargetDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LogTarget to be equal, but it is not %s %s, %v", a, b, result) } @@ -158,13 +161,13 @@ func TestLogTargetDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample LogTarget var result LogTarget - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Global = !sample.Global result.Length = sample.Length + 1 @@ -181,11 +184,11 @@ func TestLogTargetDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LogTarget to be different in 10 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/log_targets.go b/models/log_targets.go index b0bd2e51..b647ddb7 100644 --- a/models/log_targets.go +++ b/models/log_targets.go @@ -71,6 +71,11 @@ func (m LogTargets) ContextValidate(ctx context.Context, formats strfmt.Registry for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/lua_options.go b/models/lua_options.go index d0413c8d..507b1e78 100644 --- a/models/lua_options.go +++ b/models/lua_options.go @@ -139,6 +139,11 @@ func (m *LuaOptions) contextValidateLoads(ctx context.Context, formats strfmt.Re for i := 0; i < len(m.Loads); i++ { if m.Loads[i] != nil { + + if swag.IsZero(m.Loads[i]) { // not required + return nil + } + if err := m.Loads[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("loads" + "." + strconv.Itoa(i)) @@ -159,6 +164,11 @@ func (m *LuaOptions) contextValidatePrependPath(ctx context.Context, formats str for i := 0; i < len(m.PrependPath); i++ { if m.PrependPath[i] != nil { + + if swag.IsZero(m.PrependPath[i]) { // not required + return nil + } + if err := m.PrependPath[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("prepend_path" + "." + strconv.Itoa(i)) @@ -264,7 +274,7 @@ type LuaPrependPath struct { Path *string `json:"path"` // type - // Enum: [path cpath] + // Enum: ["path","cpath"] // +kubebuilder:validation:Enum=path;cpath; Type string `json:"type,omitempty"` } diff --git a/models/lua_options_compare_test.go b/models/lua_options_compare_test.go index 92b508a2..701d1d7d 100644 --- a/models/lua_options_compare_test.go +++ b/models/lua_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestLuaOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample LuaOptions var result LuaOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestLuaOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LuaOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestLuaOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample LuaOptions var result LuaOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b LuaOptions @@ -94,11 +97,11 @@ func TestLuaOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LuaOptions to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestLuaOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample LuaOptions var result LuaOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestLuaOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LuaOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestLuaOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample LuaOptions var result LuaOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b LuaOptions @@ -173,11 +176,11 @@ func TestLuaOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LuaOptions to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -191,17 +194,17 @@ func TestLuaLoadEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample LuaLoad var result LuaLoad - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -215,11 +218,11 @@ func TestLuaLoadEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LuaLoad to be equal, but it is not %s %s", a, b) } @@ -233,13 +236,13 @@ func TestLuaLoadEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample LuaLoad var result LuaLoad - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b LuaLoad @@ -252,11 +255,11 @@ func TestLuaLoadEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LuaLoad to be different, but it is not %s %s", a, b) } @@ -270,17 +273,17 @@ func TestLuaLoadDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample LuaLoad var result LuaLoad - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -294,11 +297,11 @@ func TestLuaLoadDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LuaLoad to be equal, but it is not %s %s, %v", a, b, result) } @@ -312,13 +315,13 @@ func TestLuaLoadDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample LuaLoad var result LuaLoad - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b LuaLoad @@ -331,11 +334,11 @@ func TestLuaLoadDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LuaLoad to be different in 1 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -349,17 +352,17 @@ func TestLuaPrependPathEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample LuaPrependPath var result LuaPrependPath - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -373,11 +376,11 @@ func TestLuaPrependPathEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LuaPrependPath to be equal, but it is not %s %s", a, b) } @@ -391,13 +394,13 @@ func TestLuaPrependPathEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample LuaPrependPath var result LuaPrependPath - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b LuaPrependPath @@ -410,11 +413,11 @@ func TestLuaPrependPathEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LuaPrependPath to be different, but it is not %s %s", a, b) } @@ -428,17 +431,17 @@ func TestLuaPrependPathDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample LuaPrependPath var result LuaPrependPath - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -452,11 +455,11 @@ func TestLuaPrependPathDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LuaPrependPath to be equal, but it is not %s %s, %v", a, b, result) } @@ -470,13 +473,13 @@ func TestLuaPrependPathDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample LuaPrependPath var result LuaPrependPath - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b LuaPrependPath @@ -489,11 +492,11 @@ func TestLuaPrependPathDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected LuaPrependPath to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/mailer_entries.go b/models/mailer_entries.go index 58601cf7..f3df1cc6 100644 --- a/models/mailer_entries.go +++ b/models/mailer_entries.go @@ -71,6 +71,11 @@ func (m MailerEntries) ContextValidate(ctx context.Context, formats strfmt.Regis for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/mailer_entry_compare_test.go b/models/mailer_entry_compare_test.go index 2821c10b..9778bbc7 100644 --- a/models/mailer_entry_compare_test.go +++ b/models/mailer_entry_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestMailerEntryEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample MailerEntry var result MailerEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestMailerEntryEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MailerEntry to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestMailerEntryEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample MailerEntry var result MailerEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = sample.Port + 1 samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestMailerEntryEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MailerEntry to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestMailerEntryDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample MailerEntry var result MailerEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestMailerEntryDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MailerEntry to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestMailerEntryDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample MailerEntry var result MailerEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = sample.Port + 1 samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestMailerEntryDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MailerEntry to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/mailers_section_base_compare_test.go b/models/mailers_section_base_compare_test.go index 4005dfe6..574759b9 100644 --- a/models/mailers_section_base_compare_test.go +++ b/models/mailers_section_base_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestMailersSectionBaseEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample MailersSectionBase var result MailersSectionBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestMailersSectionBaseEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MailersSectionBase to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestMailersSectionBaseEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample MailersSectionBase var result MailersSectionBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Timeout = Ptr(*sample.Timeout + 1) samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestMailersSectionBaseEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MailersSectionBase to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestMailersSectionBaseDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample MailersSectionBase var result MailersSectionBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestMailersSectionBaseDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MailersSectionBase to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestMailersSectionBaseDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample MailersSectionBase var result MailersSectionBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Timeout = Ptr(*sample.Timeout + 1) samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestMailersSectionBaseDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MailersSectionBase to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/mailers_section_compare_test.go b/models/mailers_section_compare_test.go index e93c97ef..2e7d7328 100644 --- a/models/mailers_section_compare_test.go +++ b/models/mailers_section_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestMailersSectionEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample MailersSection var result MailersSection - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestMailersSectionEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MailersSection to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestMailersSectionEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample MailersSection var result MailersSection - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b MailersSection @@ -94,11 +97,11 @@ func TestMailersSectionEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MailersSection to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestMailersSectionDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample MailersSection var result MailersSection - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestMailersSectionDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MailersSection to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestMailersSectionDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample MailersSection var result MailersSection - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b MailersSection @@ -173,11 +176,11 @@ func TestMailersSectionDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MailersSection to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/mailers_sections.go b/models/mailers_sections.go index 0db169e4..7f5a7b9d 100644 --- a/models/mailers_sections.go +++ b/models/mailers_sections.go @@ -71,6 +71,11 @@ func (m MailersSections) ContextValidate(ctx context.Context, formats strfmt.Reg for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/map_compare_test.go b/models/map_compare_test.go index 32ea2feb..4259981c 100644 --- a/models/map_compare_test.go +++ b/models/map_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestMapEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Map var result Map - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestMapEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Map to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestMapEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Map var result Map - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Size = Ptr(*sample.Size + 1) samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestMapEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Map to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestMapDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Map var result Map - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestMapDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Map to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestMapDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Map var result Map - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Size = Ptr(*sample.Size + 1) samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestMapDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Map to be different in 5 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/map_entries.go b/models/map_entries.go index 50197599..16769bf9 100644 --- a/models/map_entries.go +++ b/models/map_entries.go @@ -71,6 +71,11 @@ func (m MapEntries) ContextValidate(ctx context.Context, formats strfmt.Registry for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/map_entry_compare_test.go b/models/map_entry_compare_test.go index 32313ad3..c221a0fb 100644 --- a/models/map_entry_compare_test.go +++ b/models/map_entry_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestMapEntryEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample MapEntry var result MapEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestMapEntryEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MapEntry to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestMapEntryEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample MapEntry var result MapEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b MapEntry @@ -94,11 +97,11 @@ func TestMapEntryEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MapEntry to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestMapEntryDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample MapEntry var result MapEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestMapEntryDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MapEntry to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestMapEntryDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample MapEntry var result MapEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b MapEntry @@ -173,11 +176,11 @@ func TestMapEntryDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MapEntry to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/maps.go b/models/maps.go index 84695fa1..1e2f30b4 100644 --- a/models/maps.go +++ b/models/maps.go @@ -71,6 +71,11 @@ func (m Maps) ContextValidate(ctx context.Context, formats strfmt.Registry) erro for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/monitor_fail.go b/models/monitor_fail.go index 849fdd9a..bb03845c 100644 --- a/models/monitor_fail.go +++ b/models/monitor_fail.go @@ -36,7 +36,7 @@ import ( type MonitorFail struct { // cond // Required: true - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond *string `json:"cond"` diff --git a/models/monitor_fail_compare_test.go b/models/monitor_fail_compare_test.go index 9e29511b..fa8aeb28 100644 --- a/models/monitor_fail_compare_test.go +++ b/models/monitor_fail_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestMonitorFailEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample MonitorFail var result MonitorFail - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestMonitorFailEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MonitorFail to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestMonitorFailEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample MonitorFail var result MonitorFail - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b MonitorFail @@ -94,11 +97,11 @@ func TestMonitorFailEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MonitorFail to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestMonitorFailDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample MonitorFail var result MonitorFail - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestMonitorFailDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MonitorFail to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestMonitorFailDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample MonitorFail var result MonitorFail - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b MonitorFail @@ -173,11 +176,11 @@ func TestMonitorFailDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MonitorFail to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/monitor_uri_compare_test.go b/models/monitor_uri_compare_test.go index d1b15af7..3e561bda 100644 --- a/models/monitor_uri_compare_test.go +++ b/models/monitor_uri_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestMonitorURIEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample MonitorURI var result MonitorURI - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestMonitorURIEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MonitorURI to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestMonitorURIEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample MonitorURI var result MonitorURI - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b MonitorURI @@ -94,11 +97,11 @@ func TestMonitorURIEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MonitorURI to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestMonitorURIDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample MonitorURI var result MonitorURI - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestMonitorURIDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MonitorURI to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestMonitorURIDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample MonitorURI var result MonitorURI - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b MonitorURI @@ -173,11 +176,11 @@ func TestMonitorURIDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MonitorURI to be different in 0 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/mysql_check_params.go b/models/mysql_check_params.go index e3f9a384..64984b46 100644 --- a/models/mysql_check_params.go +++ b/models/mysql_check_params.go @@ -35,7 +35,7 @@ import ( // swagger:model mysql_check_params type MysqlCheckParams struct { // client version - // Enum: [pre-41 post-41] + // Enum: ["pre-41","post-41"] // +kubebuilder:validation:Enum=pre-41;post-41; ClientVersion string `json:"client_version,omitempty"` diff --git a/models/mysql_check_params_compare_test.go b/models/mysql_check_params_compare_test.go index 1a7698db..01a7d060 100644 --- a/models/mysql_check_params_compare_test.go +++ b/models/mysql_check_params_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestMysqlCheckParamsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample MysqlCheckParams var result MysqlCheckParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestMysqlCheckParamsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MysqlCheckParams to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestMysqlCheckParamsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample MysqlCheckParams var result MysqlCheckParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b MysqlCheckParams @@ -94,11 +97,11 @@ func TestMysqlCheckParamsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MysqlCheckParams to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestMysqlCheckParamsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample MysqlCheckParams var result MysqlCheckParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestMysqlCheckParamsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MysqlCheckParams to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestMysqlCheckParamsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample MysqlCheckParams var result MysqlCheckParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b MysqlCheckParams @@ -173,11 +176,11 @@ func TestMysqlCheckParamsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected MysqlCheckParams to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/nameserver_compare_test.go b/models/nameserver_compare_test.go index f843bb18..8ca37227 100644 --- a/models/nameserver_compare_test.go +++ b/models/nameserver_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestNameserverEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Nameserver var result Nameserver - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestNameserverEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Nameserver to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestNameserverEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Nameserver var result Nameserver - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestNameserverEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Nameserver to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestNameserverDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Nameserver var result Nameserver - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestNameserverDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Nameserver to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestNameserverDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Nameserver var result Nameserver - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestNameserverDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Nameserver to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/nameservers.go b/models/nameservers.go index bb4e5415..5c7d07c4 100644 --- a/models/nameservers.go +++ b/models/nameservers.go @@ -71,6 +71,11 @@ func (m Nameservers) ContextValidate(ctx context.Context, formats strfmt.Registr for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/native_stat.go b/models/native_stat.go index a78a4a37..bc86212e 100644 --- a/models/native_stat.go +++ b/models/native_stat.go @@ -47,7 +47,7 @@ type NativeStat struct { Stats *NativeStatStats `json:"stats,omitempty"` // type - // Enum: [backend server frontend] + // Enum: ["backend","server","frontend"] // +kubebuilder:validation:Enum=backend;server;frontend; Type string `json:"type,omitempty"` } @@ -151,6 +151,11 @@ func (m *NativeStat) ContextValidate(ctx context.Context, formats strfmt.Registr func (m *NativeStat) contextValidateStats(ctx context.Context, formats strfmt.Registry) error { if m.Stats != nil { + + if swag.IsZero(m.Stats) { // not required + return nil + } + if err := m.Stats.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("stats") diff --git a/models/native_stat_compare_test.go b/models/native_stat_compare_test.go index 1347c272..c65be41e 100644 --- a/models/native_stat_compare_test.go +++ b/models/native_stat_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestNativeStatEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample NativeStat var result NativeStat - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestNativeStatEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected NativeStat to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestNativeStatEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample NativeStat var result NativeStat - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b NativeStat @@ -94,11 +97,11 @@ func TestNativeStatEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected NativeStat to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestNativeStatDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample NativeStat var result NativeStat - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestNativeStatDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected NativeStat to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestNativeStatDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample NativeStat var result NativeStat - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b NativeStat @@ -173,11 +176,11 @@ func TestNativeStatDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected NativeStat to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/native_stat_stats.go b/models/native_stat_stats.go index fb390b42..f22bd4ee 100644 --- a/models/native_stat_stats.go +++ b/models/native_stat_stats.go @@ -61,7 +61,7 @@ type NativeStatStats struct { AgentRise *int64 `json:"agent_rise,omitempty"` // agent status - // Enum: [UNK INI SOCKERR L4OK L4TOUT L4CON L7OK L7STS] + // Enum: ["UNK","INI","SOCKERR","L4OK","L4TOUT","L4CON","L7OK","L7STS"] // +kubebuilder:validation:Enum=UNK;INI;SOCKERR;L4OK;L4TOUT;L4CON;L7OK;L7STS; AgentStatus string `json:"agent_status,omitempty"` @@ -96,7 +96,7 @@ type NativeStatStats struct { CheckRise *int64 `json:"check_rise,omitempty"` // check status - // Enum: [UNK INI SOCKERR L4OK L4TOUT L4CON L6OK L6TOUT L6RSP L7OK L7OKC L7TOUT L7RSP L7STS] + // Enum: ["UNK","INI","SOCKERR","L4OK","L4TOUT","L4CON","L6OK","L6TOUT","L6RSP","L7OK","L7OKC","L7TOUT","L7RSP","L7STS"] // +kubebuilder:validation:Enum=UNK;INI;SOCKERR;L4OK;L4TOUT;L4CON;L6OK;L6TOUT;L6RSP;L7OK;L7OKC;L7TOUT;L7RSP;L7STS; CheckStatus string `json:"check_status,omitempty"` @@ -203,7 +203,7 @@ type NativeStatStats struct { Lbtot *int64 `json:"lbtot,omitempty"` // mode - // Enum: [tcp http health unknown] + // Enum: ["tcp","http","health","unknown"] // +kubebuilder:validation:Enum=tcp;http;health;unknown; Mode string `json:"mode,omitempty"` @@ -259,8 +259,8 @@ type NativeStatStats struct { SrvAbrt *int64 `json:"srv_abrt,omitempty"` // status - // Enum: [UP DOWN NOLB MAINT no check] - // +kubebuilder:validation:Enum=UP;DOWN;NOLB;MAINT;no;check; + // Enum: ["UP","DOWN","NOLB","MAINT","no check"] + // +kubebuilder:validation:Enum=UP;DOWN;NOLB;MAINT;no check; Status string `json:"status,omitempty"` // stot diff --git a/models/native_stat_stats_compare_test.go b/models/native_stat_stats_compare_test.go index 786caf3e..7ad889c0 100644 --- a/models/native_stat_stats_compare_test.go +++ b/models/native_stat_stats_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestNativeStatStatsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample NativeStatStats var result NativeStatStats - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestNativeStatStatsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected NativeStatStats to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestNativeStatStatsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample NativeStatStats var result NativeStatStats - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Act = Ptr(*sample.Act + 1) result.AgentCode = Ptr(*sample.AgentCode + 1) @@ -161,11 +164,11 @@ func TestNativeStatStatsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected NativeStatStats to be different, but it is not %s %s", a, b) } @@ -179,17 +182,17 @@ func TestNativeStatStatsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample NativeStatStats var result NativeStatStats - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -203,11 +206,11 @@ func TestNativeStatStatsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected NativeStatStats to be equal, but it is not %s %s, %v", a, b, result) } @@ -221,13 +224,13 @@ func TestNativeStatStatsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample NativeStatStats var result NativeStatStats - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Act = Ptr(*sample.Act + 1) result.AgentCode = Ptr(*sample.AgentCode + 1) @@ -307,11 +310,11 @@ func TestNativeStatStatsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected NativeStatStats to be different in 80 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/native_stats.go b/models/native_stats.go index 8c176392..7cf2c237 100644 --- a/models/native_stats.go +++ b/models/native_stats.go @@ -105,6 +105,11 @@ func (m *NativeStats) contextValidateStats(ctx context.Context, formats strfmt.R for i := 0; i < len(m.Stats); i++ { if m.Stats[i] != nil { + + if swag.IsZero(m.Stats[i]) { // not required + return nil + } + if err := m.Stats[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("stats" + "." + strconv.Itoa(i)) diff --git a/models/native_stats_compare_test.go b/models/native_stats_compare_test.go index 95b7c20f..9c25d3d5 100644 --- a/models/native_stats_compare_test.go +++ b/models/native_stats_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestNativeStatsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample NativeStats var result NativeStats - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestNativeStatsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected NativeStats to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestNativeStatsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample NativeStats var result NativeStats - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b NativeStats @@ -94,11 +97,11 @@ func TestNativeStatsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected NativeStats to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestNativeStatsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample NativeStats var result NativeStats - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestNativeStatsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected NativeStats to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestNativeStatsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample NativeStats var result NativeStats - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b NativeStats @@ -173,11 +176,11 @@ func TestNativeStatsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected NativeStats to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/ocsp_update_options.go b/models/ocsp_update_options.go index bfebc6e0..0a8645a2 100644 --- a/models/ocsp_update_options.go +++ b/models/ocsp_update_options.go @@ -48,7 +48,7 @@ type OcspUpdateOptions struct { Mindelay *int64 `json:"mindelay,omitempty"` // mode - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Mode string `json:"mode,omitempty"` } @@ -149,6 +149,11 @@ func (m *OcspUpdateOptions) ContextValidate(ctx context.Context, formats strfmt. func (m *OcspUpdateOptions) contextValidateHttpproxy(ctx context.Context, formats strfmt.Registry) error { if m.Httpproxy != nil { + + if swag.IsZero(m.Httpproxy) { // not required + return nil + } + if err := m.Httpproxy.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("httpproxy") diff --git a/models/ocsp_update_options_compare_test.go b/models/ocsp_update_options_compare_test.go index 7756eb35..e3647b93 100644 --- a/models/ocsp_update_options_compare_test.go +++ b/models/ocsp_update_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestOcspUpdateOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample OcspUpdateOptions var result OcspUpdateOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestOcspUpdateOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected OcspUpdateOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestOcspUpdateOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample OcspUpdateOptions var result OcspUpdateOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Disable = Ptr(!*sample.Disable) result.Maxdelay = Ptr(*sample.Maxdelay + 1) @@ -97,11 +100,11 @@ func TestOcspUpdateOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected OcspUpdateOptions to be different, but it is not %s %s", a, b) } @@ -115,17 +118,17 @@ func TestOcspUpdateOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample OcspUpdateOptions var result OcspUpdateOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -139,11 +142,11 @@ func TestOcspUpdateOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected OcspUpdateOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -157,13 +160,13 @@ func TestOcspUpdateOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample OcspUpdateOptions var result OcspUpdateOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Disable = Ptr(!*sample.Disable) result.Maxdelay = Ptr(*sample.Maxdelay + 1) @@ -179,11 +182,11 @@ func TestOcspUpdateOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected OcspUpdateOptions to be different in 5 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -197,17 +200,17 @@ func TestOcspUpdateOptionsHttpproxyEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample OcspUpdateOptionsHttpproxy var result OcspUpdateOptionsHttpproxy - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -221,11 +224,11 @@ func TestOcspUpdateOptionsHttpproxyEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected OcspUpdateOptionsHttpproxy to be equal, but it is not %s %s", a, b) } @@ -239,13 +242,13 @@ func TestOcspUpdateOptionsHttpproxyEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample OcspUpdateOptionsHttpproxy var result OcspUpdateOptionsHttpproxy - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) samples = append(samples, struct { @@ -259,11 +262,11 @@ func TestOcspUpdateOptionsHttpproxyEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected OcspUpdateOptionsHttpproxy to be different, but it is not %s %s", a, b) } @@ -277,17 +280,17 @@ func TestOcspUpdateOptionsHttpproxyDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample OcspUpdateOptionsHttpproxy var result OcspUpdateOptionsHttpproxy - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -301,11 +304,11 @@ func TestOcspUpdateOptionsHttpproxyDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected OcspUpdateOptionsHttpproxy to be equal, but it is not %s %s, %v", a, b, result) } @@ -319,13 +322,13 @@ func TestOcspUpdateOptionsHttpproxyDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample OcspUpdateOptionsHttpproxy var result OcspUpdateOptionsHttpproxy - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) samples = append(samples, struct { @@ -339,11 +342,11 @@ func TestOcspUpdateOptionsHttpproxyDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected OcspUpdateOptionsHttpproxy to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/originalto.go b/models/originalto.go index 5b7f9cb1..739d5945 100644 --- a/models/originalto.go +++ b/models/originalto.go @@ -36,7 +36,7 @@ import ( type Originalto struct { // enabled // Required: true - // Enum: [enabled] + // Enum: ["enabled"] // +kubebuilder:validation:Enum=enabled; Enabled *string `json:"enabled"` diff --git a/models/originalto_compare_test.go b/models/originalto_compare_test.go index f43f9c21..16719754 100644 --- a/models/originalto_compare_test.go +++ b/models/originalto_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestOriginaltoEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Originalto var result Originalto - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestOriginaltoEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Originalto to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestOriginaltoEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Originalto var result Originalto - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Originalto @@ -94,11 +97,11 @@ func TestOriginaltoEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Originalto to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestOriginaltoDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Originalto var result Originalto - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestOriginaltoDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Originalto to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestOriginaltoDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Originalto var result Originalto - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Originalto @@ -173,11 +176,11 @@ func TestOriginaltoDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Originalto to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/peer_entries.go b/models/peer_entries.go index 9e2fb76b..6c9e79a4 100644 --- a/models/peer_entries.go +++ b/models/peer_entries.go @@ -71,6 +71,11 @@ func (m PeerEntries) ContextValidate(ctx context.Context, formats strfmt.Registr for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/peer_entry_compare_test.go b/models/peer_entry_compare_test.go index 59768916..dcbbb5c7 100644 --- a/models/peer_entry_compare_test.go +++ b/models/peer_entry_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestPeerEntryEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample PeerEntry var result PeerEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestPeerEntryEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PeerEntry to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestPeerEntryEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample PeerEntry var result PeerEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) result.Shard = sample.Shard + 1 @@ -96,11 +99,11 @@ func TestPeerEntryEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PeerEntry to be different, but it is not %s %s", a, b) } @@ -114,17 +117,17 @@ func TestPeerEntryDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample PeerEntry var result PeerEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -138,11 +141,11 @@ func TestPeerEntryDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PeerEntry to be equal, but it is not %s %s, %v", a, b, result) } @@ -156,13 +159,13 @@ func TestPeerEntryDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample PeerEntry var result PeerEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) result.Shard = sample.Shard + 1 @@ -177,11 +180,11 @@ func TestPeerEntryDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PeerEntry to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/peer_section.go b/models/peer_section.go index d41cb921..24dc9d69 100644 --- a/models/peer_section.go +++ b/models/peer_section.go @@ -46,6 +46,9 @@ type PeerSection struct { // servers Servers map[string]Server `json:"servers,omitempty"` + + // tables + Tables map[string]Table `json:"tables,omitempty"` } // UnmarshalJSON unmarshals this object from a JSON structure @@ -66,6 +69,8 @@ func (m *PeerSection) UnmarshalJSON(raw []byte) error { PeerEntries map[string]PeerEntry `json:"peer_entries,omitempty"` Servers map[string]Server `json:"servers,omitempty"` + + Tables map[string]Table `json:"tables,omitempty"` } if err := swag.ReadJSON(raw, &dataAO1); err != nil { return err @@ -79,6 +84,8 @@ func (m *PeerSection) UnmarshalJSON(raw []byte) error { m.Servers = dataAO1.Servers + m.Tables = dataAO1.Tables + return nil } @@ -99,6 +106,8 @@ func (m PeerSection) MarshalJSON() ([]byte, error) { PeerEntries map[string]PeerEntry `json:"peer_entries,omitempty"` Servers map[string]Server `json:"servers,omitempty"` + + Tables map[string]Table `json:"tables,omitempty"` } dataAO1.LogTargetList = m.LogTargetList @@ -109,6 +118,8 @@ func (m PeerSection) MarshalJSON() ([]byte, error) { dataAO1.Servers = m.Servers + dataAO1.Tables = m.Tables + jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1) if errAO1 != nil { return nil, errAO1 @@ -142,6 +153,10 @@ func (m *PeerSection) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateTables(formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -247,6 +262,33 @@ func (m *PeerSection) validateServers(formats strfmt.Registry) error { return nil } +func (m *PeerSection) validateTables(formats strfmt.Registry) error { + + if swag.IsZero(m.Tables) { // not required + return nil + } + + for k := range m.Tables { + + if err := validate.Required("tables"+"."+k, "body", m.Tables[k]); err != nil { + return err + } + if val, ok := m.Tables[k]; ok { + if err := val.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("tables" + "." + k) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("tables" + "." + k) + } + return err + } + } + + } + + return nil +} + // ContextValidate validate this peer section based on the context it is used func (m *PeerSection) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error @@ -272,6 +314,10 @@ func (m *PeerSection) ContextValidate(ctx context.Context, formats strfmt.Regist res = append(res, err) } + if err := m.contextValidateTables(ctx, formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -337,6 +383,21 @@ func (m *PeerSection) contextValidateServers(ctx context.Context, formats strfmt return nil } +func (m *PeerSection) contextValidateTables(ctx context.Context, formats strfmt.Registry) error { + + for k := range m.Tables { + + if val, ok := m.Tables[k]; ok { + if err := val.ContextValidate(ctx, formats); err != nil { + return err + } + } + + } + + return nil +} + // MarshalBinary interface implementation func (m *PeerSection) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/models/peer_section_base.go b/models/peer_section_base.go index 5902ccd1..345bd77e 100644 --- a/models/peer_section_base.go +++ b/models/peer_section_base.go @@ -155,6 +155,11 @@ func (m *PeerSectionBase) ContextValidate(ctx context.Context, formats strfmt.Re func (m *PeerSectionBase) contextValidateDefaultBind(ctx context.Context, formats strfmt.Registry) error { if m.DefaultBind != nil { + + if swag.IsZero(m.DefaultBind) { // not required + return nil + } + if err := m.DefaultBind.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("default_bind") @@ -171,6 +176,11 @@ func (m *PeerSectionBase) contextValidateDefaultBind(ctx context.Context, format func (m *PeerSectionBase) contextValidateDefaultServer(ctx context.Context, formats strfmt.Registry) error { if m.DefaultServer != nil { + + if swag.IsZero(m.DefaultServer) { // not required + return nil + } + if err := m.DefaultServer.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("default_server") diff --git a/models/peer_section_base_compare_test.go b/models/peer_section_base_compare_test.go index b4e8be98..eca9addc 100644 --- a/models/peer_section_base_compare_test.go +++ b/models/peer_section_base_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestPeerSectionBaseEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample PeerSectionBase var result PeerSectionBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestPeerSectionBaseEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PeerSectionBase to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestPeerSectionBaseEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample PeerSectionBase var result PeerSectionBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Disabled = !sample.Disabled result.Enabled = !sample.Enabled @@ -97,11 +100,11 @@ func TestPeerSectionBaseEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PeerSectionBase to be different, but it is not %s %s", a, b) } @@ -115,17 +118,17 @@ func TestPeerSectionBaseDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample PeerSectionBase var result PeerSectionBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -139,11 +142,11 @@ func TestPeerSectionBaseDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PeerSectionBase to be equal, but it is not %s %s, %v", a, b, result) } @@ -157,13 +160,13 @@ func TestPeerSectionBaseDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample PeerSectionBase var result PeerSectionBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Disabled = !sample.Disabled result.Enabled = !sample.Enabled @@ -179,11 +182,11 @@ func TestPeerSectionBaseDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PeerSectionBase to be different in 6 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/peer_section_compare.go b/models/peer_section_compare.go index 2c702f81..f3120971 100644 --- a/models/peer_section_compare.go +++ b/models/peer_section_compare.go @@ -71,6 +71,16 @@ func (s PeerSection) Equal(t PeerSection, opts ...Options) bool { } } + if !CheckSameNilAndLenMap[string, Table](s.Tables, t.Tables, opt) { + return false + } + + for k, v := range s.Tables { + if !t.Tables[k].Equal(v, opt) { + return false + } + } + return true } @@ -130,5 +140,15 @@ func (s PeerSection) Diff(t PeerSection, opts ...Options) map[string][]interface } } + if !CheckSameNilAndLenMap[string, Table](s.Tables, t.Tables, opt) { + diff["Tables"] = []interface{}{s.Tables, t.Tables} + } + + for k, v := range s.Tables { + if !t.Tables[k].Equal(v, opt) { + diff["Tables"] = []interface{}{s.Tables, t.Tables} + } + } + return diff } diff --git a/models/peer_section_compare_test.go b/models/peer_section_compare_test.go index 7d22426d..a542dcf6 100644 --- a/models/peer_section_compare_test.go +++ b/models/peer_section_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestPeerSectionEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample PeerSection var result PeerSection - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestPeerSectionEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PeerSection to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestPeerSectionEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample PeerSection var result PeerSection - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b PeerSection @@ -94,11 +97,11 @@ func TestPeerSectionEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PeerSection to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestPeerSectionDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample PeerSection var result PeerSection - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestPeerSectionDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PeerSection to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestPeerSectionDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample PeerSection var result PeerSection - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b PeerSection @@ -169,17 +172,17 @@ func TestPeerSectionDiffFalse(t *testing.T) { for _, sample := range samples { result := sample.a.Diff(sample.b) - if len(result) != 5 { + if len(result) != 6 { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - t.Errorf("Expected PeerSection to be different in 5 cases, but it is not (%d) %s %s", len(result), a, b) + t.Errorf("Expected PeerSection to be different in 6 cases, but it is not (%d) %s %s", len(result), a, b) } } } diff --git a/models/peer_sections.go b/models/peer_sections.go index e82195d9..f92a9206 100644 --- a/models/peer_sections.go +++ b/models/peer_sections.go @@ -71,6 +71,11 @@ func (m PeerSections) ContextValidate(ctx context.Context, formats strfmt.Regist for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/performance_options.go b/models/performance_options.go index f848270e..b381d15a 100644 --- a/models/performance_options.go +++ b/models/performance_options.go @@ -86,12 +86,12 @@ type PerformanceOptions struct { Nosplice bool `json:"nosplice,omitempty"` // profiling memory - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ProfilingMemory string `json:"profiling_memory,omitempty"` // profiling tasks - // Enum: [auto enabled disabled] + // Enum: ["auto","enabled","disabled"] // +kubebuilder:validation:Enum=auto;enabled;disabled; ProfilingTasks string `json:"profiling_tasks,omitempty"` diff --git a/models/performance_options_compare_test.go b/models/performance_options_compare_test.go index 4ae640c4..ca493e90 100644 --- a/models/performance_options_compare_test.go +++ b/models/performance_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestPerformanceOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample PerformanceOptions var result PerformanceOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestPerformanceOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PerformanceOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestPerformanceOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample PerformanceOptions var result PerformanceOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.BusyPolling = !sample.BusyPolling result.MaxSpreadChecks = Ptr(*sample.MaxSpreadChecks + 1) @@ -112,11 +115,11 @@ func TestPerformanceOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PerformanceOptions to be different, but it is not %s %s", a, b) } @@ -130,17 +133,17 @@ func TestPerformanceOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample PerformanceOptions var result PerformanceOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -154,11 +157,11 @@ func TestPerformanceOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PerformanceOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -172,13 +175,13 @@ func TestPerformanceOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample PerformanceOptions var result PerformanceOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.BusyPolling = !sample.BusyPolling result.MaxSpreadChecks = Ptr(*sample.MaxSpreadChecks + 1) @@ -209,11 +212,11 @@ func TestPerformanceOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PerformanceOptions to be different in 22 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/persist_rule.go b/models/persist_rule.go index b4133f68..b1000792 100644 --- a/models/persist_rule.go +++ b/models/persist_rule.go @@ -41,7 +41,7 @@ type PersistRule struct { // type // Required: true - // Enum: [rdp-cookie] + // Enum: ["rdp-cookie"] // +kubebuilder:validation:Enum=rdp-cookie; Type *string `json:"type"` } diff --git a/models/persist_rule_compare_test.go b/models/persist_rule_compare_test.go index 644b7c0f..b364e811 100644 --- a/models/persist_rule_compare_test.go +++ b/models/persist_rule_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestPersistRuleEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample PersistRule var result PersistRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestPersistRuleEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PersistRule to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestPersistRuleEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample PersistRule var result PersistRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b PersistRule @@ -94,11 +97,11 @@ func TestPersistRuleEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PersistRule to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestPersistRuleDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample PersistRule var result PersistRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestPersistRuleDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PersistRule to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestPersistRuleDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample PersistRule var result PersistRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b PersistRule @@ -173,11 +176,11 @@ func TestPersistRuleDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PersistRule to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/pgsql_check_params_compare_test.go b/models/pgsql_check_params_compare_test.go index dfb56eb5..2dfadf9a 100644 --- a/models/pgsql_check_params_compare_test.go +++ b/models/pgsql_check_params_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestPgsqlCheckParamsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample PgsqlCheckParams var result PgsqlCheckParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestPgsqlCheckParamsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PgsqlCheckParams to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestPgsqlCheckParamsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample PgsqlCheckParams var result PgsqlCheckParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b PgsqlCheckParams @@ -94,11 +97,11 @@ func TestPgsqlCheckParamsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PgsqlCheckParams to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestPgsqlCheckParamsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample PgsqlCheckParams var result PgsqlCheckParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestPgsqlCheckParamsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PgsqlCheckParams to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestPgsqlCheckParamsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample PgsqlCheckParams var result PgsqlCheckParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b PgsqlCheckParams @@ -173,11 +176,11 @@ func TestPgsqlCheckParamsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected PgsqlCheckParams to be different in 1 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/process_info.go b/models/process_info.go index 3890e1da..25f50feb 100644 --- a/models/process_info.go +++ b/models/process_info.go @@ -95,6 +95,11 @@ func (m *ProcessInfo) ContextValidate(ctx context.Context, formats strfmt.Regist func (m *ProcessInfo) contextValidateInfo(ctx context.Context, formats strfmt.Registry) error { if m.Info != nil { + + if swag.IsZero(m.Info) { // not required + return nil + } + if err := m.Info.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("info") diff --git a/models/process_info_compare_test.go b/models/process_info_compare_test.go index bc0c5f0d..6583ec62 100644 --- a/models/process_info_compare_test.go +++ b/models/process_info_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestProcessInfoEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ProcessInfo var result ProcessInfo - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestProcessInfoEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ProcessInfo to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestProcessInfoEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ProcessInfo var result ProcessInfo - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ProcessInfo @@ -94,11 +97,11 @@ func TestProcessInfoEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ProcessInfo to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestProcessInfoDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ProcessInfo var result ProcessInfo - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestProcessInfoDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ProcessInfo to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestProcessInfoDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ProcessInfo var result ProcessInfo - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ProcessInfo @@ -173,11 +176,11 @@ func TestProcessInfoDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ProcessInfo to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/process_info_item_compare_test.go b/models/process_info_item_compare_test.go index 8e5c29ff..a07c99f9 100644 --- a/models/process_info_item_compare_test.go +++ b/models/process_info_item_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -24,6 +26,7 @@ import ( "time" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" "github.com/go-openapi/strfmt" jsoniter "github.com/json-iterator/go" @@ -36,17 +39,17 @@ func TestProcessInfoItemEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ProcessInfoItem var result ProcessInfoItem - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -60,11 +63,11 @@ func TestProcessInfoItemEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ProcessInfoItem to be equal, but it is not %s %s", a, b) } @@ -78,13 +81,13 @@ func TestProcessInfoItemEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ProcessInfoItem var result ProcessInfoItem - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.ActivePeers = Ptr(*sample.ActivePeers + 1) result.BusyPolling = Ptr(*sample.BusyPolling + 1) @@ -155,11 +158,11 @@ func TestProcessInfoItemEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ProcessInfoItem to be different, but it is not %s %s", a, b) } @@ -173,17 +176,17 @@ func TestProcessInfoItemDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ProcessInfoItem var result ProcessInfoItem - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -197,11 +200,11 @@ func TestProcessInfoItemDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ProcessInfoItem to be equal, but it is not %s %s, %v", a, b, result) } @@ -215,13 +218,13 @@ func TestProcessInfoItemDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ProcessInfoItem var result ProcessInfoItem - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.ActivePeers = Ptr(*sample.ActivePeers + 1) result.BusyPolling = Ptr(*sample.BusyPolling + 1) @@ -292,11 +295,11 @@ func TestProcessInfoItemDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ProcessInfoItem to be different in 60 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/program.go b/models/program.go index 31359076..ae5552aa 100644 --- a/models/program.go +++ b/models/program.go @@ -52,7 +52,7 @@ type Program struct { Name string `json:"name"` // HAProxy stops and recreates child programs at reload. - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; StartOnReload string `json:"start-on-reload,omitempty"` diff --git a/models/program_compare_test.go b/models/program_compare_test.go index 4e39623d..15cd0f44 100644 --- a/models/program_compare_test.go +++ b/models/program_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestProgramEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Program var result Program - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestProgramEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Program to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestProgramEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Program var result Program - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Program @@ -94,11 +97,11 @@ func TestProgramEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Program to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestProgramDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Program var result Program - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestProgramDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Program to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestProgramDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Program var result Program - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Program @@ -173,11 +176,11 @@ func TestProgramDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Program to be different in 5 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/programs.go b/models/programs.go index fb915bdd..409de93a 100644 --- a/models/programs.go +++ b/models/programs.go @@ -69,6 +69,11 @@ func (m Programs) ContextValidate(ctx context.Context, formats strfmt.Registry) for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/redispatch.go b/models/redispatch.go index 925c3e4f..752684ea 100644 --- a/models/redispatch.go +++ b/models/redispatch.go @@ -36,12 +36,12 @@ import ( type Redispatch struct { // enabled // Required: true - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Enabled *string `json:"enabled"` // interval - Interval int64 `json:"interval,omitempty"` + Interval *int64 `json:"interval,omitempty"` } // Validate validates this redispatch diff --git a/models/redispatch_compare.go b/models/redispatch_compare.go index 91618ff0..c787c520 100644 --- a/models/redispatch_compare.go +++ b/models/redispatch_compare.go @@ -28,7 +28,7 @@ func (s Redispatch) Equal(t Redispatch, opts ...Options) bool { return false } - if s.Interval != t.Interval { + if !equalPointers(s.Interval, t.Interval) { return false } @@ -47,8 +47,8 @@ func (s Redispatch) Diff(t Redispatch, opts ...Options) map[string][]interface{} diff["Enabled"] = []interface{}{ValueOrNil(s.Enabled), ValueOrNil(t.Enabled)} } - if s.Interval != t.Interval { - diff["Interval"] = []interface{}{s.Interval, t.Interval} + if !equalPointers(s.Interval, t.Interval) { + diff["Interval"] = []interface{}{ValueOrNil(s.Interval), ValueOrNil(t.Interval)} } return diff diff --git a/models/redispatch_compare_test.go b/models/redispatch_compare_test.go index 7005b617..453f179e 100644 --- a/models/redispatch_compare_test.go +++ b/models/redispatch_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestRedispatchEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Redispatch var result Redispatch - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestRedispatchEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Redispatch to be equal, but it is not %s %s", a, b) } @@ -75,15 +78,15 @@ func TestRedispatchEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Redispatch var result Redispatch - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - result.Interval = sample.Interval + 1 + result.Interval = Ptr(*sample.Interval + 1) samples = append(samples, struct { a, b Redispatch }{sample, result}) @@ -95,11 +98,11 @@ func TestRedispatchEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Redispatch to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestRedispatchDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Redispatch var result Redispatch - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestRedispatchDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Redispatch to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,15 +158,15 @@ func TestRedispatchDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Redispatch var result Redispatch - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - result.Interval = sample.Interval + 1 + result.Interval = Ptr(*sample.Interval + 1) samples = append(samples, struct { a, b Redispatch }{sample, result}) @@ -175,11 +178,11 @@ func TestRedispatchDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Redispatch to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/reload.go b/models/reload.go index eeab876b..858d9150 100644 --- a/models/reload.go +++ b/models/reload.go @@ -49,7 +49,7 @@ type Reload struct { Response string `json:"response,omitempty"` // status - // Enum: [failed in_progress succeeded] + // Enum: ["failed","in_progress","succeeded"] // +kubebuilder:validation:Enum=failed;in_progress;succeeded; Status string `json:"status,omitempty"` } diff --git a/models/reload_compare_test.go b/models/reload_compare_test.go index a77f15cc..ae0aea9f 100644 --- a/models/reload_compare_test.go +++ b/models/reload_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestReloadEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Reload var result Reload - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestReloadEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Reload to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestReloadEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Reload var result Reload - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.ReloadTimestamp = sample.ReloadTimestamp + 1 samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestReloadEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Reload to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestReloadDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Reload var result Reload - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestReloadDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Reload to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestReloadDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Reload var result Reload - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.ReloadTimestamp = sample.ReloadTimestamp + 1 samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestReloadDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Reload to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/reloads.go b/models/reloads.go index 29932eae..27816469 100644 --- a/models/reloads.go +++ b/models/reloads.go @@ -71,6 +71,11 @@ func (m Reloads) ContextValidate(ctx context.Context, formats strfmt.Registry) e for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/resolver_base_compare_test.go b/models/resolver_base_compare_test.go index ed755a0b..d4bee752 100644 --- a/models/resolver_base_compare_test.go +++ b/models/resolver_base_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestResolverBaseEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ResolverBase var result ResolverBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestResolverBaseEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ResolverBase to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestResolverBaseEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ResolverBase var result ResolverBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.AcceptedPayloadSize = sample.AcceptedPayloadSize + 1 result.HoldNx = Ptr(*sample.HoldNx + 1) @@ -105,11 +108,11 @@ func TestResolverBaseEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ResolverBase to be different, but it is not %s %s", a, b) } @@ -123,17 +126,17 @@ func TestResolverBaseDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ResolverBase var result ResolverBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -147,11 +150,11 @@ func TestResolverBaseDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ResolverBase to be equal, but it is not %s %s, %v", a, b, result) } @@ -165,13 +168,13 @@ func TestResolverBaseDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ResolverBase var result ResolverBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.AcceptedPayloadSize = sample.AcceptedPayloadSize + 1 result.HoldNx = Ptr(*sample.HoldNx + 1) @@ -195,11 +198,11 @@ func TestResolverBaseDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ResolverBase to be different in 12 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/resolver_compare_test.go b/models/resolver_compare_test.go index 217db7b2..7f2dfb8c 100644 --- a/models/resolver_compare_test.go +++ b/models/resolver_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestResolverEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Resolver var result Resolver - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestResolverEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Resolver to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestResolverEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Resolver var result Resolver - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Resolver @@ -94,11 +97,11 @@ func TestResolverEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Resolver to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestResolverDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Resolver var result Resolver - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestResolverDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Resolver to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestResolverDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Resolver var result Resolver - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Resolver @@ -173,11 +176,11 @@ func TestResolverDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Resolver to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/resolvers.go b/models/resolvers.go index cd3e88ed..4c0e5977 100644 --- a/models/resolvers.go +++ b/models/resolvers.go @@ -71,6 +71,11 @@ func (m Resolvers) ContextValidate(ctx context.Context, formats strfmt.Registry) for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/return_header_compare_test.go b/models/return_header_compare_test.go index 357014c6..79687541 100644 --- a/models/return_header_compare_test.go +++ b/models/return_header_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestReturnHeaderEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ReturnHeader var result ReturnHeader - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestReturnHeaderEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ReturnHeader to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestReturnHeaderEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ReturnHeader var result ReturnHeader - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ReturnHeader @@ -94,11 +97,11 @@ func TestReturnHeaderEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ReturnHeader to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestReturnHeaderDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ReturnHeader var result ReturnHeader - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestReturnHeaderDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ReturnHeader to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestReturnHeaderDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ReturnHeader var result ReturnHeader - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ReturnHeader @@ -173,11 +176,11 @@ func TestReturnHeaderDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ReturnHeader to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/ring_base.go b/models/ring_base.go index b3207c34..4c9637c3 100644 --- a/models/ring_base.go +++ b/models/ring_base.go @@ -41,7 +41,7 @@ type RingBase struct { Description string `json:"description,omitempty"` // format - // Enum: [iso local raw rfc3164 rfc5424 short priority timed] + // Enum: ["iso","local","raw","rfc3164","rfc5424","short","priority","timed"] // +kubebuilder:validation:Enum=iso;local;raw;rfc3164;rfc5424;short;priority;timed; Format string `json:"format,omitempty"` diff --git a/models/ring_base_compare_test.go b/models/ring_base_compare_test.go index 72c23853..e3537e71 100644 --- a/models/ring_base_compare_test.go +++ b/models/ring_base_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestRingBaseEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample RingBase var result RingBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestRingBaseEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RingBase to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestRingBaseEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample RingBase var result RingBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Maxlen = Ptr(*sample.Maxlen + 1) result.Size = Ptr(*sample.Size + 1) @@ -98,11 +101,11 @@ func TestRingBaseEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RingBase to be different, but it is not %s %s", a, b) } @@ -116,17 +119,17 @@ func TestRingBaseDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample RingBase var result RingBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -140,11 +143,11 @@ func TestRingBaseDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RingBase to be equal, but it is not %s %s, %v", a, b, result) } @@ -158,13 +161,13 @@ func TestRingBaseDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample RingBase var result RingBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Maxlen = Ptr(*sample.Maxlen + 1) result.Size = Ptr(*sample.Size + 1) @@ -181,11 +184,11 @@ func TestRingBaseDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RingBase to be different in 7 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/ring_compare_test.go b/models/ring_compare_test.go index f65d33a1..43663e37 100644 --- a/models/ring_compare_test.go +++ b/models/ring_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestRingEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Ring var result Ring - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestRingEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Ring to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestRingEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Ring var result Ring - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Ring @@ -94,11 +97,11 @@ func TestRingEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Ring to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestRingDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Ring var result Ring - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestRingDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Ring to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestRingDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Ring var result Ring - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Ring @@ -173,11 +176,11 @@ func TestRingDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Ring to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/rings.go b/models/rings.go index 6edca484..8beed234 100644 --- a/models/rings.go +++ b/models/rings.go @@ -71,6 +71,11 @@ func (m Rings) ContextValidate(ctx context.Context, formats strfmt.Registry) err for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/runtime_add_server.go b/models/runtime_add_server.go index 6ee3eed2..32ed4da1 100644 --- a/models/runtime_add_server.go +++ b/models/runtime_add_server.go @@ -49,7 +49,7 @@ type RuntimeAddServer struct { AgentAddr string `json:"agent-addr,omitempty"` // agent check - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; AgentCheck string `json:"agent-check,omitempty"` @@ -77,17 +77,17 @@ type RuntimeAddServer struct { Alpn string `json:"alpn,omitempty"` // backup - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Backup string `json:"backup,omitempty"` // check - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Check string `json:"check,omitempty"` // check send proxy - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; CheckSendProxy string `json:"check-send-proxy,omitempty"` @@ -97,7 +97,7 @@ type RuntimeAddServer struct { CheckSni string `json:"check-sni,omitempty"` // check ssl - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; CheckSsl string `json:"check-ssl,omitempty"` @@ -112,7 +112,7 @@ type RuntimeAddServer struct { CheckProto string `json:"check_proto,omitempty"` // check via socks4 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; CheckViaSocks4 string `json:"check_via_socks4,omitempty"` @@ -142,27 +142,27 @@ type RuntimeAddServer struct { Fastinter *int64 `json:"fastinter,omitempty"` // force sslv3 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ForceSslv3 string `json:"force_sslv3,omitempty"` // force tlsv10 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ForceTlsv10 string `json:"force_tlsv10,omitempty"` // force tlsv11 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ForceTlsv11 string `json:"force_tlsv11,omitempty"` // force tlsv12 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ForceTlsv12 string `json:"force_tlsv12,omitempty"` // force tlsv13 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ForceTlsv13 string `json:"force_tlsv13,omitempty"` @@ -188,7 +188,7 @@ type RuntimeAddServer struct { Inter *int64 `json:"inter,omitempty"` // maintenance - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Maintenance string `json:"maintenance,omitempty"` @@ -206,27 +206,27 @@ type RuntimeAddServer struct { Name string `json:"name,omitempty"` // no sslv3 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; NoSslv3 string `json:"no_sslv3,omitempty"` // no tlsv10 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; NoTlsv10 string `json:"no_tlsv10,omitempty"` // no tlsv11 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; NoTlsv11 string `json:"no_tlsv11,omitempty"` // no tlsv12 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; NoTlsv12 string `json:"no_tlsv12,omitempty"` // no tlsv13 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; NoTlsv13 string `json:"no_tlsv13,omitempty"` @@ -234,22 +234,22 @@ type RuntimeAddServer struct { Npn string `json:"npn,omitempty"` // observe - // Enum: [layer4 layer7] + // Enum: ["layer4","layer7"] // +kubebuilder:validation:Enum=layer4;layer7; Observe string `json:"observe,omitempty"` // on error - // Enum: [fastinter fail-check sudden-death mark-down] + // Enum: ["fastinter","fail-check","sudden-death","mark-down"] // +kubebuilder:validation:Enum=fastinter;fail-check;sudden-death;mark-down; OnError string `json:"on-error,omitempty"` // on marked down - // Enum: [shutdown-sessions] + // Enum: ["shutdown-sessions"] // +kubebuilder:validation:Enum=shutdown-sessions; OnMarkedDown string `json:"on-marked-down,omitempty"` // on marked up - // Enum: [shutdown-backup-sessions] + // Enum: ["shutdown-backup-sessions"] // +kubebuilder:validation:Enum=shutdown-backup-sessions; OnMarkedUp string `json:"on-marked-up,omitempty"` @@ -284,22 +284,22 @@ type RuntimeAddServer struct { Rise *int64 `json:"rise,omitempty"` // send proxy - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SendProxy string `json:"send-proxy,omitempty"` // send proxy v2 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SendProxyV2 string `json:"send-proxy-v2,omitempty"` // send proxy v2 ssl - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SendProxyV2Ssl string `json:"send_proxy_v2_ssl,omitempty"` // send proxy v2 ssl cn - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SendProxyV2SslCn string `json:"send_proxy_v2_ssl_cn,omitempty"` @@ -317,7 +317,7 @@ type RuntimeAddServer struct { Source string `json:"source,omitempty"` // ssl - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Ssl string `json:"ssl,omitempty"` @@ -332,27 +332,27 @@ type RuntimeAddServer struct { SslCertificate string `json:"ssl_certificate,omitempty"` // ssl max ver - // Enum: [SSLv3 TLSv1.0 TLSv1.1 TLSv1.2 TLSv1.3] + // Enum: ["SSLv3","TLSv1.0","TLSv1.1","TLSv1.2","TLSv1.3"] // +kubebuilder:validation:Enum=SSLv3;TLSv1.0;TLSv1.1;TLSv1.2;TLSv1.3; SslMaxVer string `json:"ssl_max_ver,omitempty"` // ssl min ver - // Enum: [SSLv3 TLSv1.0 TLSv1.1 TLSv1.2 TLSv1.3] + // Enum: ["SSLv3","TLSv1.0","TLSv1.1","TLSv1.2","TLSv1.3"] // +kubebuilder:validation:Enum=SSLv3;TLSv1.0;TLSv1.1;TLSv1.2;TLSv1.3; SslMinVer string `json:"ssl_min_ver,omitempty"` // ssl reuse - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SslReuse string `json:"ssl_reuse,omitempty"` // tfo - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Tfo string `json:"tfo,omitempty"` // tls tickets - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; TLSTickets string `json:"tls_tickets,omitempty"` @@ -360,7 +360,7 @@ type RuntimeAddServer struct { Track string `json:"track,omitempty"` // verify - // Enum: [none required] + // Enum: ["none","required"] // +kubebuilder:validation:Enum=none;required; Verify string `json:"verify,omitempty"` @@ -371,7 +371,7 @@ type RuntimeAddServer struct { Weight *int64 `json:"weight,omitempty"` // ws - // Enum: [auto h1 h2] + // Enum: ["auto","h1","h2"] // +kubebuilder:validation:Enum=auto;h1;h2; Ws string `json:"ws,omitempty"` } diff --git a/models/runtime_add_server_compare_test.go b/models/runtime_add_server_compare_test.go index 0694f871..70ae647b 100644 --- a/models/runtime_add_server_compare_test.go +++ b/models/runtime_add_server_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestRuntimeAddServerEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample RuntimeAddServer var result RuntimeAddServer - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestRuntimeAddServerEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RuntimeAddServer to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestRuntimeAddServerEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample RuntimeAddServer var result RuntimeAddServer - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.AgentInter = Ptr(*sample.AgentInter + 1) result.AgentPort = Ptr(*sample.AgentPort + 1) @@ -113,11 +116,11 @@ func TestRuntimeAddServerEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RuntimeAddServer to be different, but it is not %s %s", a, b) } @@ -131,17 +134,17 @@ func TestRuntimeAddServerDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample RuntimeAddServer var result RuntimeAddServer - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -155,11 +158,11 @@ func TestRuntimeAddServerDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RuntimeAddServer to be equal, but it is not %s %s, %v", a, b, result) } @@ -173,13 +176,13 @@ func TestRuntimeAddServerDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample RuntimeAddServer var result RuntimeAddServer - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.AgentInter = Ptr(*sample.AgentInter + 1) result.AgentPort = Ptr(*sample.AgentPort + 1) @@ -211,11 +214,11 @@ func TestRuntimeAddServerDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RuntimeAddServer to be different in 74 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/runtime_server.go b/models/runtime_server.go index 847bdd69..8afd71b3 100644 --- a/models/runtime_server.go +++ b/models/runtime_server.go @@ -44,7 +44,7 @@ type RuntimeServer struct { Address string `json:"address,omitempty"` // admin state - // Enum: [ready maint drain] + // Enum: ["ready","maint","drain"] // +kubebuilder:validation:Enum=ready;maint;drain; AdminState string `json:"admin_state,omitempty"` @@ -57,7 +57,7 @@ type RuntimeServer struct { Name string `json:"name,omitempty"` // operational state - // Enum: [up down stopping] + // Enum: ["up","down","stopping"] // +kubebuilder:validation:Enum=up;down;stopping; OperationalState string `json:"operational_state,omitempty"` diff --git a/models/runtime_server_compare_test.go b/models/runtime_server_compare_test.go index 4e960d22..a07fcc51 100644 --- a/models/runtime_server_compare_test.go +++ b/models/runtime_server_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestRuntimeServerEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample RuntimeServer var result RuntimeServer - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestRuntimeServerEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RuntimeServer to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestRuntimeServerEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample RuntimeServer var result RuntimeServer - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestRuntimeServerEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RuntimeServer to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestRuntimeServerDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample RuntimeServer var result RuntimeServer - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestRuntimeServerDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RuntimeServer to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestRuntimeServerDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample RuntimeServer var result RuntimeServer - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = Ptr(*sample.Port + 1) samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestRuntimeServerDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected RuntimeServer to be different in 6 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/runtime_servers.go b/models/runtime_servers.go index 14c34895..d7b5a3cf 100644 --- a/models/runtime_servers.go +++ b/models/runtime_servers.go @@ -71,6 +71,11 @@ func (m RuntimeServers) ContextValidate(ctx context.Context, formats strfmt.Regi for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/server.go b/models/server.go index 290d6582..bc7f6029 100644 --- a/models/server.go +++ b/models/server.go @@ -47,6 +47,10 @@ type Server struct { // id ID *int64 `json:"id,omitempty"` + // +kubebuilder:pruning:PreserveUnknownFields + // +kubebuilder:validation:Schemaless + Metadata map[string]interface{} `json:"metadata,omitempty"` + // name // Required: true // Pattern: ^[^\s]+$ @@ -76,6 +80,8 @@ func (m *Server) UnmarshalJSON(raw []byte) error { ID *int64 `json:"id,omitempty"` + Metadata map[string]interface{} `json:"metadata,omitempty"` + Name string `json:"name"` Port *int64 `json:"port,omitempty"` @@ -88,6 +94,8 @@ func (m *Server) UnmarshalJSON(raw []byte) error { m.ID = dataAO1.ID + m.Metadata = dataAO1.Metadata + m.Name = dataAO1.Name m.Port = dataAO1.Port @@ -109,6 +117,8 @@ func (m Server) MarshalJSON() ([]byte, error) { ID *int64 `json:"id,omitempty"` + Metadata map[string]interface{} `json:"metadata,omitempty"` + Name string `json:"name"` Port *int64 `json:"port,omitempty"` @@ -118,6 +128,8 @@ func (m Server) MarshalJSON() ([]byte, error) { dataAO1.ID = m.ID + dataAO1.Metadata = m.Metadata + dataAO1.Name = m.Name dataAO1.Port = m.Port diff --git a/models/server_compare.go b/models/server_compare.go index 54efdace..a9dacd73 100644 --- a/models/server_compare.go +++ b/models/server_compare.go @@ -17,6 +17,8 @@ package models +import "reflect" + // Equal checks if two structs of type Server are equal // // By default empty maps and slices are equal to nil: @@ -45,6 +47,16 @@ func (s Server) Equal(t Server, opts ...Options) bool { return false } + if !CheckSameNilAndLenMap[string](s.Metadata, t.Metadata, opt) { + return false + } + + for k, v := range s.Metadata { + if !reflect.DeepEqual(t.Metadata[k], v) { + return false + } + } + if s.Name != t.Name { return false } @@ -86,6 +98,16 @@ func (s Server) Diff(t Server, opts ...Options) map[string][]interface{} { diff["ID"] = []interface{}{ValueOrNil(s.ID), ValueOrNil(t.ID)} } + if !CheckSameNilAndLenMap[string](s.Metadata, t.Metadata, opt) { + diff["Metadata"] = []interface{}{s.Metadata, t.Metadata} + } + + for k, v := range s.Metadata { + if !reflect.DeepEqual(t.Metadata[k], v) { + diff["Metadata"] = []interface{}{s.Metadata, t.Metadata} + } + } + if s.Name != t.Name { diff["Name"] = []interface{}{s.Name, t.Name} } diff --git a/models/server_compare_test.go b/models/server_compare_test.go index 64474ee2..483fad29 100644 --- a/models/server_compare_test.go +++ b/models/server_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestServerEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Server var result Server - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestServerEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Server to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestServerEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Server var result Server - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.ID = Ptr(*sample.ID + 1) result.Port = Ptr(*sample.Port + 1) @@ -96,11 +99,11 @@ func TestServerEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Server to be different, but it is not %s %s", a, b) } @@ -114,17 +117,17 @@ func TestServerDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Server var result Server - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -138,11 +141,11 @@ func TestServerDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Server to be equal, but it is not %s %s, %v", a, b, result) } @@ -156,13 +159,13 @@ func TestServerDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Server var result Server - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.ID = Ptr(*sample.ID + 1) result.Port = Ptr(*sample.Port + 1) @@ -177,11 +180,11 @@ func TestServerDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Server to be different in 5 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/server_params.go b/models/server_params.go index 461f7b7f..fed9c898 100644 --- a/models/server_params.go +++ b/models/server_params.go @@ -41,7 +41,7 @@ type ServerParams struct { AgentAddr string `json:"agent-addr,omitempty"` // agent check - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; AgentCheck string `json:"agent-check,omitempty"` @@ -69,17 +69,17 @@ type ServerParams struct { Alpn string `json:"alpn,omitempty"` // backup - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Backup string `json:"backup,omitempty"` // check - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Check string `json:"check,omitempty"` // check send proxy - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; CheckSendProxy string `json:"check-send-proxy,omitempty"` @@ -89,7 +89,7 @@ type ServerParams struct { CheckSni string `json:"check-sni,omitempty"` // check ssl - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; CheckSsl string `json:"check-ssl,omitempty"` @@ -104,7 +104,7 @@ type ServerParams struct { CheckProto string `json:"check_proto,omitempty"` // check via socks4 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; CheckViaSocks4 string `json:"check_via_socks4,omitempty"` @@ -145,27 +145,27 @@ type ServerParams struct { Fastinter *int64 `json:"fastinter,omitempty"` // force sslv3 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ForceSslv3 string `json:"force_sslv3,omitempty"` // force tlsv10 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ForceTlsv10 string `json:"force_tlsv10,omitempty"` // force tlsv11 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ForceTlsv11 string `json:"force_tlsv11,omitempty"` // force tlsv12 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ForceTlsv12 string `json:"force_tlsv12,omitempty"` // force tlsv13 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ForceTlsv13 string `json:"force_tlsv13,omitempty"` @@ -205,12 +205,12 @@ type ServerParams struct { LogBufsize *int64 `json:"log-bufsize,omitempty"` // log proto - // Enum: [legacy octet-count] + // Enum: ["legacy","octet-count"] // +kubebuilder:validation:Enum=legacy;octet-count; LogProto string `json:"log_proto,omitempty"` // maintenance - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Maintenance string `json:"maintenance,omitempty"` @@ -230,32 +230,32 @@ type ServerParams struct { Namespace string `json:"namespace,omitempty"` // no sslv3 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; NoSslv3 string `json:"no_sslv3,omitempty"` // no tlsv10 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; NoTlsv10 string `json:"no_tlsv10,omitempty"` // no tlsv11 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; NoTlsv11 string `json:"no_tlsv11,omitempty"` // no tlsv12 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; NoTlsv12 string `json:"no_tlsv12,omitempty"` // no tlsv13 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; NoTlsv13 string `json:"no_tlsv13,omitempty"` // no verifyhost - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; NoVerifyhost string `json:"no_verifyhost,omitempty"` @@ -263,22 +263,22 @@ type ServerParams struct { Npn string `json:"npn,omitempty"` // observe - // Enum: [layer4 layer7] + // Enum: ["layer4","layer7"] // +kubebuilder:validation:Enum=layer4;layer7; Observe string `json:"observe,omitempty"` // on error - // Enum: [fastinter fail-check sudden-death mark-down] + // Enum: ["fastinter","fail-check","sudden-death","mark-down"] // +kubebuilder:validation:Enum=fastinter;fail-check;sudden-death;mark-down; OnError string `json:"on-error,omitempty"` // on marked down - // Enum: [shutdown-sessions] + // Enum: ["shutdown-sessions"] // +kubebuilder:validation:Enum=shutdown-sessions; OnMarkedDown string `json:"on-marked-down,omitempty"` // on marked up - // Enum: [shutdown-backup-sessions] + // Enum: ["shutdown-backup-sessions"] // +kubebuilder:validation:Enum=shutdown-backup-sessions; OnMarkedUp string `json:"on-marked-up,omitempty"` @@ -315,7 +315,7 @@ type ServerParams struct { ResolveNet string `json:"resolve-net,omitempty"` // resolve prefer - // Enum: [ipv4 ipv6] + // Enum: ["ipv4","ipv6"] // +kubebuilder:validation:Enum=ipv4;ipv6; ResolvePrefer string `json:"resolve-prefer,omitempty"` @@ -333,22 +333,22 @@ type ServerParams struct { Rise *int64 `json:"rise,omitempty"` // send proxy - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SendProxy string `json:"send-proxy,omitempty"` // send proxy v2 - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SendProxyV2 string `json:"send-proxy-v2,omitempty"` // send proxy v2 ssl - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SendProxyV2Ssl string `json:"send_proxy_v2_ssl,omitempty"` // send proxy v2 ssl cn - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SendProxyV2SslCn string `json:"send_proxy_v2_ssl_cn,omitempty"` @@ -380,7 +380,7 @@ type ServerParams struct { Source string `json:"source,omitempty"` // ssl - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Ssl string `json:"ssl,omitempty"` @@ -395,22 +395,22 @@ type ServerParams struct { SslCertificate string `json:"ssl_certificate,omitempty"` // ssl max ver - // Enum: [SSLv3 TLSv1.0 TLSv1.1 TLSv1.2 TLSv1.3] + // Enum: ["SSLv3","TLSv1.0","TLSv1.1","TLSv1.2","TLSv1.3"] // +kubebuilder:validation:Enum=SSLv3;TLSv1.0;TLSv1.1;TLSv1.2;TLSv1.3; SslMaxVer string `json:"ssl_max_ver,omitempty"` // ssl min ver - // Enum: [SSLv3 TLSv1.0 TLSv1.1 TLSv1.2 TLSv1.3] + // Enum: ["SSLv3","TLSv1.0","TLSv1.1","TLSv1.2","TLSv1.3"] // +kubebuilder:validation:Enum=SSLv3;TLSv1.0;TLSv1.1;TLSv1.2;TLSv1.3; SslMinVer string `json:"ssl_min_ver,omitempty"` // ssl reuse - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SslReuse string `json:"ssl_reuse,omitempty"` // stick - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Stick string `json:"stick,omitempty"` @@ -420,12 +420,12 @@ type ServerParams struct { TCPUt *int64 `json:"tcp_ut,omitempty"` // tfo - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Tfo string `json:"tfo,omitempty"` // tls tickets - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; TLSTickets string `json:"tls_tickets,omitempty"` @@ -433,7 +433,7 @@ type ServerParams struct { Track string `json:"track,omitempty"` // verify - // Enum: [none required] + // Enum: ["none","required"] // +kubebuilder:validation:Enum=none;required; Verify string `json:"verify,omitempty"` @@ -444,7 +444,7 @@ type ServerParams struct { Weight *int64 `json:"weight,omitempty"` // ws - // Enum: [auto h1 h2] + // Enum: ["auto","h1","h2"] // +kubebuilder:validation:Enum=auto;h1;h2; Ws string `json:"ws,omitempty"` } @@ -2718,6 +2718,11 @@ func (m *ServerParams) ContextValidate(ctx context.Context, formats strfmt.Regis func (m *ServerParams) contextValidateSetProxyV2TlvFmt(ctx context.Context, formats strfmt.Registry) error { if m.SetProxyV2TlvFmt != nil { + + if swag.IsZero(m.SetProxyV2TlvFmt) { // not required + return nil + } + if err := m.SetProxyV2TlvFmt.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("set-proxy-v2-tlv-fmt") diff --git a/models/server_params_compare_test.go b/models/server_params_compare_test.go index fc3bdaeb..4ffb04b3 100644 --- a/models/server_params_compare_test.go +++ b/models/server_params_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestServerParamsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerParams var result ServerParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestServerParamsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerParams to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestServerParamsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerParams var result ServerParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.AgentInter = Ptr(*sample.AgentInter + 1) result.AgentPort = Ptr(*sample.AgentPort + 1) @@ -116,11 +119,11 @@ func TestServerParamsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerParams to be different, but it is not %s %s", a, b) } @@ -134,17 +137,17 @@ func TestServerParamsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerParams var result ServerParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -158,11 +161,11 @@ func TestServerParamsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerParams to be equal, but it is not %s %s, %v", a, b, result) } @@ -176,13 +179,13 @@ func TestServerParamsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerParams var result ServerParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.AgentInter = Ptr(*sample.AgentInter + 1) result.AgentPort = Ptr(*sample.AgentPort + 1) @@ -217,11 +220,11 @@ func TestServerParamsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerParams to be different in 93 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -235,17 +238,17 @@ func TestServerParamsSetProxyV2TlvFmtEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerParamsSetProxyV2TlvFmt var result ServerParamsSetProxyV2TlvFmt - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -259,11 +262,11 @@ func TestServerParamsSetProxyV2TlvFmtEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerParamsSetProxyV2TlvFmt to be equal, but it is not %s %s", a, b) } @@ -277,13 +280,13 @@ func TestServerParamsSetProxyV2TlvFmtEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerParamsSetProxyV2TlvFmt var result ServerParamsSetProxyV2TlvFmt - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ServerParamsSetProxyV2TlvFmt @@ -296,11 +299,11 @@ func TestServerParamsSetProxyV2TlvFmtEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerParamsSetProxyV2TlvFmt to be different, but it is not %s %s", a, b) } @@ -314,17 +317,17 @@ func TestServerParamsSetProxyV2TlvFmtDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerParamsSetProxyV2TlvFmt var result ServerParamsSetProxyV2TlvFmt - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -338,11 +341,11 @@ func TestServerParamsSetProxyV2TlvFmtDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerParamsSetProxyV2TlvFmt to be equal, but it is not %s %s, %v", a, b, result) } @@ -356,13 +359,13 @@ func TestServerParamsSetProxyV2TlvFmtDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerParamsSetProxyV2TlvFmt var result ServerParamsSetProxyV2TlvFmt - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ServerParamsSetProxyV2TlvFmt @@ -375,11 +378,11 @@ func TestServerParamsSetProxyV2TlvFmtDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerParamsSetProxyV2TlvFmt to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/server_params_prepare_for_runtime.go b/models/server_params_prepare_for_runtime.go new file mode 100644 index 00000000..00916dac --- /dev/null +++ b/models/server_params_prepare_for_runtime.go @@ -0,0 +1,102 @@ +// Code generated by server_params_runtime; DO NOT EDIT. + +package models + +func (s ServerParams) PrepareFieldsForRuntimeAddServer() *ServerParams { + serverParams := new(ServerParams) + // *defaultServer = p + a, _ := s.MarshalBinary() + _ = serverParams.UnmarshalBinary(a) + + serverParams.prepareForRuntimeDoNotSendDisabledFields() + serverParams.prepareForRuntimeDoNotSendEnabledFields() + + return serverParams +} + +func (s *ServerParams) prepareForRuntimeDoNotSendDisabledFields() { + if s.AgentCheck == "disabled" { + s.AgentCheck = "" + } + if s.Backup == "disabled" { + s.Backup = "" + } + if s.Check == "disabled" { + s.Check = "" + } + if s.CheckSendProxy == "disabled" { + s.CheckSendProxy = "" + } + if s.CheckSsl == "disabled" { + s.CheckSsl = "" + } + if s.CheckViaSocks4 == "disabled" { + s.CheckViaSocks4 = "" + } + if s.ForceSslv3 == "disabled" { + s.ForceSslv3 = "" + } + if s.ForceTlsv10 == "disabled" { + s.ForceTlsv10 = "" + } + if s.ForceTlsv11 == "disabled" { + s.ForceTlsv11 = "" + } + if s.ForceTlsv12 == "disabled" { + s.ForceTlsv12 = "" + } + if s.ForceTlsv13 == "disabled" { + s.ForceTlsv13 = "" + } + if s.Maintenance == "disabled" { + s.Maintenance = "" + } + if s.SendProxy == "disabled" { + s.SendProxy = "" + } + if s.SendProxyV2 == "disabled" { + s.SendProxyV2 = "" + } + if s.SendProxyV2Ssl == "disabled" { + s.SendProxyV2Ssl = "" + } + if s.SendProxyV2SslCn == "disabled" { + s.SendProxyV2SslCn = "" + } + if s.Ssl == "disabled" { + s.Ssl = "" + } + if s.SslReuse == "disabled" { + s.SslReuse = "" + } + if s.Stick == "disabled" { + s.Stick = "" + } + if s.Tfo == "disabled" { + s.Tfo = "" + } + if s.TLSTickets == "disabled" { + s.TLSTickets = "" + } +} + +func (s *ServerParams) prepareForRuntimeDoNotSendEnabledFields() { + if s.NoSslv3 == "enabled" { + s.NoSslv3 = "" + } + if s.NoTlsv10 == "enabled" { + s.NoTlsv10 = "" + } + if s.NoTlsv11 == "enabled" { + s.NoTlsv11 = "" + } + if s.NoTlsv12 == "enabled" { + s.NoTlsv12 = "" + } + if s.NoTlsv13 == "enabled" { + s.NoTlsv13 = "" + } + if s.NoVerifyhost == "enabled" { + s.NoVerifyhost = "" + } +} diff --git a/models/server_switching_rule.go b/models/server_switching_rule.go index ecc33be3..eb344812 100644 --- a/models/server_switching_rule.go +++ b/models/server_switching_rule.go @@ -33,12 +33,12 @@ import ( // ServerSwitchingRule Server Switching Rule // // HAProxy server switching rule configuration (corresponds to use-server directive) -// Example: {"cond":"if","cond_test":"{ req_ssl_sni -i www.example.com }","target_server":"www"} +// Example: {"cond":"if","cond_test":"{ req.ssl_sni -i www.example.com }","target_server":"www"} // // swagger:model server_switching_rule type ServerSwitchingRule struct { // cond - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond string `json:"cond,omitempty"` diff --git a/models/server_switching_rule_compare_test.go b/models/server_switching_rule_compare_test.go index a600eb9c..669ba976 100644 --- a/models/server_switching_rule_compare_test.go +++ b/models/server_switching_rule_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestServerSwitchingRuleEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerSwitchingRule var result ServerSwitchingRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestServerSwitchingRuleEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerSwitchingRule to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestServerSwitchingRuleEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerSwitchingRule var result ServerSwitchingRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ServerSwitchingRule @@ -94,11 +97,11 @@ func TestServerSwitchingRuleEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerSwitchingRule to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestServerSwitchingRuleDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerSwitchingRule var result ServerSwitchingRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestServerSwitchingRuleDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerSwitchingRule to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestServerSwitchingRuleDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerSwitchingRule var result ServerSwitchingRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b ServerSwitchingRule @@ -173,11 +176,11 @@ func TestServerSwitchingRuleDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerSwitchingRule to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/server_switching_rules.go b/models/server_switching_rules.go index e83b7b0d..a358bfbc 100644 --- a/models/server_switching_rules.go +++ b/models/server_switching_rules.go @@ -71,6 +71,11 @@ func (m ServerSwitchingRules) ContextValidate(ctx context.Context, formats strfm for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/server_template_compare_test.go b/models/server_template_compare_test.go index 666013a2..8b80f899 100644 --- a/models/server_template_compare_test.go +++ b/models/server_template_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestServerTemplateEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerTemplate var result ServerTemplate - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestServerTemplateEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerTemplate to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestServerTemplateEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerTemplate var result ServerTemplate - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.ID = Ptr(*sample.ID + 1) result.Port = Ptr(*sample.Port + 1) @@ -96,11 +99,11 @@ func TestServerTemplateEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerTemplate to be different, but it is not %s %s", a, b) } @@ -114,17 +117,17 @@ func TestServerTemplateDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerTemplate var result ServerTemplate - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -138,11 +141,11 @@ func TestServerTemplateDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerTemplate to be equal, but it is not %s %s, %v", a, b, result) } @@ -156,13 +159,13 @@ func TestServerTemplateDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample ServerTemplate var result ServerTemplate - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.ID = Ptr(*sample.ID + 1) result.Port = Ptr(*sample.Port + 1) @@ -177,11 +180,11 @@ func TestServerTemplateDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected ServerTemplate to be different in 6 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/server_templates.go b/models/server_templates.go index adf04313..da1156e8 100644 --- a/models/server_templates.go +++ b/models/server_templates.go @@ -71,6 +71,11 @@ func (m ServerTemplates) ContextValidate(ctx context.Context, formats strfmt.Reg for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/servers.go b/models/servers.go index 3e523ed3..78d2c4c3 100644 --- a/models/servers.go +++ b/models/servers.go @@ -71,6 +71,11 @@ func (m Servers) ContextValidate(ctx context.Context, formats strfmt.Registry) e for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/site.go b/models/site.go index 6b6ec57c..458d6272 100644 --- a/models/site.go +++ b/models/site.go @@ -159,6 +159,11 @@ func (m *Site) contextValidateFarms(ctx context.Context, formats strfmt.Registry for i := 0; i < len(m.Farms); i++ { if m.Farms[i] != nil { + + if swag.IsZero(m.Farms[i]) { // not required + return nil + } + if err := m.Farms[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("farms" + "." + strconv.Itoa(i)) @@ -177,6 +182,11 @@ func (m *Site) contextValidateFarms(ctx context.Context, formats strfmt.Registry func (m *Site) contextValidateService(ctx context.Context, formats strfmt.Registry) error { if m.Service != nil { + + if swag.IsZero(m.Service) { // not required + return nil + } + if err := m.Service.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("service") @@ -217,7 +227,7 @@ type SiteFarm struct { Balance *Balance `json:"balance,omitempty"` // cond - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond string `json:"cond,omitempty"` @@ -228,7 +238,7 @@ type SiteFarm struct { Forwardfor *Forwardfor `json:"forwardfor,omitempty"` // mode - // Enum: [http tcp] + // Enum: ["http","tcp"] // +kubebuilder:validation:Enum=http;tcp; Mode string `json:"mode,omitempty"` @@ -243,7 +253,7 @@ type SiteFarm struct { // use as // Required: true - // Enum: [default conditional] + // Enum: ["default","conditional"] // +kubebuilder:validation:Enum=default;conditional; UseAs string `json:"use_as"` } @@ -515,6 +525,11 @@ func (m *SiteFarm) ContextValidate(ctx context.Context, formats strfmt.Registry) func (m *SiteFarm) contextValidateBalance(ctx context.Context, formats strfmt.Registry) error { if m.Balance != nil { + + if swag.IsZero(m.Balance) { // not required + return nil + } + if err := m.Balance.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("balance") @@ -531,6 +546,11 @@ func (m *SiteFarm) contextValidateBalance(ctx context.Context, formats strfmt.Re func (m *SiteFarm) contextValidateForwardfor(ctx context.Context, formats strfmt.Registry) error { if m.Forwardfor != nil { + + if swag.IsZero(m.Forwardfor) { // not required + return nil + } + if err := m.Forwardfor.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("forwardfor") @@ -549,6 +569,11 @@ func (m *SiteFarm) contextValidateServers(ctx context.Context, formats strfmt.Re for i := 0; i < len(m.Servers); i++ { if m.Servers[i] != nil { + + if swag.IsZero(m.Servers[i]) { // not required + return nil + } + if err := m.Servers[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("servers" + "." + strconv.Itoa(i)) @@ -587,7 +612,7 @@ func (m *SiteFarm) UnmarshalBinary(b []byte) error { // swagger:model SiteService type SiteService struct { // http connection mode - // Enum: [http-tunnel httpclose forced-close http-server-close http-keep-alive] + // Enum: ["http-tunnel","httpclose","forced-close","http-server-close","http-keep-alive"] // +kubebuilder:validation:Enum=http-tunnel;httpclose;forced-close;http-server-close;http-keep-alive; HTTPConnectionMode string `json:"http_connection_mode,omitempty"` @@ -598,7 +623,7 @@ type SiteService struct { Maxconn *int64 `json:"maxconn,omitempty"` // mode - // Enum: [http tcp] + // Enum: ["http","tcp"] // +kubebuilder:validation:Enum=http;tcp; Mode string `json:"mode,omitempty"` } @@ -763,6 +788,11 @@ func (m *SiteService) contextValidateListeners(ctx context.Context, formats strf for i := 0; i < len(m.Listeners); i++ { if m.Listeners[i] != nil { + + if swag.IsZero(m.Listeners[i]) { // not required + return nil + } + if err := m.Listeners[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("service" + "." + "listeners" + "." + strconv.Itoa(i)) diff --git a/models/site_compare_test.go b/models/site_compare_test.go index 1e25fe87..94bb2c39 100644 --- a/models/site_compare_test.go +++ b/models/site_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestSiteEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Site var result Site - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestSiteEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Site to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestSiteEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Site var result Site - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Site @@ -94,11 +97,11 @@ func TestSiteEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Site to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestSiteDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Site var result Site - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestSiteDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Site to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestSiteDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Site var result Site - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Site @@ -173,11 +176,11 @@ func TestSiteDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Site to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -191,17 +194,17 @@ func TestSiteFarmEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SiteFarm var result SiteFarm - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -215,11 +218,11 @@ func TestSiteFarmEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SiteFarm to be equal, but it is not %s %s", a, b) } @@ -233,13 +236,13 @@ func TestSiteFarmEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SiteFarm var result SiteFarm - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SiteFarm @@ -252,11 +255,11 @@ func TestSiteFarmEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SiteFarm to be different, but it is not %s %s", a, b) } @@ -270,17 +273,17 @@ func TestSiteFarmDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SiteFarm var result SiteFarm - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -294,11 +297,11 @@ func TestSiteFarmDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SiteFarm to be equal, but it is not %s %s, %v", a, b, result) } @@ -312,13 +315,13 @@ func TestSiteFarmDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SiteFarm var result SiteFarm - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SiteFarm @@ -331,11 +334,11 @@ func TestSiteFarmDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SiteFarm to be different in 8 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -349,17 +352,17 @@ func TestSiteServiceEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SiteService var result SiteService - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -373,11 +376,11 @@ func TestSiteServiceEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SiteService to be equal, but it is not %s %s", a, b) } @@ -391,13 +394,13 @@ func TestSiteServiceEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SiteService var result SiteService - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Maxconn = Ptr(*sample.Maxconn + 1) samples = append(samples, struct { @@ -411,11 +414,11 @@ func TestSiteServiceEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SiteService to be different, but it is not %s %s", a, b) } @@ -429,17 +432,17 @@ func TestSiteServiceDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SiteService var result SiteService - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -453,11 +456,11 @@ func TestSiteServiceDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SiteService to be equal, but it is not %s %s, %v", a, b, result) } @@ -471,13 +474,13 @@ func TestSiteServiceDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SiteService var result SiteService - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Maxconn = Ptr(*sample.Maxconn + 1) samples = append(samples, struct { @@ -491,11 +494,11 @@ func TestSiteServiceDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SiteService to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/sites.go b/models/sites.go index 536d912e..0b2e50b6 100644 --- a/models/sites.go +++ b/models/sites.go @@ -74,6 +74,11 @@ func (m Sites) ContextValidate(ctx context.Context, formats strfmt.Registry) err for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/smtpchk_params_compare_test.go b/models/smtpchk_params_compare_test.go index 023a6f7b..3fd7414a 100644 --- a/models/smtpchk_params_compare_test.go +++ b/models/smtpchk_params_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestSmtpchkParamsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SmtpchkParams var result SmtpchkParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestSmtpchkParamsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SmtpchkParams to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestSmtpchkParamsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SmtpchkParams var result SmtpchkParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SmtpchkParams @@ -94,11 +97,11 @@ func TestSmtpchkParamsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SmtpchkParams to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestSmtpchkParamsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SmtpchkParams var result SmtpchkParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestSmtpchkParamsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SmtpchkParams to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestSmtpchkParamsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SmtpchkParams var result SmtpchkParams - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SmtpchkParams @@ -173,11 +176,11 @@ func TestSmtpchkParamsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SmtpchkParams to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/source.go b/models/source.go index 0b9c3845..e7eae1dc 100644 --- a/models/source.go +++ b/models/source.go @@ -66,7 +66,7 @@ type Source struct { PortSecond int64 `json:"port_second,omitempty"` // usesrc - // Enum: [address client clientip hdr_ip] + // Enum: ["address","client","clientip","hdr_ip"] // +kubebuilder:validation:Enum=address;client;clientip;hdr_ip; Usesrc string `json:"usesrc,omitempty"` } diff --git a/models/source_compare_test.go b/models/source_compare_test.go index 4e28738b..b21ad60b 100644 --- a/models/source_compare_test.go +++ b/models/source_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestSourceEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Source var result Source - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestSourceEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Source to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestSourceEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Source var result Source - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = sample.Port + 1 result.PortSecond = sample.PortSecond + 1 @@ -96,11 +99,11 @@ func TestSourceEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Source to be different, but it is not %s %s", a, b) } @@ -114,17 +117,17 @@ func TestSourceDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Source var result Source - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -138,11 +141,11 @@ func TestSourceDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Source to be equal, but it is not %s %s, %v", a, b, result) } @@ -156,13 +159,13 @@ func TestSourceDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Source var result Source - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Port = sample.Port + 1 result.PortSecond = sample.PortSecond + 1 @@ -177,11 +180,11 @@ func TestSourceDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Source to be different in 8 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/spoe_agent.go b/models/spoe_agent.go index 66eb9bfb..fc43d5db 100644 --- a/models/spoe_agent.go +++ b/models/spoe_agent.go @@ -37,17 +37,17 @@ import ( // swagger:model spoe_agent type SpoeAgent struct { // async - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Async string `json:"async,omitempty"` // continue on error - // Enum: [enabled] + // Enum: ["enabled"] // +kubebuilder:validation:Enum=enabled; ContinueOnError string `json:"continue-on-error,omitempty"` // dontlog normal - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; DontlogNormal string `json:"dontlog-normal,omitempty"` @@ -55,7 +55,7 @@ type SpoeAgent struct { EngineName string `json:"engine-name,omitempty"` // force set var - // Enum: [enabled] + // Enum: ["enabled"] // +kubebuilder:validation:Enum=enabled; ForceSetVar string `json:"force-set-var,omitempty"` @@ -111,7 +111,7 @@ type SpoeAgent struct { OptionVarPrefix string `json:"option_var-prefix,omitempty"` // pipelining - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Pipelining string `json:"pipelining,omitempty"` @@ -122,7 +122,7 @@ type SpoeAgent struct { RegisterVarNames string `json:"register-var-names,omitempty"` // send frag payload - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SendFragPayload string `json:"send-frag-payload,omitempty"` diff --git a/models/spoe_agent_compare_test.go b/models/spoe_agent_compare_test.go index e755b9e6..5d9f8170 100644 --- a/models/spoe_agent_compare_test.go +++ b/models/spoe_agent_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestSpoeAgentEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeAgent var result SpoeAgent - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestSpoeAgentEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeAgent to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestSpoeAgentEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeAgent var result SpoeAgent - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.HelloTimeout = sample.HelloTimeout + 1 result.IdleTimeout = sample.IdleTimeout + 1 @@ -101,11 +104,11 @@ func TestSpoeAgentEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeAgent to be different, but it is not %s %s", a, b) } @@ -119,17 +122,17 @@ func TestSpoeAgentDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeAgent var result SpoeAgent - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -143,11 +146,11 @@ func TestSpoeAgentDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeAgent to be equal, but it is not %s %s, %v", a, b, result) } @@ -161,13 +164,13 @@ func TestSpoeAgentDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeAgent var result SpoeAgent - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.HelloTimeout = sample.HelloTimeout + 1 result.IdleTimeout = sample.IdleTimeout + 1 @@ -187,11 +190,11 @@ func TestSpoeAgentDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeAgent to be different in 24 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/spoe_agents.go b/models/spoe_agents.go index 4961cbfa..29b983bc 100644 --- a/models/spoe_agents.go +++ b/models/spoe_agents.go @@ -71,6 +71,11 @@ func (m SpoeAgents) ContextValidate(ctx context.Context, formats strfmt.Registry for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/spoe_group_compare_test.go b/models/spoe_group_compare_test.go index 67fa862c..caab5918 100644 --- a/models/spoe_group_compare_test.go +++ b/models/spoe_group_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestSpoeGroupEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeGroup var result SpoeGroup - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestSpoeGroupEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeGroup to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestSpoeGroupEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeGroup var result SpoeGroup - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SpoeGroup @@ -94,11 +97,11 @@ func TestSpoeGroupEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeGroup to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestSpoeGroupDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeGroup var result SpoeGroup - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestSpoeGroupDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeGroup to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestSpoeGroupDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeGroup var result SpoeGroup - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SpoeGroup @@ -173,11 +176,11 @@ func TestSpoeGroupDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeGroup to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/spoe_groups.go b/models/spoe_groups.go index 09db7a9f..6eeb8772 100644 --- a/models/spoe_groups.go +++ b/models/spoe_groups.go @@ -71,6 +71,11 @@ func (m SpoeGroups) ContextValidate(ctx context.Context, formats strfmt.Registry for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/spoe_message.go b/models/spoe_message.go index 3cf3bbc2..bda0a1ef 100644 --- a/models/spoe_message.go +++ b/models/spoe_message.go @@ -153,6 +153,11 @@ func (m *SpoeMessage) contextValidateACL(ctx context.Context, formats strfmt.Reg func (m *SpoeMessage) contextValidateEvent(ctx context.Context, formats strfmt.Registry) error { if m.Event != nil { + + if swag.IsZero(m.Event) { // not required + return nil + } + if err := m.Event.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("event") @@ -189,7 +194,7 @@ func (m *SpoeMessage) UnmarshalBinary(b []byte) error { // swagger:model SpoeMessageEvent type SpoeMessageEvent struct { // cond - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond string `json:"cond,omitempty"` @@ -198,7 +203,7 @@ type SpoeMessageEvent struct { // name // Required: true - // Enum: [on-backend-http-request on-backend-tcp-request on-client-session on-frontend-http-request on-frontend-tcp-request on-http-response on-server-session on-tcp-response] + // Enum: ["on-backend-http-request","on-backend-tcp-request","on-client-session","on-frontend-http-request","on-frontend-tcp-request","on-http-response","on-server-session","on-tcp-response"] // +kubebuilder:validation:Enum=on-backend-http-request;on-backend-tcp-request;on-client-session;on-frontend-http-request;on-frontend-tcp-request;on-http-response;on-server-session;on-tcp-response; Name *string `json:"name"` } diff --git a/models/spoe_message_compare_test.go b/models/spoe_message_compare_test.go index bb3fcff3..481db4eb 100644 --- a/models/spoe_message_compare_test.go +++ b/models/spoe_message_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestSpoeMessageEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeMessage var result SpoeMessage - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestSpoeMessageEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeMessage to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestSpoeMessageEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeMessage var result SpoeMessage - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SpoeMessage @@ -94,11 +97,11 @@ func TestSpoeMessageEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeMessage to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestSpoeMessageDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeMessage var result SpoeMessage - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestSpoeMessageDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeMessage to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestSpoeMessageDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeMessage var result SpoeMessage - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SpoeMessage @@ -173,11 +176,11 @@ func TestSpoeMessageDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeMessage to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -191,17 +194,17 @@ func TestSpoeMessageEventEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeMessageEvent var result SpoeMessageEvent - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -215,11 +218,11 @@ func TestSpoeMessageEventEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeMessageEvent to be equal, but it is not %s %s", a, b) } @@ -233,13 +236,13 @@ func TestSpoeMessageEventEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeMessageEvent var result SpoeMessageEvent - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SpoeMessageEvent @@ -252,11 +255,11 @@ func TestSpoeMessageEventEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeMessageEvent to be different, but it is not %s %s", a, b) } @@ -270,17 +273,17 @@ func TestSpoeMessageEventDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeMessageEvent var result SpoeMessageEvent - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -294,11 +297,11 @@ func TestSpoeMessageEventDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeMessageEvent to be equal, but it is not %s %s, %v", a, b, result) } @@ -312,13 +315,13 @@ func TestSpoeMessageEventDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeMessageEvent var result SpoeMessageEvent - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SpoeMessageEvent @@ -331,11 +334,11 @@ func TestSpoeMessageEventDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeMessageEvent to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/spoe_messages.go b/models/spoe_messages.go index 37132e7c..27056f98 100644 --- a/models/spoe_messages.go +++ b/models/spoe_messages.go @@ -71,6 +71,11 @@ func (m SpoeMessages) ContextValidate(ctx context.Context, formats strfmt.Regist for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/spoe_scope_compare_test.go b/models/spoe_scope_compare_test.go index d4bce586..95ec1456 100644 --- a/models/spoe_scope_compare_test.go +++ b/models/spoe_scope_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestSpoeScopeEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeScope var result SpoeScope - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestSpoeScopeEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeScope to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestSpoeScopeEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeScope var result SpoeScope - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SpoeScope @@ -94,11 +97,11 @@ func TestSpoeScopeEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeScope to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestSpoeScopeDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeScope var result SpoeScope - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestSpoeScopeDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeScope to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestSpoeScopeDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeScope var result SpoeScope - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SpoeScope @@ -173,11 +176,11 @@ func TestSpoeScopeDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeScope to be different in 0 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/spoe_scopes.go b/models/spoe_scopes.go index f4b5a957..59dc7931 100644 --- a/models/spoe_scopes.go +++ b/models/spoe_scopes.go @@ -26,6 +26,7 @@ import ( "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" ) // SpoeScopes SPOE Scopes @@ -64,6 +65,10 @@ func (m SpoeScopes) ContextValidate(ctx context.Context, formats strfmt.Registry for i := 0; i < len(m); i++ { + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/spoe_transaction.go b/models/spoe_transaction.go index 7f9296bb..7c4644d7 100644 --- a/models/spoe_transaction.go +++ b/models/spoe_transaction.go @@ -47,7 +47,7 @@ type SpoeTransaction struct { ID string `json:"id,omitempty"` // status - // Enum: [failed in_progress success] + // Enum: ["failed","in_progress","success"] // +kubebuilder:validation:Enum=failed;in_progress;success; Status string `json:"status,omitempty"` } diff --git a/models/spoe_transaction_compare_test.go b/models/spoe_transaction_compare_test.go index e6408bd4..270e723e 100644 --- a/models/spoe_transaction_compare_test.go +++ b/models/spoe_transaction_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestSpoeTransactionEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeTransaction var result SpoeTransaction - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestSpoeTransactionEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeTransaction to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestSpoeTransactionEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeTransaction var result SpoeTransaction - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Version = sample.Version + 1 samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestSpoeTransactionEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeTransaction to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestSpoeTransactionDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeTransaction var result SpoeTransaction - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestSpoeTransactionDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeTransaction to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestSpoeTransactionDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SpoeTransaction var result SpoeTransaction - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Version = sample.Version + 1 samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestSpoeTransactionDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SpoeTransaction to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/spoe_transactions.go b/models/spoe_transactions.go index c5f0ed01..707b164a 100644 --- a/models/spoe_transactions.go +++ b/models/spoe_transactions.go @@ -71,6 +71,11 @@ func (m SpoeTransactions) ContextValidate(ctx context.Context, formats strfmt.Re for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/ssl_cert_entry_compare_test.go b/models/ssl_cert_entry_compare_test.go index b2ec6275..ddc777c5 100644 --- a/models/ssl_cert_entry_compare_test.go +++ b/models/ssl_cert_entry_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -24,6 +26,7 @@ import ( "time" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" "github.com/go-openapi/strfmt" jsoniter "github.com/json-iterator/go" @@ -36,17 +39,17 @@ func TestSslCertEntryEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SslCertEntry var result SslCertEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -60,11 +63,11 @@ func TestSslCertEntryEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslCertEntry to be equal, but it is not %s %s", a, b) } @@ -78,13 +81,13 @@ func TestSslCertEntryEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SslCertEntry var result SslCertEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.NotAfter = strfmt.Date(time.Now().AddDate(rand.Intn(10), rand.Intn(12), rand.Intn(28))) result.NotBefore = strfmt.Date(time.Now().AddDate(rand.Intn(10), rand.Intn(12), rand.Intn(28))) @@ -99,11 +102,11 @@ func TestSslCertEntryEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslCertEntry to be different, but it is not %s %s", a, b) } @@ -117,17 +120,17 @@ func TestSslCertEntryDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SslCertEntry var result SslCertEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -141,11 +144,11 @@ func TestSslCertEntryDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslCertEntry to be equal, but it is not %s %s, %v", a, b, result) } @@ -159,13 +162,13 @@ func TestSslCertEntryDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SslCertEntry var result SslCertEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.NotAfter = strfmt.Date(time.Now().AddDate(rand.Intn(10), rand.Intn(12), rand.Intn(28))) result.NotBefore = strfmt.Date(time.Now().AddDate(rand.Intn(10), rand.Intn(12), rand.Intn(28))) @@ -180,11 +183,11 @@ func TestSslCertEntryDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslCertEntry to be different in 12 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/ssl_certificate_compare_test.go b/models/ssl_certificate_compare_test.go index 9ee4b129..c3f85ea7 100644 --- a/models/ssl_certificate_compare_test.go +++ b/models/ssl_certificate_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -24,6 +26,7 @@ import ( "time" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" "github.com/go-openapi/strfmt" jsoniter "github.com/json-iterator/go" @@ -36,17 +39,17 @@ func TestSslCertificateEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SslCertificate var result SslCertificate - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -60,11 +63,11 @@ func TestSslCertificateEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslCertificate to be equal, but it is not %s %s", a, b) } @@ -78,13 +81,13 @@ func TestSslCertificateEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SslCertificate var result SslCertificate - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.NotAfter = Ptr(strfmt.DateTime(time.Now().AddDate(rand.Intn(10), rand.Intn(12), rand.Intn(28)))) result.NotBefore = Ptr(strfmt.DateTime(time.Now().AddDate(rand.Intn(10), rand.Intn(12), rand.Intn(28)))) @@ -100,11 +103,11 @@ func TestSslCertificateEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslCertificate to be different, but it is not %s %s", a, b) } @@ -118,17 +121,17 @@ func TestSslCertificateDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SslCertificate var result SslCertificate - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -142,11 +145,11 @@ func TestSslCertificateDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslCertificate to be equal, but it is not %s %s, %v", a, b, result) } @@ -160,13 +163,13 @@ func TestSslCertificateDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SslCertificate var result SslCertificate - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.NotAfter = Ptr(strfmt.DateTime(time.Now().AddDate(rand.Intn(10), rand.Intn(12), rand.Intn(28)))) result.NotBefore = Ptr(strfmt.DateTime(time.Now().AddDate(rand.Intn(10), rand.Intn(12), rand.Intn(28)))) @@ -182,11 +185,11 @@ func TestSslCertificateDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslCertificate to be different in 17 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/ssl_certificates.go b/models/ssl_certificates.go index 499b0810..1f60eaa8 100644 --- a/models/ssl_certificates.go +++ b/models/ssl_certificates.go @@ -71,6 +71,11 @@ func (m SslCertificates) ContextValidate(ctx context.Context, formats strfmt.Reg for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/ssl_options.go b/models/ssl_options.go index 7dda90b6..868ac9b8 100644 --- a/models/ssl_options.go +++ b/models/ssl_options.go @@ -97,7 +97,7 @@ type SslOptions struct { Maxsslrate int64 `json:"maxsslrate,omitempty"` // mode async - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ModeAsync string `json:"mode_async,omitempty"` @@ -118,7 +118,7 @@ type SslOptions struct { SecurityLevel *int64 `json:"security_level,omitempty"` // server verify - // Enum: [none required] + // Enum: ["none","required"] // +kubebuilder:validation:Enum=none;required; ServerVerify string `json:"server_verify,omitempty"` @@ -297,6 +297,11 @@ func (m *SslOptions) contextValidateSslEngines(ctx context.Context, formats strf for i := 0; i < len(m.SslEngines); i++ { if m.SslEngines[i] != nil { + + if swag.IsZero(m.SslEngines[i]) { // not required + return nil + } + if err := m.SslEngines[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("engines" + "." + strconv.Itoa(i)) diff --git a/models/ssl_options_compare_test.go b/models/ssl_options_compare_test.go index f1e8a27f..9397e40e 100644 --- a/models/ssl_options_compare_test.go +++ b/models/ssl_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestSslOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SslOptions var result SslOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestSslOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestSslOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SslOptions var result SslOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Maxsslconn = sample.Maxsslconn + 1 result.Maxsslrate = sample.Maxsslrate + 1 @@ -98,11 +101,11 @@ func TestSslOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslOptions to be different, but it is not %s %s", a, b) } @@ -116,17 +119,17 @@ func TestSslOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SslOptions var result SslOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -140,11 +143,11 @@ func TestSslOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -158,13 +161,13 @@ func TestSslOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SslOptions var result SslOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Maxsslconn = sample.Maxsslconn + 1 result.Maxsslrate = sample.Maxsslrate + 1 @@ -181,11 +184,11 @@ func TestSslOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslOptions to be different in 27 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -199,17 +202,17 @@ func TestSslEngineEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample SslEngine var result SslEngine - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -223,11 +226,11 @@ func TestSslEngineEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslEngine to be equal, but it is not %s %s", a, b) } @@ -241,13 +244,13 @@ func TestSslEngineEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SslEngine var result SslEngine - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SslEngine @@ -260,11 +263,11 @@ func TestSslEngineEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslEngine to be different, but it is not %s %s", a, b) } @@ -278,17 +281,17 @@ func TestSslEngineDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample SslEngine var result SslEngine - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -302,11 +305,11 @@ func TestSslEngineDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslEngine to be equal, but it is not %s %s, %v", a, b, result) } @@ -320,13 +323,13 @@ func TestSslEngineDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample SslEngine var result SslEngine - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b SslEngine @@ -339,11 +342,11 @@ func TestSslEngineDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected SslEngine to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/stats_auth_compare_test.go b/models/stats_auth_compare_test.go index b1d907f6..a026db35 100644 --- a/models/stats_auth_compare_test.go +++ b/models/stats_auth_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestStatsAuthEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample StatsAuth var result StatsAuth - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestStatsAuthEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StatsAuth to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestStatsAuthEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample StatsAuth var result StatsAuth - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b StatsAuth @@ -94,11 +97,11 @@ func TestStatsAuthEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StatsAuth to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestStatsAuthDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample StatsAuth var result StatsAuth - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestStatsAuthDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StatsAuth to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestStatsAuthDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample StatsAuth var result StatsAuth - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b StatsAuth @@ -173,11 +176,11 @@ func TestStatsAuthDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StatsAuth to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/stats_http_request.go b/models/stats_http_request.go index b2327435..6e68a987 100644 --- a/models/stats_http_request.go +++ b/models/stats_http_request.go @@ -46,7 +46,7 @@ type StatsHTTPRequest struct { // type // Required: true - // Enum: [allow deny auth] + // Enum: ["allow","deny","auth"] // +kubebuilder:validation:Enum=allow;deny;auth; Type *string `json:"type"` } diff --git a/models/stats_http_request_compare_test.go b/models/stats_http_request_compare_test.go index 4921defb..3a68c8b3 100644 --- a/models/stats_http_request_compare_test.go +++ b/models/stats_http_request_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestStatsHTTPRequestEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample StatsHTTPRequest var result StatsHTTPRequest - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestStatsHTTPRequestEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StatsHTTPRequest to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestStatsHTTPRequestEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample StatsHTTPRequest var result StatsHTTPRequest - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b StatsHTTPRequest @@ -94,11 +97,11 @@ func TestStatsHTTPRequestEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StatsHTTPRequest to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestStatsHTTPRequestDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample StatsHTTPRequest var result StatsHTTPRequest - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestStatsHTTPRequestDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StatsHTTPRequest to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestStatsHTTPRequestDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample StatsHTTPRequest var result StatsHTTPRequest - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b StatsHTTPRequest @@ -173,11 +176,11 @@ func TestStatsHTTPRequestDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StatsHTTPRequest to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/stats_options.go b/models/stats_options.go index ffdc2544..6d065c41 100644 --- a/models/stats_options.go +++ b/models/stats_options.go @@ -40,7 +40,7 @@ type StatsOptions struct { StatsAdmin bool `json:"stats_admin,omitempty"` // stats admin cond - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; StatsAdminCond string `json:"stats_admin_cond,omitempty"` @@ -298,6 +298,11 @@ func (m *StatsOptions) contextValidateStatsAuths(ctx context.Context, formats st for i := 0; i < len(m.StatsAuths); i++ { if m.StatsAuths[i] != nil { + + if swag.IsZero(m.StatsAuths[i]) { // not required + return nil + } + if err := m.StatsAuths[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("stats_auths" + "." + strconv.Itoa(i)) @@ -318,6 +323,11 @@ func (m *StatsOptions) contextValidateStatsHTTPRequests(ctx context.Context, for for i := 0; i < len(m.StatsHTTPRequests); i++ { if m.StatsHTTPRequests[i] != nil { + + if swag.IsZero(m.StatsHTTPRequests[i]) { // not required + return nil + } + if err := m.StatsHTTPRequests[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("stats_http_requests" + "." + strconv.Itoa(i)) diff --git a/models/stats_options_compare_test.go b/models/stats_options_compare_test.go index 061720b0..ed768c29 100644 --- a/models/stats_options_compare_test.go +++ b/models/stats_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestStatsOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample StatsOptions var result StatsOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestStatsOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StatsOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestStatsOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample StatsOptions var result StatsOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.StatsAdmin = !sample.StatsAdmin result.StatsEnable = !sample.StatsEnable @@ -102,11 +105,11 @@ func TestStatsOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StatsOptions to be different, but it is not %s %s", a, b) } @@ -120,17 +123,17 @@ func TestStatsOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample StatsOptions var result StatsOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -144,11 +147,11 @@ func TestStatsOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StatsOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -162,13 +165,13 @@ func TestStatsOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample StatsOptions var result StatsOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.StatsAdmin = !sample.StatsAdmin result.StatsEnable = !sample.StatsEnable @@ -189,11 +192,11 @@ func TestStatsOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StatsOptions to be different in 16 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/stick_rule.go b/models/stick_rule.go index d8f2bc7d..68e710e4 100644 --- a/models/stick_rule.go +++ b/models/stick_rule.go @@ -38,7 +38,7 @@ import ( // swagger:model stick_rule type StickRule struct { // cond - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond string `json:"cond,omitempty"` @@ -58,7 +58,7 @@ type StickRule struct { // type // Required: true - // Enum: [match on store-request store-response] + // Enum: ["match","on","store-request","store-response"] // +kubebuilder:validation:Enum=match;on;store-request;store-response; Type string `json:"type"` } diff --git a/models/stick_rule_compare_test.go b/models/stick_rule_compare_test.go index 3e5fbd34..30f62eaa 100644 --- a/models/stick_rule_compare_test.go +++ b/models/stick_rule_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestStickRuleEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample StickRule var result StickRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestStickRuleEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StickRule to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestStickRuleEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample StickRule var result StickRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b StickRule @@ -94,11 +97,11 @@ func TestStickRuleEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StickRule to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestStickRuleDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample StickRule var result StickRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestStickRuleDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StickRule to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestStickRuleDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample StickRule var result StickRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b StickRule @@ -173,11 +176,11 @@ func TestStickRuleDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StickRule to be different in 5 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/stick_rules.go b/models/stick_rules.go index 5b03d968..e18b0918 100644 --- a/models/stick_rules.go +++ b/models/stick_rules.go @@ -71,6 +71,11 @@ func (m StickRules) ContextValidate(ctx context.Context, formats strfmt.Registry for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/stick_table.go b/models/stick_table.go index 7afaf349..78b2c1e4 100644 --- a/models/stick_table.go +++ b/models/stick_table.go @@ -48,7 +48,7 @@ type StickTable struct { Size *int64 `json:"size,omitempty"` // type - // Enum: [ip ipv6 integer string binary] + // Enum: ["ip","ipv6","integer","string","binary"] // +kubebuilder:validation:Enum=ip;ipv6;integer;string;binary; Type string `json:"type,omitempty"` @@ -170,6 +170,11 @@ func (m *StickTable) contextValidateFields(ctx context.Context, formats strfmt.R for i := 0; i < len(m.Fields); i++ { if m.Fields[i] != nil { + + if swag.IsZero(m.Fields[i]) { // not required + return nil + } + if err := m.Fields[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("fields" + "." + strconv.Itoa(i)) @@ -208,15 +213,18 @@ func (m *StickTable) UnmarshalBinary(b []byte) error { // swagger:model StickTableField type StickTableField struct { // field - // Enum: [bytes_in_cnt bytes_in_rate bytes_out_cnt bytes_out_rate conn_cnt conn_cur conn_rate gpc0 gpc0_rate gpc1 gpc1_rate gpt0 http_req_cnt http_req_rate http_err_cnt http_err_rate server_id sess_cnt sess_rate] - // +kubebuilder:validation:Enum=bytes_in_cnt;bytes_in_rate;bytes_out_cnt;bytes_out_rate;conn_cnt;conn_cur;conn_rate;gpc0;gpc0_rate;gpc1;gpc1_rate;gpt0;http_req_cnt;http_req_rate;http_err_cnt;http_err_rate;server_id;sess_cnt;sess_rate; + // Enum: ["bytes_in_cnt","bytes_in_rate","bytes_out_cnt","bytes_out_rate","conn_cnt","conn_cur","conn_rate","glitch_cnt","glitch_rate","gpc","gpc_rate","gpc0","gpc0_rate","gpc1","gpc1_rate","gpt0","gpt","http_req_cnt","http_req_rate","http_err_cnt","http_err_rate","http_fail_cnt","http_fail_rate","server_id","sess_cnt","sess_rate"] + // +kubebuilder:validation:Enum=bytes_in_cnt;bytes_in_rate;bytes_out_cnt;bytes_out_rate;conn_cnt;conn_cur;conn_rate;glitch_cnt;glitch_rate;gpc;gpc_rate;gpc0;gpc0_rate;gpc1;gpc1_rate;gpt0;gpt;http_req_cnt;http_req_rate;http_err_cnt;http_err_rate;http_fail_cnt;http_fail_rate;server_id;sess_cnt;sess_rate; Field string `json:"field,omitempty"` + // idx + Idx int64 `json:"idx,omitempty"` + // period Period int64 `json:"period,omitempty"` // type - // Enum: [rate counter] + // Enum: ["rate","counter"] // +kubebuilder:validation:Enum=rate;counter; Type string `json:"type,omitempty"` } @@ -243,7 +251,7 @@ var stickTableFieldTypeFieldPropEnum []interface{} func init() { var res []string - if err := json.Unmarshal([]byte(`["bytes_in_cnt","bytes_in_rate","bytes_out_cnt","bytes_out_rate","conn_cnt","conn_cur","conn_rate","gpc0","gpc0_rate","gpc1","gpc1_rate","gpt0","http_req_cnt","http_req_rate","http_err_cnt","http_err_rate","server_id","sess_cnt","sess_rate"]`), &res); err != nil { + if err := json.Unmarshal([]byte(`["bytes_in_cnt","bytes_in_rate","bytes_out_cnt","bytes_out_rate","conn_cnt","conn_cur","conn_rate","glitch_cnt","glitch_rate","gpc","gpc_rate","gpc0","gpc0_rate","gpc1","gpc1_rate","gpt0","gpt","http_req_cnt","http_req_rate","http_err_cnt","http_err_rate","http_fail_cnt","http_fail_rate","server_id","sess_cnt","sess_rate"]`), &res); err != nil { panic(err) } for _, v := range res { @@ -274,6 +282,18 @@ const ( // StickTableFieldFieldConnRate captures enum value "conn_rate" StickTableFieldFieldConnRate string = "conn_rate" + // StickTableFieldFieldGlitchCnt captures enum value "glitch_cnt" + StickTableFieldFieldGlitchCnt string = "glitch_cnt" + + // StickTableFieldFieldGlitchRate captures enum value "glitch_rate" + StickTableFieldFieldGlitchRate string = "glitch_rate" + + // StickTableFieldFieldGpc captures enum value "gpc" + StickTableFieldFieldGpc string = "gpc" + + // StickTableFieldFieldGpcRate captures enum value "gpc_rate" + StickTableFieldFieldGpcRate string = "gpc_rate" + // StickTableFieldFieldGpc0 captures enum value "gpc0" StickTableFieldFieldGpc0 string = "gpc0" @@ -289,6 +309,9 @@ const ( // StickTableFieldFieldGpt0 captures enum value "gpt0" StickTableFieldFieldGpt0 string = "gpt0" + // StickTableFieldFieldGpt captures enum value "gpt" + StickTableFieldFieldGpt string = "gpt" + // StickTableFieldFieldHTTPReqCnt captures enum value "http_req_cnt" StickTableFieldFieldHTTPReqCnt string = "http_req_cnt" @@ -301,6 +324,12 @@ const ( // StickTableFieldFieldHTTPErrRate captures enum value "http_err_rate" StickTableFieldFieldHTTPErrRate string = "http_err_rate" + // StickTableFieldFieldHTTPFailCnt captures enum value "http_fail_cnt" + StickTableFieldFieldHTTPFailCnt string = "http_fail_cnt" + + // StickTableFieldFieldHTTPFailRate captures enum value "http_fail_rate" + StickTableFieldFieldHTTPFailRate string = "http_fail_rate" + // StickTableFieldFieldServerID captures enum value "server_id" StickTableFieldFieldServerID string = "server_id" diff --git a/models/stick_table_compare.go b/models/stick_table_compare.go index ac6b55d8..25f02502 100644 --- a/models/stick_table_compare.go +++ b/models/stick_table_compare.go @@ -130,6 +130,10 @@ func (s StickTableField) Equal(t StickTableField, opts ...Options) bool { return false } + if s.Idx != t.Idx { + return false + } + if s.Period != t.Period { return false } @@ -153,6 +157,10 @@ func (s StickTableField) Diff(t StickTableField, opts ...Options) map[string][]i diff["Field"] = []interface{}{s.Field, t.Field} } + if s.Idx != t.Idx { + diff["Idx"] = []interface{}{s.Idx, t.Idx} + } + if s.Period != t.Period { diff["Period"] = []interface{}{s.Period, t.Period} } diff --git a/models/stick_table_compare_test.go b/models/stick_table_compare_test.go index 83501c41..94fb70ab 100644 --- a/models/stick_table_compare_test.go +++ b/models/stick_table_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestStickTableEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample StickTable var result StickTable - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestStickTableEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StickTable to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestStickTableEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample StickTable var result StickTable - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Size = Ptr(*sample.Size + 1) result.Used = Ptr(*sample.Used + 1) @@ -96,11 +99,11 @@ func TestStickTableEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StickTable to be different, but it is not %s %s", a, b) } @@ -114,17 +117,17 @@ func TestStickTableDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample StickTable var result StickTable - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -138,11 +141,11 @@ func TestStickTableDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StickTable to be equal, but it is not %s %s, %v", a, b, result) } @@ -156,13 +159,13 @@ func TestStickTableDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample StickTable var result StickTable - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Size = Ptr(*sample.Size + 1) result.Used = Ptr(*sample.Used + 1) @@ -177,11 +180,11 @@ func TestStickTableDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StickTable to be different in 5 cases, but it is not (%d) %s %s", len(result), a, b) } @@ -195,17 +198,17 @@ func TestStickTableFieldEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample StickTableField var result StickTableField - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -219,11 +222,11 @@ func TestStickTableFieldEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StickTableField to be equal, but it is not %s %s", a, b) } @@ -237,14 +240,15 @@ func TestStickTableFieldEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample StickTableField var result StickTableField - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } + result.Idx = sample.Idx + 1 result.Period = sample.Period + 1 samples = append(samples, struct { a, b StickTableField @@ -257,11 +261,11 @@ func TestStickTableFieldEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StickTableField to be different, but it is not %s %s", a, b) } @@ -275,17 +279,17 @@ func TestStickTableFieldDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample StickTableField var result StickTableField - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -299,11 +303,11 @@ func TestStickTableFieldDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StickTableField to be equal, but it is not %s %s, %v", a, b, result) } @@ -317,14 +321,15 @@ func TestStickTableFieldDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample StickTableField var result StickTableField - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } + result.Idx = sample.Idx + 1 result.Period = sample.Period + 1 samples = append(samples, struct { a, b StickTableField @@ -333,17 +338,17 @@ func TestStickTableFieldDiffFalse(t *testing.T) { for _, sample := range samples { result := sample.a.Diff(sample.b) - if len(result) != 3 { + if len(result) != 4 { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - t.Errorf("Expected StickTableField to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) + t.Errorf("Expected StickTableField to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } } } diff --git a/models/stick_table_entries.go b/models/stick_table_entries.go index 779ae97c..fe664184 100644 --- a/models/stick_table_entries.go +++ b/models/stick_table_entries.go @@ -71,6 +71,11 @@ func (m StickTableEntries) ContextValidate(ctx context.Context, formats strfmt.R for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/stick_table_entry.go b/models/stick_table_entry.go index 4ea1f1b8..64ef42a4 100644 --- a/models/stick_table_entry.go +++ b/models/stick_table_entry.go @@ -23,6 +23,7 @@ package models import ( "context" + "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" ) @@ -58,6 +59,15 @@ type StickTableEntry struct { // exp Exp *int64 `json:"exp,omitempty"` + // glitch cnt + GlitchCnt *int64 `json:"glitch_cnt,omitempty"` + + // glitch rate + GlitchRate *int64 `json:"glitch_rate,omitempty"` + + // gpc + Gpc *StickTableEntryGpc `json:"gpc,omitempty"` + // gpc0 Gpc0 *int64 `json:"gpc0,omitempty"` @@ -70,6 +80,12 @@ type StickTableEntry struct { // gpc1 rate Gpc1Rate *int64 `json:"gpc1_rate,omitempty"` + // gpc rate + GpcRate *StickTableEntryGpcRate `json:"gpc_rate,omitempty"` + + // gpt + Gpt *StickTableEntryGpt `json:"gpt,omitempty"` + // gpt0 Gpt0 *int64 `json:"gpt0,omitempty"` @@ -79,6 +95,12 @@ type StickTableEntry struct { // http err rate HTTPErrRate *int64 `json:"http_err_rate,omitempty"` + // http fail cnt + HTTPFailCnt *int64 `json:"http_fail_cnt,omitempty"` + + // http fail rate + HTTPFailRate *int64 `json:"http_fail_rate,omitempty"` + // http req cnt HTTPReqCnt *int64 `json:"http_req_cnt,omitempty"` @@ -106,11 +128,165 @@ type StickTableEntry struct { // Validate validates this stick table entry func (m *StickTableEntry) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateGpc(formats); err != nil { + res = append(res, err) + } + + if err := m.validateGpcRate(formats); err != nil { + res = append(res, err) + } + + if err := m.validateGpt(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } return nil } -// ContextValidate validates this stick table entry based on context it is used +func (m *StickTableEntry) validateGpc(formats strfmt.Registry) error { + if swag.IsZero(m.Gpc) { // not required + return nil + } + + if m.Gpc != nil { + if err := m.Gpc.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("gpc") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("gpc") + } + return err + } + } + + return nil +} + +func (m *StickTableEntry) validateGpcRate(formats strfmt.Registry) error { + if swag.IsZero(m.GpcRate) { // not required + return nil + } + + if m.GpcRate != nil { + if err := m.GpcRate.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("gpc_rate") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("gpc_rate") + } + return err + } + } + + return nil +} + +func (m *StickTableEntry) validateGpt(formats strfmt.Registry) error { + if swag.IsZero(m.Gpt) { // not required + return nil + } + + if m.Gpt != nil { + if err := m.Gpt.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("gpt") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("gpt") + } + return err + } + } + + return nil +} + +// ContextValidate validate this stick table entry based on the context it is used func (m *StickTableEntry) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateGpc(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateGpcRate(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateGpt(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *StickTableEntry) contextValidateGpc(ctx context.Context, formats strfmt.Registry) error { + + if m.Gpc != nil { + + if swag.IsZero(m.Gpc) { // not required + return nil + } + + if err := m.Gpc.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("gpc") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("gpc") + } + return err + } + } + + return nil +} + +func (m *StickTableEntry) contextValidateGpcRate(ctx context.Context, formats strfmt.Registry) error { + + if m.GpcRate != nil { + + if swag.IsZero(m.GpcRate) { // not required + return nil + } + + if err := m.GpcRate.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("gpc_rate") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("gpc_rate") + } + return err + } + } + + return nil +} + +func (m *StickTableEntry) contextValidateGpt(ctx context.Context, formats strfmt.Registry) error { + + if m.Gpt != nil { + + if swag.IsZero(m.Gpt) { // not required + return nil + } + + if err := m.Gpt.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("gpt") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("gpt") + } + return err + } + } + return nil } @@ -131,3 +307,123 @@ func (m *StickTableEntry) UnmarshalBinary(b []byte) error { *m = res return nil } + +// StickTableEntryGpc stick table entry gpc +// +// swagger:model StickTableEntryGpc +type StickTableEntryGpc struct { + + // idx + Idx int64 `json:"idx,omitempty"` + + // value + Value *int64 `json:"value,omitempty"` +} + +// Validate validates this stick table entry gpc +func (m *StickTableEntryGpc) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this stick table entry gpc based on context it is used +func (m *StickTableEntryGpc) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *StickTableEntryGpc) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *StickTableEntryGpc) UnmarshalBinary(b []byte) error { + var res StickTableEntryGpc + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} + +// StickTableEntryGpcRate stick table entry gpc rate +// +// swagger:model StickTableEntryGpcRate +type StickTableEntryGpcRate struct { + + // idx + Idx int64 `json:"idx,omitempty"` + + // value + Value *int64 `json:"value,omitempty"` +} + +// Validate validates this stick table entry gpc rate +func (m *StickTableEntryGpcRate) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this stick table entry gpc rate based on context it is used +func (m *StickTableEntryGpcRate) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *StickTableEntryGpcRate) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *StickTableEntryGpcRate) UnmarshalBinary(b []byte) error { + var res StickTableEntryGpcRate + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} + +// StickTableEntryGpt stick table entry gpt +// +// swagger:model StickTableEntryGpt +type StickTableEntryGpt struct { + + // idx + Idx int64 `json:"idx,omitempty"` + + // value + Value *int64 `json:"value,omitempty"` +} + +// Validate validates this stick table entry gpt +func (m *StickTableEntryGpt) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this stick table entry gpt based on context it is used +func (m *StickTableEntryGpt) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *StickTableEntryGpt) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *StickTableEntryGpt) UnmarshalBinary(b []byte) error { + var res StickTableEntryGpt + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/models/stick_table_entry_compare.go b/models/stick_table_entry_compare.go index 185cdf17..92356042 100644 --- a/models/stick_table_entry_compare.go +++ b/models/stick_table_entry_compare.go @@ -19,11 +19,20 @@ package models // Equal checks if two structs of type StickTableEntry are equal // +// By default empty maps and slices are equal to nil: +// // var a, b StickTableEntry // equal := a.Equal(b) // -// opts ...Options are ignored in this method +// For more advanced use case you can configure these options (default values are shown): +// +// var a, b StickTableEntry +// equal := a.Equal(b,Options{ +// NilSameAsEmpty: true, +// }) func (s StickTableEntry) Equal(t StickTableEntry, opts ...Options) bool { + opt := getOptions(opts...) + if !equalPointers(s.BytesInCnt, t.BytesInCnt) { return false } @@ -56,6 +65,36 @@ func (s StickTableEntry) Equal(t StickTableEntry, opts ...Options) bool { return false } + if !equalPointers(s.GlitchCnt, t.GlitchCnt) { + return false + } + + if !equalPointers(s.GlitchRate, t.GlitchRate) { + return false + } + + if s.Gpc == nil || t.Gpc == nil { + if s.Gpc != nil || t.Gpc != nil { + if opt.NilSameAsEmpty { + empty := &StickTableEntryGpc{} + if s.Gpc == nil { + if !(t.Gpc.Equal(*empty)) { + return false + } + } + if t.Gpc == nil { + if !(s.Gpc.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Gpc.Equal(*t.Gpc, opt) { + return false + } + if !equalPointers(s.Gpc0, t.Gpc0) { return false } @@ -72,6 +111,50 @@ func (s StickTableEntry) Equal(t StickTableEntry, opts ...Options) bool { return false } + if s.GpcRate == nil || t.GpcRate == nil { + if s.GpcRate != nil || t.GpcRate != nil { + if opt.NilSameAsEmpty { + empty := &StickTableEntryGpcRate{} + if s.GpcRate == nil { + if !(t.GpcRate.Equal(*empty)) { + return false + } + } + if t.GpcRate == nil { + if !(s.GpcRate.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.GpcRate.Equal(*t.GpcRate, opt) { + return false + } + + if s.Gpt == nil || t.Gpt == nil { + if s.Gpt != nil || t.Gpt != nil { + if opt.NilSameAsEmpty { + empty := &StickTableEntryGpt{} + if s.Gpt == nil { + if !(t.Gpt.Equal(*empty)) { + return false + } + } + if t.Gpt == nil { + if !(s.Gpt.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Gpt.Equal(*t.Gpt, opt) { + return false + } + if !equalPointers(s.Gpt0, t.Gpt0) { return false } @@ -84,6 +167,14 @@ func (s StickTableEntry) Equal(t StickTableEntry, opts ...Options) bool { return false } + if !equalPointers(s.HTTPFailCnt, t.HTTPFailCnt) { + return false + } + + if !equalPointers(s.HTTPFailRate, t.HTTPFailRate) { + return false + } + if !equalPointers(s.HTTPReqCnt, t.HTTPReqCnt) { return false } @@ -121,11 +212,20 @@ func (s StickTableEntry) Equal(t StickTableEntry, opts ...Options) bool { // Diff checks if two structs of type StickTableEntry are equal // +// By default empty maps and slices are equal to nil: +// // var a, b StickTableEntry // diff := a.Diff(b) // -// opts ...Options are ignored in this method +// For more advanced use case you can configure these options (default values are shown): +// +// var a, b StickTableEntry +// diff := a.Diff(b,Options{ +// NilSameAsEmpty: true, +// }) func (s StickTableEntry) Diff(t StickTableEntry, opts ...Options) map[string][]interface{} { + opt := getOptions(opts...) + diff := make(map[string][]interface{}) if !equalPointers(s.BytesInCnt, t.BytesInCnt) { diff["BytesInCnt"] = []interface{}{ValueOrNil(s.BytesInCnt), ValueOrNil(t.BytesInCnt)} @@ -159,6 +259,36 @@ func (s StickTableEntry) Diff(t StickTableEntry, opts ...Options) map[string][]i diff["Exp"] = []interface{}{ValueOrNil(s.Exp), ValueOrNil(t.Exp)} } + if !equalPointers(s.GlitchCnt, t.GlitchCnt) { + diff["GlitchCnt"] = []interface{}{ValueOrNil(s.GlitchCnt), ValueOrNil(t.GlitchCnt)} + } + + if !equalPointers(s.GlitchRate, t.GlitchRate) { + diff["GlitchRate"] = []interface{}{ValueOrNil(s.GlitchRate), ValueOrNil(t.GlitchRate)} + } + + if s.Gpc == nil || t.Gpc == nil { + if s.Gpc != nil || t.Gpc != nil { + if opt.NilSameAsEmpty { + empty := &StickTableEntryGpc{} + if s.Gpc == nil { + if !(t.Gpc.Equal(*empty)) { + diff["Gpc"] = []interface{}{ValueOrNil(s.Gpc), ValueOrNil(t.Gpc)} + } + } + if t.Gpc == nil { + if !(s.Gpc.Equal(*empty)) { + diff["Gpc"] = []interface{}{ValueOrNil(s.Gpc), ValueOrNil(t.Gpc)} + } + } + } else { + diff["Gpc"] = []interface{}{ValueOrNil(s.Gpc), ValueOrNil(t.Gpc)} + } + } + } else if !s.Gpc.Equal(*t.Gpc, opt) { + diff["Gpc"] = []interface{}{ValueOrNil(s.Gpc), ValueOrNil(t.Gpc)} + } + if !equalPointers(s.Gpc0, t.Gpc0) { diff["Gpc0"] = []interface{}{ValueOrNil(s.Gpc0), ValueOrNil(t.Gpc0)} } @@ -175,6 +305,50 @@ func (s StickTableEntry) Diff(t StickTableEntry, opts ...Options) map[string][]i diff["Gpc1Rate"] = []interface{}{ValueOrNil(s.Gpc1Rate), ValueOrNil(t.Gpc1Rate)} } + if s.GpcRate == nil || t.GpcRate == nil { + if s.GpcRate != nil || t.GpcRate != nil { + if opt.NilSameAsEmpty { + empty := &StickTableEntryGpcRate{} + if s.GpcRate == nil { + if !(t.GpcRate.Equal(*empty)) { + diff["GpcRate"] = []interface{}{ValueOrNil(s.GpcRate), ValueOrNil(t.GpcRate)} + } + } + if t.GpcRate == nil { + if !(s.GpcRate.Equal(*empty)) { + diff["GpcRate"] = []interface{}{ValueOrNil(s.GpcRate), ValueOrNil(t.GpcRate)} + } + } + } else { + diff["GpcRate"] = []interface{}{ValueOrNil(s.GpcRate), ValueOrNil(t.GpcRate)} + } + } + } else if !s.GpcRate.Equal(*t.GpcRate, opt) { + diff["GpcRate"] = []interface{}{ValueOrNil(s.GpcRate), ValueOrNil(t.GpcRate)} + } + + if s.Gpt == nil || t.Gpt == nil { + if s.Gpt != nil || t.Gpt != nil { + if opt.NilSameAsEmpty { + empty := &StickTableEntryGpt{} + if s.Gpt == nil { + if !(t.Gpt.Equal(*empty)) { + diff["Gpt"] = []interface{}{ValueOrNil(s.Gpt), ValueOrNil(t.Gpt)} + } + } + if t.Gpt == nil { + if !(s.Gpt.Equal(*empty)) { + diff["Gpt"] = []interface{}{ValueOrNil(s.Gpt), ValueOrNil(t.Gpt)} + } + } + } else { + diff["Gpt"] = []interface{}{ValueOrNil(s.Gpt), ValueOrNil(t.Gpt)} + } + } + } else if !s.Gpt.Equal(*t.Gpt, opt) { + diff["Gpt"] = []interface{}{ValueOrNil(s.Gpt), ValueOrNil(t.Gpt)} + } + if !equalPointers(s.Gpt0, t.Gpt0) { diff["Gpt0"] = []interface{}{ValueOrNil(s.Gpt0), ValueOrNil(t.Gpt0)} } @@ -187,6 +361,14 @@ func (s StickTableEntry) Diff(t StickTableEntry, opts ...Options) map[string][]i diff["HTTPErrRate"] = []interface{}{ValueOrNil(s.HTTPErrRate), ValueOrNil(t.HTTPErrRate)} } + if !equalPointers(s.HTTPFailCnt, t.HTTPFailCnt) { + diff["HTTPFailCnt"] = []interface{}{ValueOrNil(s.HTTPFailCnt), ValueOrNil(t.HTTPFailCnt)} + } + + if !equalPointers(s.HTTPFailRate, t.HTTPFailRate) { + diff["HTTPFailRate"] = []interface{}{ValueOrNil(s.HTTPFailRate), ValueOrNil(t.HTTPFailRate)} + } + if !equalPointers(s.HTTPReqCnt, t.HTTPReqCnt) { diff["HTTPReqCnt"] = []interface{}{ValueOrNil(s.HTTPReqCnt), ValueOrNil(t.HTTPReqCnt)} } @@ -221,3 +403,114 @@ func (s StickTableEntry) Diff(t StickTableEntry, opts ...Options) map[string][]i return diff } + +// Equal checks if two structs of type StickTableEntryGpc are equal +// +// var a, b StickTableEntryGpc +// equal := a.Equal(b) +// +// opts ...Options are ignored in this method +func (s StickTableEntryGpc) Equal(t StickTableEntryGpc, opts ...Options) bool { + if s.Idx != t.Idx { + return false + } + + if !equalPointers(s.Value, t.Value) { + return false + } + + return true +} + +// Diff checks if two structs of type StickTableEntryGpc are equal +// +// var a, b StickTableEntryGpc +// diff := a.Diff(b) +// +// opts ...Options are ignored in this method +func (s StickTableEntryGpc) Diff(t StickTableEntryGpc, opts ...Options) map[string][]interface{} { + diff := make(map[string][]interface{}) + if s.Idx != t.Idx { + diff["Idx"] = []interface{}{s.Idx, t.Idx} + } + + if !equalPointers(s.Value, t.Value) { + diff["Value"] = []interface{}{ValueOrNil(s.Value), ValueOrNil(t.Value)} + } + + return diff +} + +// Equal checks if two structs of type StickTableEntryGpcRate are equal +// +// var a, b StickTableEntryGpcRate +// equal := a.Equal(b) +// +// opts ...Options are ignored in this method +func (s StickTableEntryGpcRate) Equal(t StickTableEntryGpcRate, opts ...Options) bool { + if s.Idx != t.Idx { + return false + } + + if !equalPointers(s.Value, t.Value) { + return false + } + + return true +} + +// Diff checks if two structs of type StickTableEntryGpcRate are equal +// +// var a, b StickTableEntryGpcRate +// diff := a.Diff(b) +// +// opts ...Options are ignored in this method +func (s StickTableEntryGpcRate) Diff(t StickTableEntryGpcRate, opts ...Options) map[string][]interface{} { + diff := make(map[string][]interface{}) + if s.Idx != t.Idx { + diff["Idx"] = []interface{}{s.Idx, t.Idx} + } + + if !equalPointers(s.Value, t.Value) { + diff["Value"] = []interface{}{ValueOrNil(s.Value), ValueOrNil(t.Value)} + } + + return diff +} + +// Equal checks if two structs of type StickTableEntryGpt are equal +// +// var a, b StickTableEntryGpt +// equal := a.Equal(b) +// +// opts ...Options are ignored in this method +func (s StickTableEntryGpt) Equal(t StickTableEntryGpt, opts ...Options) bool { + if s.Idx != t.Idx { + return false + } + + if !equalPointers(s.Value, t.Value) { + return false + } + + return true +} + +// Diff checks if two structs of type StickTableEntryGpt are equal +// +// var a, b StickTableEntryGpt +// diff := a.Diff(b) +// +// opts ...Options are ignored in this method +func (s StickTableEntryGpt) Diff(t StickTableEntryGpt, opts ...Options) map[string][]interface{} { + diff := make(map[string][]interface{}) + if s.Idx != t.Idx { + diff["Idx"] = []interface{}{s.Idx, t.Idx} + } + + if !equalPointers(s.Value, t.Value) { + diff["Value"] = []interface{}{ValueOrNil(s.Value), ValueOrNil(t.Value)} + } + + return diff +} diff --git a/models/stick_table_entry_compare_test.go b/models/stick_table_entry_compare_test.go index f7ff6101..b684cd08 100644 --- a/models/stick_table_entry_compare_test.go +++ b/models/stick_table_entry_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestStickTableEntryEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample StickTableEntry var result StickTableEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestStickTableEntryEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StickTableEntry to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestStickTableEntryEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample StickTableEntry var result StickTableEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.BytesInCnt = Ptr(*sample.BytesInCnt + 1) result.BytesInRate = Ptr(*sample.BytesInRate + 1) @@ -91,6 +94,8 @@ func TestStickTableEntryEqualFalse(t *testing.T) { result.ConnCur = Ptr(*sample.ConnCur + 1) result.ConnRate = Ptr(*sample.ConnRate + 1) result.Exp = Ptr(*sample.Exp + 1) + result.GlitchCnt = Ptr(*sample.GlitchCnt + 1) + result.GlitchRate = Ptr(*sample.GlitchRate + 1) result.Gpc0 = Ptr(*sample.Gpc0 + 1) result.Gpc0Rate = Ptr(*sample.Gpc0Rate + 1) result.Gpc1 = Ptr(*sample.Gpc1 + 1) @@ -98,6 +103,8 @@ func TestStickTableEntryEqualFalse(t *testing.T) { result.Gpt0 = Ptr(*sample.Gpt0 + 1) result.HTTPErrCnt = Ptr(*sample.HTTPErrCnt + 1) result.HTTPErrRate = Ptr(*sample.HTTPErrRate + 1) + result.HTTPFailCnt = Ptr(*sample.HTTPFailCnt + 1) + result.HTTPFailRate = Ptr(*sample.HTTPFailRate + 1) result.HTTPReqCnt = Ptr(*sample.HTTPReqCnt + 1) result.HTTPReqRate = Ptr(*sample.HTTPReqRate + 1) result.ServerID = Ptr(*sample.ServerID + 1) @@ -115,11 +122,11 @@ func TestStickTableEntryEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StickTableEntry to be different, but it is not %s %s", a, b) } @@ -133,17 +140,17 @@ func TestStickTableEntryDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample StickTableEntry var result StickTableEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -157,11 +164,11 @@ func TestStickTableEntryDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected StickTableEntry to be equal, but it is not %s %s, %v", a, b, result) } @@ -175,13 +182,13 @@ func TestStickTableEntryDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample StickTableEntry var result StickTableEntry - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.BytesInCnt = Ptr(*sample.BytesInCnt + 1) result.BytesInRate = Ptr(*sample.BytesInRate + 1) @@ -191,6 +198,8 @@ func TestStickTableEntryDiffFalse(t *testing.T) { result.ConnCur = Ptr(*sample.ConnCur + 1) result.ConnRate = Ptr(*sample.ConnRate + 1) result.Exp = Ptr(*sample.Exp + 1) + result.GlitchCnt = Ptr(*sample.GlitchCnt + 1) + result.GlitchRate = Ptr(*sample.GlitchRate + 1) result.Gpc0 = Ptr(*sample.Gpc0 + 1) result.Gpc0Rate = Ptr(*sample.Gpc0Rate + 1) result.Gpc1 = Ptr(*sample.Gpc1 + 1) @@ -198,6 +207,8 @@ func TestStickTableEntryDiffFalse(t *testing.T) { result.Gpt0 = Ptr(*sample.Gpt0 + 1) result.HTTPErrCnt = Ptr(*sample.HTTPErrCnt + 1) result.HTTPErrRate = Ptr(*sample.HTTPErrRate + 1) + result.HTTPFailCnt = Ptr(*sample.HTTPFailCnt + 1) + result.HTTPFailRate = Ptr(*sample.HTTPFailRate + 1) result.HTTPReqCnt = Ptr(*sample.HTTPReqCnt + 1) result.HTTPReqRate = Ptr(*sample.HTTPReqRate + 1) result.ServerID = Ptr(*sample.ServerID + 1) @@ -211,17 +222,503 @@ func TestStickTableEntryDiffFalse(t *testing.T) { for _, sample := range samples { result := sample.a.Diff(sample.b) - if len(result) != 23 { + if len(result) != 30 { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Error(err) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Error(err) + } + t.Errorf("Expected StickTableEntry to be different in 30 cases, but it is not (%d) %s %s", len(result), a, b) + } + } +} + +func TestStickTableEntryGpcEqual(t *testing.T) { + samples := []struct { + a, b StickTableEntryGpc + }{} + for i := 0; i < 2; i++ { + var sample StickTableEntryGpc + var result StickTableEntryGpc + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + byteJSON, err := json.Marshal(sample) + if err != nil { + t.Error(err) + } + err = json.Unmarshal(byteJSON, &result) + if err != nil { + t.Error(err) + } + + samples = append(samples, struct { + a, b StickTableEntryGpc + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Equal(sample.b) + if !result { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Error(err) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Error(err) + } + t.Errorf("Expected StickTableEntryGpc to be equal, but it is not %s %s", a, b) + } + } +} + +func TestStickTableEntryGpcEqualFalse(t *testing.T) { + samples := []struct { + a, b StickTableEntryGpc + }{} + for i := 0; i < 2; i++ { + var sample StickTableEntryGpc + var result StickTableEntryGpc + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + result.Idx = sample.Idx + 1 + result.Value = Ptr(*sample.Value + 1) + samples = append(samples, struct { + a, b StickTableEntryGpc + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Equal(sample.b) + if result { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Error(err) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Error(err) + } + t.Errorf("Expected StickTableEntryGpc to be different, but it is not %s %s", a, b) + } + } +} + +func TestStickTableEntryGpcDiff(t *testing.T) { + samples := []struct { + a, b StickTableEntryGpc + }{} + for i := 0; i < 2; i++ { + var sample StickTableEntryGpc + var result StickTableEntryGpc + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + byteJSON, err := json.Marshal(sample) + if err != nil { + t.Error(err) + } + err = json.Unmarshal(byteJSON, &result) + if err != nil { + t.Error(err) + } + + samples = append(samples, struct { + a, b StickTableEntryGpc + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Diff(sample.b) + if len(result) != 0 { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Error(err) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Error(err) + } + t.Errorf("Expected StickTableEntryGpc to be equal, but it is not %s %s, %v", a, b, result) + } + } +} + +func TestStickTableEntryGpcDiffFalse(t *testing.T) { + samples := []struct { + a, b StickTableEntryGpc + }{} + for i := 0; i < 2; i++ { + var sample StickTableEntryGpc + var result StickTableEntryGpc + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + result.Idx = sample.Idx + 1 + result.Value = Ptr(*sample.Value + 1) + samples = append(samples, struct { + a, b StickTableEntryGpc + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Diff(sample.b) + if len(result) != 2 { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Error(err) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Error(err) + } + t.Errorf("Expected StickTableEntryGpc to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) + } + } +} + +func TestStickTableEntryGpcRateEqual(t *testing.T) { + samples := []struct { + a, b StickTableEntryGpcRate + }{} + for i := 0; i < 2; i++ { + var sample StickTableEntryGpcRate + var result StickTableEntryGpcRate + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + byteJSON, err := json.Marshal(sample) + if err != nil { + t.Error(err) + } + err = json.Unmarshal(byteJSON, &result) + if err != nil { + t.Error(err) + } + + samples = append(samples, struct { + a, b StickTableEntryGpcRate + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Equal(sample.b) + if !result { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Error(err) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Error(err) + } + t.Errorf("Expected StickTableEntryGpcRate to be equal, but it is not %s %s", a, b) + } + } +} + +func TestStickTableEntryGpcRateEqualFalse(t *testing.T) { + samples := []struct { + a, b StickTableEntryGpcRate + }{} + for i := 0; i < 2; i++ { + var sample StickTableEntryGpcRate + var result StickTableEntryGpcRate + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + result.Idx = sample.Idx + 1 + result.Value = Ptr(*sample.Value + 1) + samples = append(samples, struct { + a, b StickTableEntryGpcRate + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Equal(sample.b) + if result { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Error(err) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Error(err) + } + t.Errorf("Expected StickTableEntryGpcRate to be different, but it is not %s %s", a, b) + } + } +} + +func TestStickTableEntryGpcRateDiff(t *testing.T) { + samples := []struct { + a, b StickTableEntryGpcRate + }{} + for i := 0; i < 2; i++ { + var sample StickTableEntryGpcRate + var result StickTableEntryGpcRate + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + byteJSON, err := json.Marshal(sample) + if err != nil { + t.Error(err) + } + err = json.Unmarshal(byteJSON, &result) + if err != nil { + t.Error(err) + } + + samples = append(samples, struct { + a, b StickTableEntryGpcRate + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Diff(sample.b) + if len(result) != 0 { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Error(err) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Error(err) + } + t.Errorf("Expected StickTableEntryGpcRate to be equal, but it is not %s %s, %v", a, b, result) + } + } +} + +func TestStickTableEntryGpcRateDiffFalse(t *testing.T) { + samples := []struct { + a, b StickTableEntryGpcRate + }{} + for i := 0; i < 2; i++ { + var sample StickTableEntryGpcRate + var result StickTableEntryGpcRate + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + result.Idx = sample.Idx + 1 + result.Value = Ptr(*sample.Value + 1) + samples = append(samples, struct { + a, b StickTableEntryGpcRate + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Diff(sample.b) + if len(result) != 2 { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Error(err) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Error(err) + } + t.Errorf("Expected StickTableEntryGpcRate to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) + } + } +} + +func TestStickTableEntryGptEqual(t *testing.T) { + samples := []struct { + a, b StickTableEntryGpt + }{} + for i := 0; i < 2; i++ { + var sample StickTableEntryGpt + var result StickTableEntryGpt + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + byteJSON, err := json.Marshal(sample) + if err != nil { + t.Error(err) + } + err = json.Unmarshal(byteJSON, &result) + if err != nil { + t.Error(err) + } + + samples = append(samples, struct { + a, b StickTableEntryGpt + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Equal(sample.b) + if !result { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Error(err) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Error(err) + } + t.Errorf("Expected StickTableEntryGpt to be equal, but it is not %s %s", a, b) + } + } +} + +func TestStickTableEntryGptEqualFalse(t *testing.T) { + samples := []struct { + a, b StickTableEntryGpt + }{} + for i := 0; i < 2; i++ { + var sample StickTableEntryGpt + var result StickTableEntryGpt + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + result.Idx = sample.Idx + 1 + result.Value = Ptr(*sample.Value + 1) + samples = append(samples, struct { + a, b StickTableEntryGpt + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Equal(sample.b) + if result { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Error(err) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Error(err) + } + t.Errorf("Expected StickTableEntryGpt to be different, but it is not %s %s", a, b) + } + } +} + +func TestStickTableEntryGptDiff(t *testing.T) { + samples := []struct { + a, b StickTableEntryGpt + }{} + for i := 0; i < 2; i++ { + var sample StickTableEntryGpt + var result StickTableEntryGpt + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + byteJSON, err := json.Marshal(sample) + if err != nil { + t.Error(err) + } + err = json.Unmarshal(byteJSON, &result) + if err != nil { + t.Error(err) + } + + samples = append(samples, struct { + a, b StickTableEntryGpt + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Diff(sample.b) + if len(result) != 0 { + json := jsoniter.ConfigCompatibleWithStandardLibrary + a, err := json.Marshal(&sample.a) + if err != nil { + t.Error(err) + } + b, err := json.Marshal(&sample.b) + if err != nil { + t.Error(err) + } + t.Errorf("Expected StickTableEntryGpt to be equal, but it is not %s %s, %v", a, b, result) + } + } +} + +func TestStickTableEntryGptDiffFalse(t *testing.T) { + samples := []struct { + a, b StickTableEntryGpt + }{} + for i := 0; i < 2; i++ { + var sample StickTableEntryGpt + var result StickTableEntryGpt + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) + if err != nil { + t.Error(err) + } + result.Idx = sample.Idx + 1 + result.Value = Ptr(*sample.Value + 1) + samples = append(samples, struct { + a, b StickTableEntryGpt + }{sample, result}) + } + + for _, sample := range samples { + result := sample.a.Diff(sample.b) + if len(result) != 2 { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - t.Errorf("Expected StickTableEntry to be different in 23 cases, but it is not (%d) %s %s", len(result), a, b) + t.Errorf("Expected StickTableEntryGpt to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } } } diff --git a/models/stick_tables.go b/models/stick_tables.go index fe1d97ad..10be1e11 100644 --- a/models/stick_tables.go +++ b/models/stick_tables.go @@ -71,6 +71,11 @@ func (m StickTables) ContextValidate(ctx context.Context, formats strfmt.Registr for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/table.go b/models/table.go index 063ad497..0449cdf3 100644 --- a/models/table.go +++ b/models/table.go @@ -54,7 +54,7 @@ type Table struct { Store string `json:"store,omitempty"` // type - // Enum: [ip integer string binary] + // Enum: ["ip","integer","string","binary"] // +kubebuilder:validation:Enum=ip;integer;string;binary; Type string `json:"type,omitempty"` diff --git a/models/table_compare_test.go b/models/table_compare_test.go index 2a9a55bf..97a042b4 100644 --- a/models/table_compare_test.go +++ b/models/table_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestTableEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Table var result Table - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestTableEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Table to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestTableEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Table var result Table - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.NoPurge = !sample.NoPurge result.TypeLen = Ptr(*sample.TypeLen + 1) @@ -96,11 +99,11 @@ func TestTableEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Table to be different, but it is not %s %s", a, b) } @@ -114,17 +117,17 @@ func TestTableDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Table var result Table - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -138,11 +141,11 @@ func TestTableDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Table to be equal, but it is not %s %s, %v", a, b, result) } @@ -156,13 +159,13 @@ func TestTableDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Table var result Table - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.NoPurge = !sample.NoPurge result.TypeLen = Ptr(*sample.TypeLen + 1) @@ -177,11 +180,11 @@ func TestTableDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Table to be different in 8 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/tables.go b/models/tables.go index 89c0d7f9..fb5362f8 100644 --- a/models/tables.go +++ b/models/tables.go @@ -71,6 +71,11 @@ func (m Tables) ContextValidate(ctx context.Context, formats strfmt.Registry) er for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/tcp_check.go b/models/tcp_check.go index 8fa4f8bd..8542f4aa 100644 --- a/models/tcp_check.go +++ b/models/tcp_check.go @@ -36,7 +36,7 @@ import ( type TCPCheck struct { // action // Required: true - // Enum: [comment connect expect send send-lf send-binary send-binary-lf set-var set-var-fmt unset-var] + // Enum: ["comment","connect","expect","send","send-lf","send-binary","send-binary-lf","set-var","set-var-fmt","unset-var"] // +kubebuilder:validation:Enum=comment;connect;expect;send;send-lf;send-binary;send-binary-lf;set-var;set-var-fmt;unset-var; Action string `json:"action"` @@ -60,7 +60,7 @@ type TCPCheck struct { Default bool `json:"default,omitempty"` // error status - // Enum: [L7OKC L7RSP L7STS L6RSP L4CON] + // Enum: ["L7OKC","L7RSP","L7STS","L6RSP","L4CON"] // +kubebuilder:validation:Enum=L7OKC;L7RSP;L7STS;L6RSP;L4CON; ErrorStatus string `json:"error_status,omitempty"` @@ -81,7 +81,7 @@ type TCPCheck struct { // match // Pattern: ^[^\s]+$ - // Enum: [string rstring string-lf binary rbinary binary-lf] + // Enum: ["string","rstring","string-lf","binary","rbinary","binary-lf"] // +kubebuilder:validation:Pattern=`^[^\s]+$` // +kubebuilder:validation:Enum=string;rstring;string-lf;binary;rbinary;binary-lf; Match string `json:"match,omitempty"` @@ -90,7 +90,7 @@ type TCPCheck struct { MinRecv int64 `json:"min_recv,omitempty"` // ok status - // Enum: [L7OK L7OKC L6OK L4OK] + // Enum: ["L7OK","L7OKC","L6OK","L4OK"] // +kubebuilder:validation:Enum=L7OK;L7OKC;L6OK;L4OK; OkStatus string `json:"ok_status,omitempty"` @@ -129,7 +129,7 @@ type TCPCheck struct { StatusCode string `json:"status-code,omitempty"` // tout status - // Enum: [L7TOUT L6TOUT L4TOUT] + // Enum: ["L7TOUT","L6TOUT","L4TOUT"] // +kubebuilder:validation:Enum=L7TOUT;L6TOUT;L4TOUT; ToutStatus string `json:"tout_status,omitempty"` diff --git a/models/tcp_check_compare_test.go b/models/tcp_check_compare_test.go index f4e483d6..4a7cad5f 100644 --- a/models/tcp_check_compare_test.go +++ b/models/tcp_check_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestTCPCheckEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample TCPCheck var result TCPCheck - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestTCPCheckEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TCPCheck to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestTCPCheckEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TCPCheck var result TCPCheck - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Default = !sample.Default result.ExclamationMark = !sample.ExclamationMark @@ -102,11 +105,11 @@ func TestTCPCheckEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TCPCheck to be different, but it is not %s %s", a, b) } @@ -120,17 +123,17 @@ func TestTCPCheckDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample TCPCheck var result TCPCheck - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -144,11 +147,11 @@ func TestTCPCheckDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TCPCheck to be equal, but it is not %s %s, %v", a, b, result) } @@ -162,13 +165,13 @@ func TestTCPCheckDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TCPCheck var result TCPCheck - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Default = !sample.Default result.ExclamationMark = !sample.ExclamationMark @@ -189,11 +192,11 @@ func TestTCPCheckDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TCPCheck to be different in 31 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/tcp_checks.go b/models/tcp_checks.go index 9975ddc3..a958fba9 100644 --- a/models/tcp_checks.go +++ b/models/tcp_checks.go @@ -69,6 +69,11 @@ func (m TCPChecks) ContextValidate(ctx context.Context, formats strfmt.Registry) for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/tcp_request_rule.go b/models/tcp_request_rule.go index f12bce7f..d8487ed6 100644 --- a/models/tcp_request_rule.go +++ b/models/tcp_request_rule.go @@ -38,8 +38,8 @@ import ( // swagger:model tcp_request_rule type TCPRequestRule struct { // action - // Enum: [accept attach-srv capture do-resolve expect-netscaler-cip expect-proxy lua reject sc-add-gpc sc-inc-gpc sc-inc-gpc0 sc-inc-gpc1 sc-set-gpt sc-set-gpt0 send-spoe-group set-bandwidth-limit set-bc-mark set-bc-tos set-dst-port set-dst set-fc-mark set-fc-tos set-log-level set-mark set-nice set-priority-class set-priority-offset set-src set-src-port set-tos set-var set-var-fmt silent-drop switch-mode track-sc0 track-sc1 track-sc2 track-sc unset-var use-service] - // +kubebuilder:validation:Enum=accept;attach-srv;capture;do-resolve;expect-netscaler-cip;expect-proxy;lua;reject;sc-add-gpc;sc-inc-gpc;sc-inc-gpc0;sc-inc-gpc1;sc-set-gpt;sc-set-gpt0;send-spoe-group;set-bandwidth-limit;set-bc-mark;set-bc-tos;set-dst-port;set-dst;set-fc-mark;set-fc-tos;set-log-level;set-mark;set-nice;set-priority-class;set-priority-offset;set-src;set-src-port;set-tos;set-var;set-var-fmt;silent-drop;switch-mode;track-sc0;track-sc1;track-sc2;track-sc;unset-var;use-service; + // Enum: ["accept","attach-srv","capture","do-resolve","expect-netscaler-cip","expect-proxy","lua","reject","sc-add-gpc","sc-inc-gpc","sc-inc-gpc0","sc-inc-gpc1","sc-set-gpt","sc-set-gpt0","send-spoe-group","set-bandwidth-limit","set-bc-mark","set-bc-tos","set-dst-port","set-dst","set-fc-mark","set-fc-tos","set-log-level","set-mark","set-nice","set-priority-class","set-priority-offset","set-src","set-src-port","set-tos","set-var","set-var-fmt","silent-drop","switch-mode","track-sc","unset-var","use-service"] + // +kubebuilder:validation:Enum=accept;attach-srv;capture;do-resolve;expect-netscaler-cip;expect-proxy;lua;reject;sc-add-gpc;sc-inc-gpc;sc-inc-gpc0;sc-inc-gpc1;sc-set-gpt;sc-set-gpt0;send-spoe-group;set-bandwidth-limit;set-bc-mark;set-bc-tos;set-dst-port;set-dst;set-fc-mark;set-fc-tos;set-log-level;set-mark;set-nice;set-priority-class;set-priority-offset;set-src;set-src-port;set-tos;set-var;set-var-fmt;silent-drop;switch-mode;track-sc;unset-var;use-service; Action string `json:"action,omitempty"` // bandwidth limit limit @@ -55,12 +55,12 @@ type TCPRequestRule struct { CaptureLen int64 `json:"capture_len,omitempty"` // capture sample - // Pattern: ^[^\s]+$ - // +kubebuilder:validation:Pattern=`^[^\s]+$` + // Pattern: ^(?:[A-Za-z]+\("([A-Za-z\s]+)"\)|[A-Za-z]+) + // +kubebuilder:validation:Pattern=`^(?:[A-Za-z]+\("([A-Za-z\s]+)"\)|[A-Za-z]+)` CaptureSample string `json:"capture_sample,omitempty"` // cond - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond string `json:"cond,omitempty"` @@ -74,7 +74,7 @@ type TCPRequestRule struct { GptValue string `json:"gpt_value,omitempty"` // log level - // Enum: [emerg alert crit err warning notice info debug silent] + // Enum: ["emerg","alert","crit","err","warning","notice","info","debug","silent"] // +kubebuilder:validation:Enum=emerg;alert;crit;err;warning;notice;info;debug;silent; LogLevel string `json:"log_level,omitempty"` @@ -99,7 +99,7 @@ type TCPRequestRule struct { NiceValue int64 `json:"nice_value,omitempty"` // resolve protocol - // Enum: [ipv4 ipv6] + // Enum: ["ipv4","ipv6"] // +kubebuilder:validation:Enum=ipv4;ipv6; ResolveProtocol string `json:"resolve_protocol,omitempty"` @@ -109,6 +109,9 @@ type TCPRequestRule struct { // resolve var ResolveVar string `json:"resolve_var,omitempty"` + // rst ttl + RstTTL int64 `json:"rst_ttl,omitempty"` + // sc idx ScIdx string `json:"sc_idx,omitempty"` @@ -152,7 +155,7 @@ type TCPRequestRule struct { // type // Required: true - // Enum: [connection content inspect-delay session] + // Enum: ["connection","content","inspect-delay","session"] // +kubebuilder:validation:Enum=connection;content;inspect-delay;session; Type string `json:"type"` @@ -232,7 +235,7 @@ var tcpRequestRuleTypeActionPropEnum []interface{} func init() { var res []string - if err := json.Unmarshal([]byte(`["accept","attach-srv","capture","do-resolve","expect-netscaler-cip","expect-proxy","lua","reject","sc-add-gpc","sc-inc-gpc","sc-inc-gpc0","sc-inc-gpc1","sc-set-gpt","sc-set-gpt0","send-spoe-group","set-bandwidth-limit","set-bc-mark","set-bc-tos","set-dst-port","set-dst","set-fc-mark","set-fc-tos","set-log-level","set-mark","set-nice","set-priority-class","set-priority-offset","set-src","set-src-port","set-tos","set-var","set-var-fmt","silent-drop","switch-mode","track-sc0","track-sc1","track-sc2","track-sc","unset-var","use-service"]`), &res); err != nil { + if err := json.Unmarshal([]byte(`["accept","attach-srv","capture","do-resolve","expect-netscaler-cip","expect-proxy","lua","reject","sc-add-gpc","sc-inc-gpc","sc-inc-gpc0","sc-inc-gpc1","sc-set-gpt","sc-set-gpt0","send-spoe-group","set-bandwidth-limit","set-bc-mark","set-bc-tos","set-dst-port","set-dst","set-fc-mark","set-fc-tos","set-log-level","set-mark","set-nice","set-priority-class","set-priority-offset","set-src","set-src-port","set-tos","set-var","set-var-fmt","silent-drop","switch-mode","track-sc","unset-var","use-service"]`), &res); err != nil { panic(err) } for _, v := range res { @@ -344,15 +347,6 @@ const ( // TCPRequestRuleActionSwitchDashMode captures enum value "switch-mode" TCPRequestRuleActionSwitchDashMode string = "switch-mode" - // TCPRequestRuleActionTrackDashSc0 captures enum value "track-sc0" - TCPRequestRuleActionTrackDashSc0 string = "track-sc0" - - // TCPRequestRuleActionTrackDashSc1 captures enum value "track-sc1" - TCPRequestRuleActionTrackDashSc1 string = "track-sc1" - - // TCPRequestRuleActionTrackDashSc2 captures enum value "track-sc2" - TCPRequestRuleActionTrackDashSc2 string = "track-sc2" - // TCPRequestRuleActionTrackDashSc captures enum value "track-sc" TCPRequestRuleActionTrackDashSc string = "track-sc" @@ -389,7 +383,7 @@ func (m *TCPRequestRule) validateCaptureSample(formats strfmt.Registry) error { return nil } - if err := validate.Pattern("capture_sample", "body", m.CaptureSample, `^[^\s]+$`); err != nil { + if err := validate.Pattern("capture_sample", "body", m.CaptureSample, `^(?:[A-Za-z]+\("([A-Za-z\s]+)"\)|[A-Za-z]+)`); err != nil { return err } diff --git a/models/tcp_request_rule_compare.go b/models/tcp_request_rule_compare.go index 4211cd41..c2d22cd5 100644 --- a/models/tcp_request_rule_compare.go +++ b/models/tcp_request_rule_compare.go @@ -96,6 +96,10 @@ func (s TCPRequestRule) Equal(t TCPRequestRule, opts ...Options) bool { return false } + if s.RstTTL != t.RstTTL { + return false + } + if s.ScIdx != t.ScIdx { return false } @@ -247,6 +251,10 @@ func (s TCPRequestRule) Diff(t TCPRequestRule, opts ...Options) map[string][]int diff["ResolveVar"] = []interface{}{s.ResolveVar, t.ResolveVar} } + if s.RstTTL != t.RstTTL { + diff["RstTTL"] = []interface{}{s.RstTTL, t.RstTTL} + } + if s.ScIdx != t.ScIdx { diff["ScIdx"] = []interface{}{s.ScIdx, t.ScIdx} } diff --git a/models/tcp_request_rule_compare_test.go b/models/tcp_request_rule_compare_test.go index 7ac08cdd..921b4e56 100644 --- a/models/tcp_request_rule_compare_test.go +++ b/models/tcp_request_rule_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestTCPRequestRuleEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample TCPRequestRule var result TCPRequestRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestTCPRequestRuleEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TCPRequestRule to be equal, but it is not %s %s", a, b) } @@ -75,16 +78,17 @@ func TestTCPRequestRuleEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TCPRequestRule var result TCPRequestRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CaptureLen = sample.CaptureLen + 1 result.NiceValue = sample.NiceValue + 1 + result.RstTTL = sample.RstTTL + 1 result.ScInt = Ptr(*sample.ScInt + 1) result.Timeout = Ptr(*sample.Timeout + 1) result.TrackStickCounter = Ptr(*sample.TrackStickCounter + 1) @@ -99,11 +103,11 @@ func TestTCPRequestRuleEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TCPRequestRule to be different, but it is not %s %s", a, b) } @@ -117,17 +121,17 @@ func TestTCPRequestRuleDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample TCPRequestRule var result TCPRequestRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -141,11 +145,11 @@ func TestTCPRequestRuleDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TCPRequestRule to be equal, but it is not %s %s, %v", a, b, result) } @@ -159,16 +163,17 @@ func TestTCPRequestRuleDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TCPRequestRule var result TCPRequestRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CaptureLen = sample.CaptureLen + 1 result.NiceValue = sample.NiceValue + 1 + result.RstTTL = sample.RstTTL + 1 result.ScInt = Ptr(*sample.ScInt + 1) result.Timeout = Ptr(*sample.Timeout + 1) result.TrackStickCounter = Ptr(*sample.TrackStickCounter + 1) @@ -179,17 +184,17 @@ func TestTCPRequestRuleDiffFalse(t *testing.T) { for _, sample := range samples { result := sample.a.Diff(sample.b) - if len(result) != 35 { + if len(result) != 36 { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - t.Errorf("Expected TCPRequestRule to be different in 35 cases, but it is not (%d) %s %s", len(result), a, b) + t.Errorf("Expected TCPRequestRule to be different in 36 cases, but it is not (%d) %s %s", len(result), a, b) } } } diff --git a/models/tcp_request_rules.go b/models/tcp_request_rules.go index b2dadd96..249ff499 100644 --- a/models/tcp_request_rules.go +++ b/models/tcp_request_rules.go @@ -71,6 +71,11 @@ func (m TCPRequestRules) ContextValidate(ctx context.Context, formats strfmt.Reg for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/tcp_response_rule.go b/models/tcp_response_rule.go index f5853fd7..46d39a3d 100644 --- a/models/tcp_response_rule.go +++ b/models/tcp_response_rule.go @@ -38,7 +38,7 @@ import ( // swagger:model tcp_response_rule type TCPResponseRule struct { // action - // Enum: [accept close lua reject sc-add-gpc sc-inc-gpc sc-inc-gpc0 sc-inc-gpc1 sc-set-gpt sc-set-gpt0 send-spoe-group set-bandwidth-limit set-fc-mark set-fc-tos set-log-level set-mark set-nice set-tos set-var set-var-fmt silent-drop unset-var] + // Enum: ["accept","close","lua","reject","sc-add-gpc","sc-inc-gpc","sc-inc-gpc0","sc-inc-gpc1","sc-set-gpt","sc-set-gpt0","send-spoe-group","set-bandwidth-limit","set-fc-mark","set-fc-tos","set-log-level","set-mark","set-nice","set-tos","set-var","set-var-fmt","silent-drop","unset-var"] // +kubebuilder:validation:Enum=accept;close;lua;reject;sc-add-gpc;sc-inc-gpc;sc-inc-gpc0;sc-inc-gpc1;sc-set-gpt;sc-set-gpt0;send-spoe-group;set-bandwidth-limit;set-fc-mark;set-fc-tos;set-log-level;set-mark;set-nice;set-tos;set-var;set-var-fmt;silent-drop;unset-var; Action string `json:"action,omitempty"` @@ -52,7 +52,7 @@ type TCPResponseRule struct { BandwidthLimitPeriod string `json:"bandwidth_limit_period,omitempty"` // cond - // Enum: [if unless] + // Enum: ["if","unless"] // +kubebuilder:validation:Enum=if;unless; Cond string `json:"cond,omitempty"` @@ -63,7 +63,7 @@ type TCPResponseRule struct { Expr string `json:"expr,omitempty"` // log level - // Enum: [emerg alert crit err warning notice info debug silent] + // Enum: ["emerg","alert","crit","err","warning","notice","info","debug","silent"] // +kubebuilder:validation:Enum=emerg;alert;crit;err;warning;notice;info;debug;silent; LogLevel string `json:"log_level,omitempty"` @@ -87,6 +87,9 @@ type TCPResponseRule struct { // +kubebuilder:validation:Minimum=-1024 NiceValue int64 `json:"nice_value,omitempty"` + // rst ttl + RstTTL int64 `json:"rst_ttl,omitempty"` + // sc expr ScExpr string `json:"sc_expr,omitempty"` @@ -119,7 +122,7 @@ type TCPResponseRule struct { // type // Required: true - // Enum: [content inspect-delay] + // Enum: ["content","inspect-delay"] // +kubebuilder:validation:Enum=content;inspect-delay; Type string `json:"type"` diff --git a/models/tcp_response_rule_compare.go b/models/tcp_response_rule_compare.go index 267ccfef..906050d0 100644 --- a/models/tcp_response_rule_compare.go +++ b/models/tcp_response_rule_compare.go @@ -72,6 +72,10 @@ func (s TCPResponseRule) Equal(t TCPResponseRule, opts ...Options) bool { return false } + if s.RstTTL != t.RstTTL { + return false + } + if s.ScExpr != t.ScExpr { return false } @@ -179,6 +183,10 @@ func (s TCPResponseRule) Diff(t TCPResponseRule, opts ...Options) map[string][]i diff["NiceValue"] = []interface{}{s.NiceValue, t.NiceValue} } + if s.RstTTL != t.RstTTL { + diff["RstTTL"] = []interface{}{s.RstTTL, t.RstTTL} + } + if s.ScExpr != t.ScExpr { diff["ScExpr"] = []interface{}{s.ScExpr, t.ScExpr} } diff --git a/models/tcp_response_rule_compare_test.go b/models/tcp_response_rule_compare_test.go index b89bbba7..7a745566 100644 --- a/models/tcp_response_rule_compare_test.go +++ b/models/tcp_response_rule_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestTCPResponseRuleEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample TCPResponseRule var result TCPResponseRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestTCPResponseRuleEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TCPResponseRule to be equal, but it is not %s %s", a, b) } @@ -75,15 +78,16 @@ func TestTCPResponseRuleEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TCPResponseRule var result TCPResponseRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.NiceValue = sample.NiceValue + 1 + result.RstTTL = sample.RstTTL + 1 result.ScID = sample.ScID + 1 result.ScIdx = sample.ScIdx + 1 result.ScInt = Ptr(*sample.ScInt + 1) @@ -99,11 +103,11 @@ func TestTCPResponseRuleEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TCPResponseRule to be different, but it is not %s %s", a, b) } @@ -117,17 +121,17 @@ func TestTCPResponseRuleDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample TCPResponseRule var result TCPResponseRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -141,11 +145,11 @@ func TestTCPResponseRuleDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TCPResponseRule to be equal, but it is not %s %s, %v", a, b, result) } @@ -159,15 +163,16 @@ func TestTCPResponseRuleDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TCPResponseRule var result TCPResponseRule - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.NiceValue = sample.NiceValue + 1 + result.RstTTL = sample.RstTTL + 1 result.ScID = sample.ScID + 1 result.ScIdx = sample.ScIdx + 1 result.ScInt = Ptr(*sample.ScInt + 1) @@ -179,17 +184,17 @@ func TestTCPResponseRuleDiffFalse(t *testing.T) { for _, sample := range samples { result := sample.a.Diff(sample.b) - if len(result) != 24 { + if len(result) != 25 { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - t.Errorf("Expected TCPResponseRule to be different in 24 cases, but it is not (%d) %s %s", len(result), a, b) + t.Errorf("Expected TCPResponseRule to be different in 25 cases, but it is not (%d) %s %s", len(result), a, b) } } } diff --git a/models/tcp_response_rules.go b/models/tcp_response_rules.go index ba78b301..26f8fe85 100644 --- a/models/tcp_response_rules.go +++ b/models/tcp_response_rules.go @@ -71,6 +71,11 @@ func (m TCPResponseRules) ContextValidate(ctx context.Context, formats strfmt.Re for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/transaction.go b/models/transaction.go index 5fee5841..327e3445 100644 --- a/models/transaction.go +++ b/models/transaction.go @@ -47,7 +47,7 @@ type Transaction struct { ID string `json:"id,omitempty"` // status - // Enum: [failed outdated in_progress success] + // Enum: ["failed","outdated","in_progress","success"] // +kubebuilder:validation:Enum=failed;outdated;in_progress;success; Status string `json:"status,omitempty"` } diff --git a/models/transaction_compare_test.go b/models/transaction_compare_test.go index 4dd63cd1..55b07198 100644 --- a/models/transaction_compare_test.go +++ b/models/transaction_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestTransactionEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Transaction var result Transaction - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestTransactionEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Transaction to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestTransactionEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Transaction var result Transaction - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Version = sample.Version + 1 samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestTransactionEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Transaction to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestTransactionDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Transaction var result Transaction - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestTransactionDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Transaction to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestTransactionDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Transaction var result Transaction - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Version = sample.Version + 1 samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestTransactionDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Transaction to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/transactions.go b/models/transactions.go index b45c314f..2bc270c0 100644 --- a/models/transactions.go +++ b/models/transactions.go @@ -71,6 +71,11 @@ func (m Transactions) ContextValidate(ctx context.Context, formats strfmt.Regist for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/tune_buffer_options_compare_test.go b/models/tune_buffer_options_compare_test.go index f78188d6..8e92219d 100644 --- a/models/tune_buffer_options_compare_test.go +++ b/models/tune_buffer_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestTuneBufferOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneBufferOptions var result TuneBufferOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestTuneBufferOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneBufferOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestTuneBufferOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneBufferOptions var result TuneBufferOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.BuffersLimit = Ptr(*sample.BuffersLimit + 1) result.BuffersReserve = sample.BuffersReserve + 1 @@ -107,11 +110,11 @@ func TestTuneBufferOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneBufferOptions to be different, but it is not %s %s", a, b) } @@ -125,17 +128,17 @@ func TestTuneBufferOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneBufferOptions var result TuneBufferOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -149,11 +152,11 @@ func TestTuneBufferOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneBufferOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -167,13 +170,13 @@ func TestTuneBufferOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneBufferOptions var result TuneBufferOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.BuffersLimit = Ptr(*sample.BuffersLimit + 1) result.BuffersReserve = sample.BuffersReserve + 1 @@ -199,11 +202,11 @@ func TestTuneBufferOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneBufferOptions to be different in 13 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/tune_lua_options.go b/models/tune_lua_options.go index bdb34801..735ddb62 100644 --- a/models/tune_lua_options.go +++ b/models/tune_lua_options.go @@ -43,12 +43,12 @@ type TuneLuaOptions struct { ForcedYield int64 `json:"forced_yield,omitempty"` // log loggers - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; LogLoggers string `json:"log_loggers,omitempty"` // log stderr - // Enum: [auto enabled disabled] + // Enum: ["auto","enabled","disabled"] // +kubebuilder:validation:Enum=auto;enabled;disabled; LogStderr string `json:"log_stderr,omitempty"` diff --git a/models/tune_lua_options_compare_test.go b/models/tune_lua_options_compare_test.go index 7c512d8a..fbe0b691 100644 --- a/models/tune_lua_options_compare_test.go +++ b/models/tune_lua_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestTuneLuaOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneLuaOptions var result TuneLuaOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestTuneLuaOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneLuaOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestTuneLuaOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneLuaOptions var result TuneLuaOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.BurstTimeout = Ptr(*sample.BurstTimeout + 1) result.ForcedYield = sample.ForcedYield + 1 @@ -100,11 +103,11 @@ func TestTuneLuaOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneLuaOptions to be different, but it is not %s %s", a, b) } @@ -118,17 +121,17 @@ func TestTuneLuaOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneLuaOptions var result TuneLuaOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -142,11 +145,11 @@ func TestTuneLuaOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneLuaOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -160,13 +163,13 @@ func TestTuneLuaOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneLuaOptions var result TuneLuaOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.BurstTimeout = Ptr(*sample.BurstTimeout + 1) result.ForcedYield = sample.ForcedYield + 1 @@ -185,11 +188,11 @@ func TestTuneLuaOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneLuaOptions to be different in 8 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/tune_options.go b/models/tune_options.go index dedc9b05..e4821fc9 100644 --- a/models/tune_options.go +++ b/models/tune_options.go @@ -35,7 +35,7 @@ import ( // swagger:model tune_options type TuneOptions struct { // applet zero copy forwarding - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; AppletZeroCopyForwarding string `json:"applet_zero_copy_forwarding,omitempty"` @@ -56,17 +56,17 @@ type TuneOptions struct { FailAlloc bool `json:"fail_alloc,omitempty"` // fd edge triggered - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; FdEdgeTriggered string `json:"fd_edge_triggered,omitempty"` // h1 zero copy fwd recv - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; H1ZeroCopyFwdRecv string `json:"h1_zero_copy_fwd_recv,omitempty"` // h1 zero copy fwd send - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; H1ZeroCopyFwdSend string `json:"h1_zero_copy_fwd_send,omitempty"` @@ -106,7 +106,7 @@ type TuneOptions struct { H2MaxFrameSize int64 `json:"h2_max_frame_size,omitempty"` // h2 zero copy fwd send - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; H2ZeroCopyFwdSend string `json:"h2_zero_copy_fwd_send,omitempty"` @@ -124,7 +124,7 @@ type TuneOptions struct { HTTPMaxhdr int64 `json:"http_maxhdr,omitempty"` // idle pool shared - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; IdlePoolShared string `json:"idle_pool_shared,omitempty"` @@ -136,12 +136,12 @@ type TuneOptions struct { Idletimer *int64 `json:"idletimer,omitempty"` // listener default shards - // Enum: [by-process by-thread by-group] + // Enum: ["by-process","by-thread","by-group"] // +kubebuilder:validation:Enum=by-process;by-thread;by-group; ListenerDefaultShards string `json:"listener_default_shards,omitempty"` // listener multi queue - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ListenerMultiQueue string `json:"listener_multi_queue,omitempty"` @@ -173,7 +173,7 @@ type TuneOptions struct { PoolLowFdRatio int64 `json:"pool_low_fd_ratio,omitempty"` // pt zero copy forwarding - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; PtZeroCopyForwarding string `json:"pt_zero_copy_forwarding,omitempty"` @@ -184,7 +184,7 @@ type TuneOptions struct { RunqueueDepth int64 `json:"runqueue_depth,omitempty"` // sched low latency - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; SchedLowLatency string `json:"sched_low_latency,omitempty"` diff --git a/models/tune_options_compare_test.go b/models/tune_options_compare_test.go index 5fefdc0b..7b9cdacc 100644 --- a/models/tune_options_compare_test.go +++ b/models/tune_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestTuneOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneOptions var result TuneOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestTuneOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestTuneOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneOptions var result TuneOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CompMaxlevel = sample.CompMaxlevel + 1 result.DisableZeroCopyForwarding = !sample.DisableZeroCopyForwarding @@ -125,11 +128,11 @@ func TestTuneOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneOptions to be different, but it is not %s %s", a, b) } @@ -143,17 +146,17 @@ func TestTuneOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneOptions var result TuneOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -167,11 +170,11 @@ func TestTuneOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -185,13 +188,13 @@ func TestTuneOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneOptions var result TuneOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CompMaxlevel = sample.CompMaxlevel + 1 result.DisableZeroCopyForwarding = !sample.DisableZeroCopyForwarding @@ -235,11 +238,11 @@ func TestTuneOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneOptions to be different in 41 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/tune_quic_options.go b/models/tune_quic_options.go index 7b743c70..dc0f0fa5 100644 --- a/models/tune_quic_options.go +++ b/models/tune_quic_options.go @@ -60,12 +60,12 @@ type TuneQuicOptions struct { RetryThreshold *int64 `json:"retry_threshold,omitempty"` // socket owner - // Enum: [listener connection] + // Enum: ["listener","connection"] // +kubebuilder:validation:Enum=listener;connection; SocketOwner string `json:"socket_owner,omitempty"` // zero copy fwd send - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; ZeroCopyFwdSend string `json:"zero_copy_fwd_send,omitempty"` } diff --git a/models/tune_quic_options_compare_test.go b/models/tune_quic_options_compare_test.go index 4b8e4beb..470560ed 100644 --- a/models/tune_quic_options_compare_test.go +++ b/models/tune_quic_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestTuneQuicOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneQuicOptions var result TuneQuicOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestTuneQuicOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneQuicOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestTuneQuicOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneQuicOptions var result TuneQuicOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.FrontendConnTxBuffersLimit = Ptr(*sample.FrontendConnTxBuffersLimit + 1) result.FrontendMaxIdleTimeout = Ptr(*sample.FrontendMaxIdleTimeout + 1) @@ -100,11 +103,11 @@ func TestTuneQuicOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneQuicOptions to be different, but it is not %s %s", a, b) } @@ -118,17 +121,17 @@ func TestTuneQuicOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneQuicOptions var result TuneQuicOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -142,11 +145,11 @@ func TestTuneQuicOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneQuicOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -160,13 +163,13 @@ func TestTuneQuicOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneQuicOptions var result TuneQuicOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.FrontendConnTxBuffersLimit = Ptr(*sample.FrontendConnTxBuffersLimit + 1) result.FrontendMaxIdleTimeout = Ptr(*sample.FrontendMaxIdleTimeout + 1) @@ -185,11 +188,11 @@ func TestTuneQuicOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneQuicOptions to be different in 8 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/tune_ssl_options.go b/models/tune_ssl_options.go index 1701c3e5..fe6cbda4 100644 --- a/models/tune_ssl_options.go +++ b/models/tune_ssl_options.go @@ -51,7 +51,7 @@ type TuneSslOptions struct { ForcePrivateCache bool `json:"force_private_cache,omitempty"` // keylog - // Enum: [enabled disabled] + // Enum: ["enabled","disabled"] // +kubebuilder:validation:Enum=enabled;disabled; Keylog string `json:"keylog,omitempty"` diff --git a/models/tune_ssl_options_compare_test.go b/models/tune_ssl_options_compare_test.go index 258f6679..a9742593 100644 --- a/models/tune_ssl_options_compare_test.go +++ b/models/tune_ssl_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestTuneSslOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneSslOptions var result TuneSslOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestTuneSslOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneSslOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestTuneSslOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneSslOptions var result TuneSslOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Cachesize = Ptr(*sample.Cachesize + 1) result.CaptureBufferSize = Ptr(*sample.CaptureBufferSize + 1) @@ -103,11 +106,11 @@ func TestTuneSslOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneSslOptions to be different, but it is not %s %s", a, b) } @@ -121,17 +124,17 @@ func TestTuneSslOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneSslOptions var result TuneSslOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -145,11 +148,11 @@ func TestTuneSslOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneSslOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -163,13 +166,13 @@ func TestTuneSslOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneSslOptions var result TuneSslOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Cachesize = Ptr(*sample.Cachesize + 1) result.CaptureBufferSize = Ptr(*sample.CaptureBufferSize + 1) @@ -191,11 +194,11 @@ func TestTuneSslOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneSslOptions to be different in 10 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/tune_vars_options_compare_test.go b/models/tune_vars_options_compare_test.go index 8b8978e6..626679c0 100644 --- a/models/tune_vars_options_compare_test.go +++ b/models/tune_vars_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestTuneVarsOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneVarsOptions var result TuneVarsOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestTuneVarsOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneVarsOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestTuneVarsOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneVarsOptions var result TuneVarsOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.GlobalMaxSize = Ptr(*sample.GlobalMaxSize + 1) result.ProcMaxSize = Ptr(*sample.ProcMaxSize + 1) @@ -99,11 +102,11 @@ func TestTuneVarsOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneVarsOptions to be different, but it is not %s %s", a, b) } @@ -117,17 +120,17 @@ func TestTuneVarsOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneVarsOptions var result TuneVarsOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -141,11 +144,11 @@ func TestTuneVarsOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneVarsOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -159,13 +162,13 @@ func TestTuneVarsOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneVarsOptions var result TuneVarsOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.GlobalMaxSize = Ptr(*sample.GlobalMaxSize + 1) result.ProcMaxSize = Ptr(*sample.ProcMaxSize + 1) @@ -183,11 +186,11 @@ func TestTuneVarsOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneVarsOptions to be different in 5 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/tune_zlib_options_compare_test.go b/models/tune_zlib_options_compare_test.go index abb21699..19c02ae1 100644 --- a/models/tune_zlib_options_compare_test.go +++ b/models/tune_zlib_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestTuneZlibOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneZlibOptions var result TuneZlibOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestTuneZlibOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneZlibOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestTuneZlibOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneZlibOptions var result TuneZlibOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Memlevel = sample.Memlevel + 1 result.Windowsize = sample.Windowsize + 1 @@ -96,11 +99,11 @@ func TestTuneZlibOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneZlibOptions to be different, but it is not %s %s", a, b) } @@ -114,17 +117,17 @@ func TestTuneZlibOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneZlibOptions var result TuneZlibOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -138,11 +141,11 @@ func TestTuneZlibOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneZlibOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -156,13 +159,13 @@ func TestTuneZlibOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample TuneZlibOptions var result TuneZlibOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.Memlevel = sample.Memlevel + 1 result.Windowsize = sample.Windowsize + 1 @@ -177,11 +180,11 @@ func TestTuneZlibOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected TuneZlibOptions to be different in 2 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/user_compare_test.go b/models/user_compare_test.go index 563e3532..5668890b 100644 --- a/models/user_compare_test.go +++ b/models/user_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestUserEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample User var result User - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestUserEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected User to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestUserEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample User var result User - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.SecurePassword = Ptr(!*sample.SecurePassword) samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestUserEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected User to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestUserDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample User var result User - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestUserDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected User to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestUserDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample User var result User - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.SecurePassword = Ptr(!*sample.SecurePassword) samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestUserDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected User to be different in 4 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/userlist_base_compare_test.go b/models/userlist_base_compare_test.go index 8ad74ef2..25c653e4 100644 --- a/models/userlist_base_compare_test.go +++ b/models/userlist_base_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestUserlistBaseEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample UserlistBase var result UserlistBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestUserlistBaseEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected UserlistBase to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestUserlistBaseEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample UserlistBase var result UserlistBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b UserlistBase @@ -94,11 +97,11 @@ func TestUserlistBaseEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected UserlistBase to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestUserlistBaseDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample UserlistBase var result UserlistBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestUserlistBaseDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected UserlistBase to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestUserlistBaseDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample UserlistBase var result UserlistBase - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b UserlistBase @@ -173,11 +176,11 @@ func TestUserlistBaseDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected UserlistBase to be different in 1 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/userlist_compare_test.go b/models/userlist_compare_test.go index 99f54feb..ddbcf4a9 100644 --- a/models/userlist_compare_test.go +++ b/models/userlist_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestUserlistEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample Userlist var result Userlist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestUserlistEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Userlist to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestUserlistEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Userlist var result Userlist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Userlist @@ -94,11 +97,11 @@ func TestUserlistEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Userlist to be different, but it is not %s %s", a, b) } @@ -112,17 +115,17 @@ func TestUserlistDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample Userlist var result Userlist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -136,11 +139,11 @@ func TestUserlistDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Userlist to be equal, but it is not %s %s, %v", a, b, result) } @@ -154,13 +157,13 @@ func TestUserlistDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample Userlist var result Userlist - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { a, b Userlist @@ -173,11 +176,11 @@ func TestUserlistDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected Userlist to be different in 3 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/models/userlists.go b/models/userlists.go index 1acc7d7f..831ca45a 100644 --- a/models/userlists.go +++ b/models/userlists.go @@ -71,6 +71,11 @@ func (m Userlists) ContextValidate(ctx context.Context, formats strfmt.Registry) for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/users.go b/models/users.go index 18a69e85..cc1ecb3d 100644 --- a/models/users.go +++ b/models/users.go @@ -71,6 +71,11 @@ func (m Users) ContextValidate(ctx context.Context, formats strfmt.Registry) err for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/models/wurfl_options_compare_test.go b/models/wurfl_options_compare_test.go index 75c48bbe..5e5945f8 100644 --- a/models/wurfl_options_compare_test.go +++ b/models/wurfl_options_compare_test.go @@ -15,6 +15,8 @@ // limitations under the License. // +//go:build equal + package models import ( @@ -22,6 +24,7 @@ import ( "testing" "github.com/go-faker/faker/v4" + "github.com/go-faker/faker/v4/pkg/options" jsoniter "github.com/json-iterator/go" ) @@ -33,17 +36,17 @@ func TestWurflOptionsEqual(t *testing.T) { for i := 0; i < 2; i++ { var sample WurflOptions var result WurflOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -57,11 +60,11 @@ func TestWurflOptionsEqual(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected WurflOptions to be equal, but it is not %s %s", a, b) } @@ -75,13 +78,13 @@ func TestWurflOptionsEqualFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample WurflOptions var result WurflOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CacheSize = sample.CacheSize + 1 samples = append(samples, struct { @@ -95,11 +98,11 @@ func TestWurflOptionsEqualFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected WurflOptions to be different, but it is not %s %s", a, b) } @@ -113,17 +116,17 @@ func TestWurflOptionsDiff(t *testing.T) { for i := 0; i < 2; i++ { var sample WurflOptions var result WurflOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } byteJSON, err := json.Marshal(sample) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } err = json.Unmarshal(byteJSON, &result) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } samples = append(samples, struct { @@ -137,11 +140,11 @@ func TestWurflOptionsDiff(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected WurflOptions to be equal, but it is not %s %s, %v", a, b, result) } @@ -155,13 +158,13 @@ func TestWurflOptionsDiffFalse(t *testing.T) { for i := 0; i < 2; i++ { var sample WurflOptions var result WurflOptions - err := faker.FakeData(&sample) + err := faker.FakeData(&sample, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } - err = faker.FakeData(&result) + err = faker.FakeData(&result, options.WithIgnoreInterface(true)) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } result.CacheSize = sample.CacheSize + 1 samples = append(samples, struct { @@ -175,11 +178,11 @@ func TestWurflOptionsDiffFalse(t *testing.T) { json := jsoniter.ConfigCompatibleWithStandardLibrary a, err := json.Marshal(&sample.a) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } b, err := json.Marshal(&sample.b) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } t.Errorf("Expected WurflOptions to be different in 5 cases, but it is not (%d) %s %s", len(result), a, b) } diff --git a/runtime/acls.go b/runtime/acls.go index d2398e2b..2a526277 100644 --- a/runtime/acls.go +++ b/runtime/acls.go @@ -31,8 +31,8 @@ func (s *SingleRuntime) parseACLS(output string) models.ACLFiles { } acls := models.ACLFiles{} - lines := strings.Split(strings.TrimSpace(output), "\n") - for _, line := range lines { + lines := strings.SplitSeq(strings.TrimSpace(output), "\n") + for line := range lines { m := s.parseACL(line) if m != nil { acls = append(acls, m) @@ -97,7 +97,7 @@ func (s *SingleRuntime) ShowACLFileEntries(storageName string) (models.ACLFilesE if storageName == "" { return nil, fmt.Errorf("%s %w", "Argument file empty", native_errors.ErrGeneral) } - cmd := fmt.Sprintf("show acl %s", storageName) + cmd := "show acl " + storageName response, err := s.ExecuteWithResponse(cmd) if err != nil { return nil, fmt.Errorf("%s %w", err.Error(), native_errors.ErrNotFound) @@ -115,8 +115,8 @@ func ParseACLFileEntries(output string, hasID bool) (models.ACLFilesEntries, err } me := models.ACLFilesEntries{} - lines := strings.Split(strings.TrimSpace(output), "\n") - for _, line := range lines { + lines := strings.SplitSeq(strings.TrimSpace(output), "\n") + for line := range lines { e := parseACLFileEntry(line, hasID) if e != nil { me = append(me, e) @@ -166,8 +166,8 @@ func (s *SingleRuntime) AddACLFileEntry(aclID, value string) error { return nil } -func (s *SingleRuntime) PrepareACL(aclID string) (version string, err error) { - cmd := fmt.Sprintf("prepare acl %s", aclID) +func (s *SingleRuntime) PrepareACL(aclID string) (string, error) { + cmd := "prepare acl " + aclID response, err := s.ExecuteWithResponse(cmd) if err != nil { return "", fmt.Errorf("%s %w", err.Error(), native_errors.ErrGeneral) @@ -176,7 +176,7 @@ func (s *SingleRuntime) PrepareACL(aclID string) (version string, err error) { if len(parts) < 3 { return "", fmt.Errorf("not enough parts in response: %s %w", response, native_errors.ErrGeneral) } - version = strings.TrimSpace(parts[2]) + version := strings.TrimSpace(parts[2]) if _, err = strconv.ParseInt(version, 10, 64); err == nil { return version, nil } @@ -209,13 +209,13 @@ func (s *SingleRuntime) GetACLFileEntry(aclID, value string) (*models.ACLFileEnt matched := false m := &models.ACLFileEntry{} - parts := strings.Split(response, ",") - for _, p := range parts { + parts := strings.SplitSeq(response, ",") + for p := range parts { kv := strings.Split(p, "=") - switch key := strings.TrimSpace(kv[0]); { - case key == "pattern": + switch key := strings.TrimSpace(kv[0]); key { + case "pattern": m.Value = strings.Trim(strings.TrimSpace(kv[1]), "\"") - case key == "match": + case "match": matched = true } } diff --git a/runtime/acls_test.go b/runtime/acls_test.go index bedd8635..4b9ac03c 100644 --- a/runtime/acls_test.go +++ b/runtime/acls_test.go @@ -1,10 +1,8 @@ package runtime import ( - "context" "reflect" "testing" - "time" "github.com/haproxytech/client-native/v6/models" ) @@ -52,9 +50,7 @@ func TestSingleRuntime_ShowACLS(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -159,9 +155,7 @@ func TestSingleRuntime_GetACL(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -253,9 +247,7 @@ func TestSingleRuntime_ShowACLFileEntries(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -329,9 +321,7 @@ func TestSingleRuntime_GetACLFileEntry(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -436,9 +426,7 @@ func TestSingleRuntime_AddACLFileEntry(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -521,9 +509,7 @@ func TestSingleRuntime_DeleteACLFileEntry(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return diff --git a/runtime/certs.go b/runtime/certs.go index 63b2bb51..3da3052a 100644 --- a/runtime/certs.go +++ b/runtime/certs.go @@ -1,6 +1,7 @@ package runtime import ( + "errors" "fmt" "strings" "time" @@ -33,8 +34,8 @@ func (s *SingleRuntime) parseCerts(output string) models.SslCertificates { } certs := models.SslCertificates{} - lines := strings.Split(output, "\n") - for _, line := range lines { + lines := strings.SplitSeq(output, "\n") + for line := range lines { c := s.parseCert(line) if c != nil { certs = append(certs, c) @@ -79,7 +80,7 @@ func (s *SingleRuntime) ShowCertEntry(storageName string) (*models.SslCertEntry, if storageName == "" { return nil, fmt.Errorf("%s %w", "Argument storageName empty", native_errors.ErrGeneral) } - cmd := fmt.Sprintf("show ssl cert %s", storageName) + cmd := "show ssl cert " + storageName response, err := s.ExecuteWithResponse(cmd) if err != nil { return nil, fmt.Errorf("%s %w", err.Error(), native_errors.ErrNotFound) @@ -87,9 +88,9 @@ func (s *SingleRuntime) ShowCertEntry(storageName string) (*models.SslCertEntry, return parseCertEntry(response) } -// parseCertEntry parses one entry in one CrtList file/runtime and returns it structured +// parseCertEntry parses one entry in one CrtList file and returns it structured // example: -// Filename: /etc/ssl/cert-2.pem +// Filename: /etc/ssl/cert-2.pem <= this is just the same name you gave as certificate name, could be an alias // Status: Used // Serial: 0D933C1B1089BF660AE5253A245BB388 // notBefore: Sep 9 00:00:00 2020 GMT @@ -101,51 +102,75 @@ func (s *SingleRuntime) ShowCertEntry(storageName string) (*models.SslCertEntry, // Issuer: /C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA // Chain Subject: /C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA // Chain Issuer: /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Global Root CA +// *** undocumented, only in recent versions, "Key filename" is optional *** +// Crt filename: /etc/ssl/cert-2.pem +// Key filename: /etc/ssl/cert-2.key func parseCertEntry(response string) (*models.SslCertEntry, error) { if response == "" || strings.HasPrefix(strings.TrimSpace(response), "#") { return nil, native_errors.ErrNotFound } c := &models.SslCertEntry{} - parts := strings.Split(response, "\n") - for _, p := range parts { - index := strings.Index(p, ":") - if index == -1 { + var crtFilename string + var keyFilename string + + parts := strings.SplitSeq(response, "\n") + for p := range parts { + before, after, found := strings.Cut(p, ":") + if !found { continue } - keyString := strings.TrimSpace(p[0:index]) - valueString := strings.TrimSpace(p[index+1:]) + keyString := strings.TrimSpace(strings.TrimSpace(before)) + valueString := strings.TrimSpace(strings.TrimSpace(after)) - switch key := keyString; { - case key == "Filename": + switch keyString { + case "Filename": c.StorageName = valueString - case key == "Status": + case "Status": c.Status = valueString - case key == "Serial": + case "Serial": c.Serial = valueString - case key == "notBefore": + case "notBefore": notBefore, _ := time.Parse("Jan 2 15:04:05 2006 MST", valueString) c.NotBefore = strfmt.Date(notBefore) - case key == "notAfter": + case "notAfter": notAfter, _ := time.Parse("Jan 2 15:04:05 2006 MST", valueString) c.NotAfter = strfmt.Date(notAfter) - case key == "Subject Alternative Name": + case "Subject Alternative Name": c.SubjectAlternativeNames = strings.Split(valueString, ", ") - case key == "Algorithm": + case "Algorithm": c.Algorithm = valueString - case key == "SHA1 FingerPrint": + case "SHA1 FingerPrint": c.Sha1FingerPrint = valueString - case key == "Subject": + case "Subject": c.Subject = valueString - case key == "Issuer": + case "Issuer": c.Issuer = valueString - case key == "Chain Subject": + case "Chain Subject": c.ChainSubject = valueString - case key == "Chain Issuer": + case "Chain Issuer": c.ChainIssuer = valueString + case "Crt filename": + crtFilename = valueString + case "Key filename": + keyFilename = valueString } } + if crtFilename != "" { + c.StorageName = crtFilename + } + + // We currently do not support storing the key in a separate file. + if keyFilename != "" && keyFilename != crtFilename { + return nil, fmt.Errorf("failed to parse certificate info for %s: storing the private key in a separate file is not supported", c.StorageName) + } + + // This should be impossible. + if c.StorageName == "" { + return nil, errors.New("failed to parse certificate info: empty filename") + } + return c, nil } @@ -154,7 +179,7 @@ func (s *SingleRuntime) NewCertEntry(storageName string) error { if storageName == "" { return fmt.Errorf("%s %w", "Argument storageName empty", native_errors.ErrGeneral) } - cmd := fmt.Sprintf("new ssl cert %s", storageName) + cmd := "new ssl cert " + storageName response, err := s.ExecuteWithResponse(cmd) if err != nil { return fmt.Errorf("%s %w", err.Error(), native_errors.ErrGeneral) @@ -186,12 +211,12 @@ func (s *SingleRuntime) CommitCertEntry(storageName string) error { if storageName == "" { return fmt.Errorf("%s %w", "Argument storageName empty", native_errors.ErrGeneral) } - cmd := fmt.Sprintf("commit ssl cert %s", storageName) + cmd := "commit ssl cert " + storageName response, err := s.ExecuteWithResponse(cmd) if err != nil { return fmt.Errorf("%s %w", err.Error(), native_errors.ErrGeneral) } - if !(strings.Contains(response, "Committing") && strings.Contains(response, "Success!")) { + if !strings.Contains(response, "Committing") || !strings.Contains(response, "Success!") { return fmt.Errorf("%s %w", response, native_errors.ErrGeneral) } return nil @@ -202,7 +227,7 @@ func (s *SingleRuntime) AbortCertEntry(storageName string) error { if storageName == "" { return fmt.Errorf("%s %w", "Argument storageName empty", native_errors.ErrGeneral) } - cmd := fmt.Sprintf("abort ssl cert %s", storageName) + cmd := "abort ssl cert " + storageName response, err := s.ExecuteWithResponse(cmd) if err != nil { return fmt.Errorf("%s %w", err.Error(), native_errors.ErrGeneral) @@ -218,12 +243,12 @@ func (s *SingleRuntime) DeleteCertEntry(storageName string) error { if storageName == "" { return fmt.Errorf("%s %w", "Argument storageName empty", native_errors.ErrGeneral) } - cmd := fmt.Sprintf("del ssl cert %s", storageName) + cmd := "del ssl cert " + storageName response, err := s.ExecuteWithResponse(cmd) if err != nil { return fmt.Errorf("%s %w", err.Error(), native_errors.ErrGeneral) } - if !(strings.Contains(response, "Certificate") && strings.Contains(response, "deleted!")) { + if !strings.Contains(response, "Certificate") || !strings.Contains(response, "deleted!") { return fmt.Errorf("%s %w", response, native_errors.ErrGeneral) } return nil diff --git a/runtime/certs_test.go b/runtime/certs_test.go index c6eb1c59..d93bd990 100644 --- a/runtime/certs_test.go +++ b/runtime/certs_test.go @@ -1,7 +1,6 @@ package runtime import ( - "context" "reflect" "testing" "time" @@ -56,9 +55,7 @@ func TestSingleRuntime_ShowCerts(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -146,9 +143,7 @@ func TestSingleRuntime_GetCert(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -191,7 +186,7 @@ func TestSingleRuntime_ShowCertEntry(t *testing.T) { name: "Simple show certs, should return a cert", fields: fields{socketPath: haProxy.Addr().String()}, args: args{ - storageName: "/etc/ssl/cert-0.pem", + storageName: "cert-0", }, want: &models.SslCertEntry{ StorageName: "/etc/ssl/cert-0.pem", @@ -211,7 +206,72 @@ func TestSingleRuntime_ShowCertEntry(t *testing.T) { ChainIssuer: "/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Global Root CA", }, socketResponse: map[string]string{ - "show ssl cert /etc/ssl/cert-0.pem\n": ` Filename: /etc/ssl/cert-0.pem + "show ssl cert cert-0\n": ` Filename: cert-0 + Status: Used + Serial: 0D933C1B1089BF660AE5253A245BB388 + notBefore: Sep 9 00:00:00 2020 GMT + notAfter: Sep 14 12:00:00 2021 GMT + Subject Alternative Name: DNS:*.platform.domain.com, DNS:uaa.platform.domain.com + Algorithm: RSA4096 + SHA1 FingerPrint: 59242F1838BDEF3E7DAFC83FFE4DD6C03B88805C + Subject: /C=DE/ST=Baden-Württemberg/L=Walldorf/O=ORG SE/CN=*.platform.domain.com + Issuer: /C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA + Chain Subject: /C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA + Chain Issuer: /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Global Root CA + Crt filename: /etc/ssl/cert-0.pem + Key filename: /etc/ssl/cert-0.pem + `, + }, + }, + { + name: "A certificate without a 'Crt filename'", + fields: fields{socketPath: haProxy.Addr().String()}, + args: args{ + storageName: "cert-1", + }, + want: &models.SslCertEntry{ + StorageName: "cert-1", + Status: "Used", + Serial: "0D933C1B1089BF660AE5253A245BB388", + NotBefore: strfmt.Date(notBefore), + NotAfter: strfmt.Date(notAfter), + SubjectAlternativeNames: []string{ + "DNS:*.platform.domain.com", + "DNS:uaa.platform.domain.com", + }, + Algorithm: "RSA4096", + Sha1FingerPrint: "59242F1838BDEF3E7DAFC83FFE4DD6C03B88805C", + Subject: "/C=DE/ST=Baden-Württemberg/L=Walldorf/O=ORG SE/CN=*.platform.domain.com", + Issuer: "/C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA", + ChainSubject: "/C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA", + ChainIssuer: "/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Global Root CA", + }, + socketResponse: map[string]string{ + "show ssl cert cert-1\n": ` Filename: cert-1 + Status: Used + Serial: 0D933C1B1089BF660AE5253A245BB388 + notBefore: Sep 9 00:00:00 2020 GMT + notAfter: Sep 14 12:00:00 2021 GMT + Subject Alternative Name: DNS:*.platform.domain.com, DNS:uaa.platform.domain.com + Algorithm: RSA4096 + SHA1 FingerPrint: 59242F1838BDEF3E7DAFC83FFE4DD6C03B88805C + Subject: /C=DE/ST=Baden-Württemberg/L=Walldorf/O=ORG SE/CN=*.platform.domain.com + Issuer: /C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA + Chain Subject: /C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA + Chain Issuer: /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Global Root CA + `, + }, + }, + { + name: "A certificate with a separate key file", + fields: fields{socketPath: haProxy.Addr().String()}, + args: args{ + storageName: "cert-2", + }, + want: nil, + wantErr: true, + socketResponse: map[string]string{ + "show ssl cert cert-2\n": ` Filename: cert-2 Status: Used Serial: 0D933C1B1089BF660AE5253A245BB388 notBefore: Sep 9 00:00:00 2020 GMT @@ -223,6 +283,8 @@ func TestSingleRuntime_ShowCertEntry(t *testing.T) { Issuer: /C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA Chain Subject: /C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA Chain Issuer: /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Global Root CA + Crt filename: /etc/ssl/cert-2.crt + Key filename: /etc/ssl/cert-2.key `, }, }, @@ -231,9 +293,7 @@ func TestSingleRuntime_ShowCertEntry(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -256,7 +316,6 @@ func TestSingleRuntime_NewCertEntry(t *testing.T) { defer haProxy.Stop() type fields struct { - jobs chan Task socketPath string masterWorkerMode bool } @@ -308,9 +367,7 @@ func TestSingleRuntime_NewCertEntry(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -328,7 +385,6 @@ func TestSingleRuntime_SetCertEntry(t *testing.T) { defer haProxy.Stop() type fields struct { - jobs chan Task socketPath string masterWorkerMode bool } @@ -396,9 +452,7 @@ func TestSingleRuntime_SetCertEntry(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -416,7 +470,6 @@ func TestSingleRuntime_CommitCertEntry(t *testing.T) { defer haProxy.Stop() type fields struct { - jobs chan Task socketPath string masterWorkerMode bool } @@ -470,9 +523,7 @@ func TestSingleRuntime_CommitCertEntry(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -490,7 +541,6 @@ func TestSingleRuntime_AbortCertEntry(t *testing.T) { defer haProxy.Stop() type fields struct { - jobs chan Task socketPath string masterWorkerMode bool } @@ -542,9 +592,7 @@ func TestSingleRuntime_AbortCertEntry(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -562,7 +610,6 @@ func TestSingleRuntime_DeleteCertEntry(t *testing.T) { defer haProxy.Stop() type fields struct { - jobs chan Task socketPath string masterWorkerMode bool } @@ -614,9 +661,7 @@ func TestSingleRuntime_DeleteCertEntry(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return diff --git a/runtime/crt-lists.go b/runtime/crt-lists.go index 180a9dd1..b6ee4c5e 100644 --- a/runtime/crt-lists.go +++ b/runtime/crt-lists.go @@ -45,8 +45,8 @@ func (s *SingleRuntime) parseCrtLists(output string) CrtLists { } crtLists := CrtLists{} - lines := strings.Split(output, "\n") - for _, line := range lines { + lines := strings.SplitSeq(output, "\n") + for line := range lines { c := s.parseCrtList(line) if c != nil { crtLists = append(crtLists, c) @@ -83,7 +83,7 @@ func (s *SingleRuntime) GetCrtList(file string) (*CrtList, error) { // ShowCrtListEntries returns one CrtList runtime entries func (s *SingleRuntime) ShowCrtListEntries(file string) (CrtListEntries, error) { - cmd := fmt.Sprintf("show ssl crt-list -n %s", file) + cmd := "show ssl crt-list -n " + file response, err := s.ExecuteWithResponse(cmd) if err != nil { return nil, fmt.Errorf("%s %w", err.Error(), native_errors.ErrNotFound) @@ -103,8 +103,8 @@ func ParseCrtListEntries(output string) (CrtListEntries, error) { } ce := CrtListEntries{} - lines := strings.Split(strings.TrimSpace(output), "\n") - for _, line := range lines { + lines := strings.SplitSeq(strings.TrimSpace(output), "\n") + for line := range lines { entry := parseCrtListEntry(line) if entry != nil { ce = append(ce, entry) @@ -160,8 +160,12 @@ func (s *SingleRuntime) AddCrtListEntry(crtList string, entry CrtListEntry) erro } // DeleteCrtListEntry deletes all the CrtList entries from the CrtList by its id -func (s *SingleRuntime) DeleteCrtListEntry(crtList, certFile string, lineNumber int) error { - cmd := fmt.Sprintf("del ssl crt-list %s %s:%v", crtList, certFile, lineNumber) +func (s *SingleRuntime) DeleteCrtListEntry(crtList, certFile string, lineNumber *int64) error { + lineNumberPart := "" + if lineNumber != nil { + lineNumberPart = fmt.Sprintf(":%v", *lineNumber) + } + cmd := fmt.Sprintf("del ssl crt-list %s %s%s", crtList, certFile, lineNumberPart) response, err := s.ExecuteWithResponse(cmd) if err != nil { return fmt.Errorf("%s %w", err.Error(), native_errors.ErrNotFound) diff --git a/runtime/crt-lists_test.go b/runtime/crt-lists_test.go index 4fa8a3d1..334f0bdf 100644 --- a/runtime/crt-lists_test.go +++ b/runtime/crt-lists_test.go @@ -1,10 +1,10 @@ package runtime import ( - "context" "reflect" "testing" - "time" + + "github.com/haproxytech/client-native/v5/misc" ) func TestSingleRuntime_ShowCrtLists(t *testing.T) { @@ -50,9 +50,7 @@ func TestSingleRuntime_ShowCrtLists(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -136,9 +134,7 @@ func TestSingleRuntime_GetCrtList(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -161,7 +157,6 @@ func TestSingleRuntime_ShowCrtListEntries(t *testing.T) { defer haProxy.Stop() type fields struct { - jobs chan Task socketPath string masterWorkerMode bool } @@ -236,9 +231,7 @@ func TestSingleRuntime_ShowCrtListEntries(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -263,7 +256,6 @@ func TestSingleRuntime_AddCrtListEntry(t *testing.T) { defer haProxy.Stop() type fields struct { - jobs chan Task socketPath string masterWorkerMode bool } @@ -338,9 +330,7 @@ func TestSingleRuntime_AddCrtListEntry(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return @@ -358,7 +348,6 @@ func TestSingleRuntime_DeleteCrtListEntry(t *testing.T) { defer haProxy.Stop() type fields struct { - jobs chan Task socketPath string masterWorkerMode bool } @@ -407,14 +396,12 @@ func TestSingleRuntime_DeleteCrtListEntry(t *testing.T) { t.Run(tt.name, func(t *testing.T) { haProxy.SetResponses(&tt.socketResponse) s := &SingleRuntime{} - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second)) - defer cancel() - err := s.Init(ctx, tt.fields.socketPath, tt.fields.masterWorkerMode) + err := s.Init(tt.fields.socketPath, tt.fields.masterWorkerMode) if err != nil { t.Errorf("SingleRuntime.Init() error = %v", err) return } - if err := s.DeleteCrtListEntry(tt.args.crtList, tt.args.certFile, tt.args.lineNumber); (err != nil) != tt.wantErr { + if err := s.DeleteCrtListEntry(tt.args.crtList, tt.args.certFile, misc.Int64P(tt.args.lineNumber)); (err != nil) != tt.wantErr { t.Errorf("SingleRuntime.DeleteCrtListEntry() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/runtime/haproxy_mock.go b/runtime/haproxy_mock.go index 9fc00c64..e0511554 100644 --- a/runtime/haproxy_mock.go +++ b/runtime/haproxy_mock.go @@ -14,14 +14,16 @@ import ( // HAProxyMock - Mock HAProxy Server for testing the socket communication type HAProxyMock struct { net.Listener + responses map[string]string t *testing.T - - mu sync.RWMutex - running bool + mu sync.RWMutex + running bool } // NewHAProxyMock - create new haproxy mock +// +//nolint:thelper,noctx func NewHAProxyMock(t *testing.T) *HAProxyMock { haProxyMock := &HAProxyMock{} haProxyMock.t = t diff --git a/runtime/info.go b/runtime/info.go index 4831cfeb..b28b924c 100644 --- a/runtime/info.go +++ b/runtime/info.go @@ -40,7 +40,7 @@ func (s *SingleRuntime) GetInfo() models.ProcessInfo { func parseInfo(info string) *models.ProcessInfoItem { //nolint:gocognit,gocyclo,cyclop,maintidx data := &models.ProcessInfoItem{} - for _, line := range strings.Split(info, "\n") { + for line := range strings.SplitSeq(info, "\n") { fields := strings.Split(line, ":") fID := strings.TrimSpace(strings.Split(fields[0], ".")[0]) switch fID { diff --git a/runtime/interface.go b/runtime/interface.go index 05ac3b9a..826cbd39 100644 --- a/runtime/interface.go +++ b/runtime/interface.go @@ -71,6 +71,8 @@ type Servers interface { SetServerWeight(backend, server string, weight string) error // SetServerHealth set health for server SetServerHealth(backend, server string, health string) error + // EnableServerHealth + EnableServerHealth(backend, server string) error // EnableAgentCheck enable agent check for server EnableAgentCheck(backend, server string) error // DisableAgentCheck disable agent check for server @@ -136,6 +138,16 @@ type Raw interface { ExecuteRaw(command string) (string, error) } +type Cert interface { + NewCertEntry(filename string) error + SetCertEntry(filename, payload string) error + CommitCertEntry(filename string) error + AbortCertEntry(filename string) error + AddCrtListEntry(crtList string, entry CrtListEntry) error + DeleteCrtListEntry(crtList, filename string, lineNumber *int64) error + DeleteCertEntry(filename string) error +} + type Runtime interface { Info Frontend @@ -145,11 +157,12 @@ type Runtime interface { ACLs Tables Raw + Cert SocketPath() string IsStatsSocket() bool } -func New(ctx context.Context, opt ...options.RuntimeOption) (Runtime, error) { +func New(_ context.Context, opt ...options.RuntimeOption) (Runtime, error) { c := &client{ options: options.RuntimeOptions{}, } @@ -163,9 +176,9 @@ func New(ctx context.Context, opt ...options.RuntimeOption) (Runtime, error) { } if c.options.MasterSocketData != nil { - err = c.initWithMasterSocket(ctx, c.options) + err = c.initWithMasterSocket(c.options) } else { - err = c.initWithSockets(ctx, c.options) + err = c.initWithSockets(c.options) } if err != nil { return nil, err diff --git a/runtime/maps.go b/runtime/maps.go index 779e8520..b149b873 100644 --- a/runtime/maps.go +++ b/runtime/maps.go @@ -60,8 +60,8 @@ func (s *SingleRuntime) parseMaps(output string) models.Maps { } maps := models.Maps{} - lines := strings.Split(strings.TrimSpace(output), "\n") - for _, line := range lines { + lines := strings.SplitSeq(strings.TrimSpace(output), "\n") + for line := range lines { m := s.parseMap(line) if m != nil { maps = append(maps, m) @@ -107,7 +107,7 @@ func (s *SingleRuntime) GetMap(name string) (*models.Map, error) { // ClearMap removes all map entries from the map file. func (s *SingleRuntime) ClearMap(name string) error { - cmd := fmt.Sprintf("clear map %s", name) + cmd := "clear map " + name if err := s.Execute(cmd); err != nil { return fmt.Errorf("%s %w", err.Error(), native_errors.ErrNotFound) } @@ -125,7 +125,7 @@ func (s *SingleRuntime) ClearMapVersioned(name, version string) error { // ShowMapEntries returns one map runtime entries func (s *SingleRuntime) ShowMapEntries(name string) (models.MapEntries, error) { - cmd := fmt.Sprintf("show map %s", name) + cmd := "show map " + name response, err := s.ExecuteWithResponse(cmd) if err != nil { return nil, fmt.Errorf("%s %w", err.Error(), native_errors.ErrNotFound) @@ -153,8 +153,8 @@ func ParseMapEntries(output string, hasID bool) models.MapEntries { } me := models.MapEntries{} - lines := strings.Split(strings.TrimSpace(output), "\n") - for _, line := range lines { + lines := strings.SplitSeq(strings.TrimSpace(output), "\n") + for line := range lines { e := parseMapEntry(line, hasID) if e != nil { me = append(me, e) @@ -239,8 +239,8 @@ func (s *SingleRuntime) AddMapPayload(name, payload string) error { return nil } -func (s *SingleRuntime) PrepareMap(name string) (version string, err error) { - cmd := fmt.Sprintf("prepare map %s", name) +func (s *SingleRuntime) PrepareMap(name string) (string, error) { + cmd := "prepare map " + name response, err := s.ExecuteWithResponse(cmd) if err != nil { return "", fmt.Errorf("%s %w", err.Error(), native_errors.ErrGeneral) @@ -249,7 +249,7 @@ func (s *SingleRuntime) PrepareMap(name string) (version string, err error) { if len(parts) < 3 { return "", fmt.Errorf("%s %w", "parsing error", native_errors.ErrGeneral) } - version = strings.TrimSpace(parts[2]) + version := strings.TrimSpace(parts[2]) if _, err = strconv.ParseInt(version, 10, 64); err == nil { return version, nil } @@ -285,13 +285,13 @@ func (s *SingleRuntime) GetMapEntry(name, id string) (*models.MapEntry, error) { } m := &models.MapEntry{} - parts := strings.Split(response, ",") - for _, p := range parts { + parts := strings.SplitSeq(response, ",") + for p := range parts { kv := strings.Split(p, "=") - switch key := strings.TrimSpace(kv[0]); { - case key == "key": + switch key := strings.TrimSpace(kv[0]); key { + case "key": m.Key = strings.TrimPrefix(strings.TrimSuffix(kv[1], "\""), "\"") - case key == "value": + case "value": m.Value = strings.TrimPrefix(strings.TrimSuffix(kv[1], "\""), "\"") } } diff --git a/runtime/runtime_client.go b/runtime/runtime_client.go index 34331d8c..975d454a 100644 --- a/runtime/runtime_client.go +++ b/runtime/runtime_client.go @@ -16,28 +16,25 @@ package runtime import ( - "context" + "errors" "fmt" "io" "mime/multipart" "os" "path/filepath" "strings" - "sync" - - "github.com/pkg/errors" native_errors "github.com/haproxytech/client-native/v6/errors" "github.com/haproxytech/client-native/v6/misc" "github.com/haproxytech/client-native/v6/models" "github.com/haproxytech/client-native/v6/runtime/options" + "golang.org/x/sync/singleflight" ) // Client handles multiple HAProxy clients type client struct { - haproxyVersion *HAProxyVersion - options options.RuntimeOptions - runtime SingleRuntime + options options.RuntimeOptions + runtime *SingleRuntime } const ( @@ -48,29 +45,31 @@ const ( maxBufSize = 8192 ) -func (c *client) initWithSockets(ctx context.Context, opt options.RuntimeOptions) error { +func (c *client) initWithSockets(opt options.RuntimeOptions) error { socketPath := opt.Socket - runtime := SingleRuntime{} + runtime := &SingleRuntime{} masterWorkerMode := false - err := runtime.Init(ctx, socketPath, masterWorkerMode, opt) - if err != nil { - return err + if socketPath != "" { + err := runtime.Init(socketPath, masterWorkerMode, opt) + if err != nil { + return err + } + c.runtime = runtime } - c.runtime = runtime _, _ = c.GetVersion() return nil } -func (c *client) initWithMasterSocket(ctx context.Context, opt options.RuntimeOptions) error { +func (c *client) initWithMasterSocket(opt options.RuntimeOptions) error { masterSocketPath := opt.MasterSocketData.MasterSocketPath if masterSocketPath == "" { return errors.New("master socket not configured") } - runtime := SingleRuntime{} + runtime := &SingleRuntime{} masterWorkerMode := true - err := runtime.Init(ctx, masterSocketPath, masterWorkerMode, opt) + err := runtime.Init(masterSocketPath, masterWorkerMode, opt) if err != nil { return err } @@ -82,60 +81,79 @@ func (c *client) initWithMasterSocket(ctx context.Context, opt options.RuntimeOp // GetStats returns stats from the socket func (c *client) GetStats() models.NativeStats { + if !c.runtime.IsValid() { + return models.NativeStats{} + } result := c.runtime.GetStats() return result } // GetInfo returns info from the socket func (c *client) GetInfo() (models.ProcessInfo, error) { + if !c.runtime.IsValid() { + return models.ProcessInfo{}, errors.New("no valid runtime found") + } result := c.runtime.GetInfo() return result, nil } -var versionSync sync.Once //nolint:gochecknoglobals +var ( + haproxyVersion *HAProxyVersion //nolint:gochecknoglobals + versionKey = "version" //nolint:gochecknoglobals + versionSfg = singleflight.Group{} //nolint:gochecknoglobals +) // GetVersion returns info from the socket func (c *client) GetVersion() (HAProxyVersion, error) { var err error - versionSync.Do(func() { + if haproxyVersion != nil { + return *haproxyVersion, nil + } + _, err, _ = versionSfg.Do(versionKey, func() (any, error) { version := &HAProxyVersion{} var response string + if !c.runtime.IsValid() { + return HAProxyVersion{}, errors.New("no valid runtime found") + } response, err = c.runtime.ExecuteRaw("show info") if err != nil { - return + return HAProxyVersion{}, err } - for _, line := range strings.Split(response, "\n") { - if strings.HasPrefix(line, "Version: ") { - err = version.ParseHAProxyVersion(strings.TrimPrefix(line, "Version: ")) + for line := range strings.SplitSeq(response, "\n") { + versionStr, found := strings.CutPrefix(line, "Version: ") + if found { + err = version.ParseHAProxyVersion(versionStr) if err != nil { - return + return HAProxyVersion{}, err } - c.haproxyVersion = version - return + haproxyVersion = version + return HAProxyVersion{}, err } // Starting with HAProxy 3.0, there is no more "Version:" prefix. if len(line) > 0 && line[0] >= '3' && line[0] <= '9' { err = version.ParseHAProxyVersion(line) if err == nil { - c.haproxyVersion = version + haproxyVersion = version } - return + return HAProxyVersion{}, err } } err = errors.New("version data not found") + return HAProxyVersion{}, err // it's dereferenced in IsVersionBiggerOrEqual }) if err != nil { return HAProxyVersion{}, err } - if c.haproxyVersion == nil { + if haproxyVersion == nil { return HAProxyVersion{}, errors.New("version data not found") } - return *c.haproxyVersion, err + + return *haproxyVersion, err } func (c *client) IsVersionBiggerOrEqual(minimumVersion *HAProxyVersion) bool { - return IsBiggerOrEqual(minimumVersion, c.haproxyVersion) + return IsBiggerOrEqual(minimumVersion, haproxyVersion) } // Reloads HAProxy's configuration file. Similar to SIGUSR2. Returns the startup logs. @@ -146,9 +164,12 @@ func (c *client) Reload() (string, error) { return "", errors.New("cannot reload: not connected to a master socket") } if !c.IsVersionBiggerOrEqual(&HAProxyVersion{Major: 2, Minor: 7}) { - return "", errors.New("cannot reload: requires HAProxy 2.7 or later") + return "", fmt.Errorf("cannot reload: requires HAProxy 2.7 or later but current version is %v", haproxyVersion) } + if !c.runtime.IsValid() { + return "", errors.New("cannot reload: no valid runtime found") + } output, err := c.runtime.ExecuteMaster("reload") if err != nil { return "", fmt.Errorf("cannot reload: %w", err) @@ -156,7 +177,9 @@ func (c *client) Reload() (string, error) { parts := strings.SplitN(output, "\n--\n", 2) if len(parts) == 1 { // No startup logs. This happens when HAProxy is compiled without USE_SHM_OPEN. - status = output[:len(output)-1] + if len(output) > 0 { + status = output[:len(output)-1] + } } else { status, logs = parts[0], parts[1] } @@ -220,7 +243,7 @@ func (c *client) AddServer(backend, name, attributes string) error { return errors.New("no valid runtime found") } if !c.IsVersionBiggerOrEqual(&HAProxyVersion{Major: 2, Minor: 6}) { - return errors.New("this operation requires HAProxy 2.6 or later") + return fmt.Errorf("this operation requires HAProxy 2.6 or later but current version is %v", haproxyVersion) } err := c.runtime.AddServer(backend, name, attributes) if err != nil { @@ -293,6 +316,19 @@ func (c *client) SetServerHealth(backend, server string, health string) error { return nil } +// EnableServerHealth enable health check for server +func (c *client) EnableServerHealth(backend, server string) error { + if !c.runtime.IsValid() { + return errors.New("no valid runtime found") + } + err := c.runtime.EnableServerHealth(backend, server) + if err != nil { + return fmt.Errorf("%s %w", c.runtime.socketPath, err) + } + + return nil +} + // EnableAgentCheck enable agent check for server func (c *client) EnableAgentCheck(backend, server string) error { if !c.runtime.IsValid() { @@ -538,7 +574,7 @@ func (c *client) ClearMap(name string, forceDelete bool) error { if os.IsNotExist(err) { return native_errors.ErrNotFound } - return fmt.Errorf(strings.Join([]string{err.Error(), native_errors.ErrNotFound.Error()}, " ")) + return fmt.Errorf("%s %s", err.Error(), native_errors.ErrNotFound.Error()) } } @@ -562,7 +598,7 @@ func (c *client) ClearMapVersioned(name, version string, forceDelete bool) error if os.IsNotExist(err) { return native_errors.ErrNotFound } - return fmt.Errorf(strings.Join([]string{err.Error(), native_errors.ErrNotFound.Error()}, " ")) + return fmt.Errorf("%s %s", err.Error(), native_errors.ErrNotFound.Error()) } } @@ -628,10 +664,12 @@ func (c *client) AddMapPayload(name, payload string) error { return nil } -func parseMapPayload(entries models.MapEntries, maxBufSize int) (exceededSize bool, payload []string) { +func parseMapPayload(entries models.MapEntries, maxBufSize int) (bool, []string) { prevKV := "" currKV := "" data := "" + var payload []string + var exceededSize bool for _, d := range entries { if prevKV != "" { data += prevKV @@ -684,7 +722,7 @@ func (c *client) AddMapPayloadVersioned(name string, entries models.MapEntries) if err != nil { return fmt.Errorf("%s %w", c.runtime.socketPath, err) } - for i := 0; i < len(payload); i++ { + for i := range payload { err = c.runtime.AddMapPayloadVersioned(version, name, payload[i]) if err != nil { return fmt.Errorf("%s %w", c.runtime.socketPath, err) @@ -733,15 +771,15 @@ func (c *client) AddMapEntryVersioned(version, name, key, value string) error { return nil } -func (c *client) PrepareMap(name string) (version string, err error) { +func (c *client) PrepareMap(name string) (string, error) { if !c.runtime.IsValid() { return "", errors.New("no valid runtime found") } - name, err = c.GetMapsPath(name) + name, err := c.GetMapsPath(name) if err != nil { return "", fmt.Errorf("%s %w", c.runtime.socketPath, err) } - version, err = c.runtime.PrepareMap(name) + version, err := c.runtime.PrepareMap(name) if err != nil { return "", fmt.Errorf("%s %w", c.runtime.socketPath, err) } @@ -819,45 +857,45 @@ func (c *client) ParseMapEntriesFromFile(inputFile io.Reader, hasID bool) models } // GetACLFile returns a the ACL file by its ID -func (c *client) GetACLFile(id string) (files *models.ACLFile, err error) { +func (c *client) GetACLFile(id string) (*models.ACLFile, error) { if !c.runtime.IsValid() { return nil, errors.New("no valid runtime found") } - files, err = c.runtime.GetACL("#" + id) + files, err := c.runtime.GetACL("#" + id) if err != nil { - err = errors.Wrap(err, "cannot retrieve ACL file for "+id) + err = fmt.Errorf("cannot retrieve ACL file for %s: %w", id, err) } - return + return files, err } // GetACLFiles returns all the ACL files -func (c *client) GetACLFiles() (files models.ACLFiles, err error) { +func (c *client) GetACLFiles() (models.ACLFiles, error) { if !c.runtime.IsValid() { return nil, errors.New("no valid runtime found") } - files, err = c.runtime.ShowACLS() + files, err := c.runtime.ShowACLS() if err != nil { - err = errors.Wrap(err, "cannot retrieve ACL files") + err = fmt.Errorf("cannot retrieve ACL files: %w", err) } - return + return files, err } // GetACLFilesEntries returns all the files entries for the ACL file ID -func (c *client) GetACLFilesEntries(id string) (files models.ACLFilesEntries, err error) { +func (c *client) GetACLFilesEntries(id string) (models.ACLFilesEntries, error) { if !c.runtime.IsValid() { return nil, errors.New("no valid runtime found") } - files, err = c.runtime.ShowACLFileEntries("#" + id) + files, err := c.runtime.ShowACLFileEntries("#" + id) if err != nil { - err = errors.Wrap(err, "cannot retrieve ACL files entries for "+id) + err = fmt.Errorf("cannot retrieve ACL files entries for %s: %w", id, err) } - return + return files, err } // AddACLFileEntry adds the value for the specified ACL file entry based on its ID @@ -866,20 +904,20 @@ func (c *client) AddACLFileEntry(id, value string) error { return errors.New("no valid runtime found") } if err := c.runtime.AddACLFileEntry(id, value); err != nil { - return errors.Wrap(err, "cannot add ACL files entry for "+id) + return fmt.Errorf("cannot add ACL files entry for %s: %w", id, err) } return nil } // GetACLFileEntry returns the specified file entry based on value and ACL file ID -func (c *client) GetACLFileEntry(id, value string) (fileEntry *models.ACLFileEntry, err error) { +func (c *client) GetACLFileEntry(id, value string) (*models.ACLFileEntry, error) { if !c.runtime.IsValid() { return nil, errors.New("no valid runtime found") } - var fe models.ACLFilesEntries - if fe, err = c.runtime.ShowACLFileEntries("#" + id); err != nil { - return nil, errors.Wrap(err, "cannot retrieve ACL file entries, cannot list available ACL files") + fe, err := c.runtime.ShowACLFileEntries("#" + id) + if err != nil { + return nil, fmt.Errorf("cannot retrieve ACL file entries, cannot list available ACL files: %w", err) } for _, e := range fe { @@ -889,11 +927,12 @@ func (c *client) GetACLFileEntry(id, value string) (fileEntry *models.ACLFileEnt } } - if fileEntry, err = c.runtime.GetACLFileEntry(id, value); err != nil { - err = errors.Wrap(err, "cannot retrieve ACL file entry for "+id) + fileEntry, err := c.runtime.GetACLFileEntry(id, value) + if err != nil { + err = fmt.Errorf("cannot retrieve ACL file entry for %s: %w", id, err) } - return + return fileEntry, err } // DeleteACLFileEntry deletes the value for the specified ACL file entry based on its ID @@ -902,7 +941,7 @@ func (c *client) DeleteACLFileEntry(id, value string) error { return errors.New("no valid runtime found") } if err := c.runtime.DeleteACLFileEntry(id, value); err != nil { - return errors.Wrap(err, "cannot delete ACL files entry for "+id) + return fmt.Errorf("cannot delete ACL files entry for %s: %w", id, err) } return nil @@ -936,11 +975,11 @@ func (c *client) AddACLAtomic(aclID string, entries models.ACLFilesEntries) erro return nil } -func (c *client) PrepareACL(name string) (version string, err error) { +func (c *client) PrepareACL(name string) (string, error) { if !c.runtime.IsValid() { return "", errors.New("no valid runtime found") } - version, err = c.runtime.PrepareACL(name) + version, err := c.runtime.PrepareACL(name) if err != nil { return "", fmt.Errorf("%s %w", c.runtime.socketPath, err) } @@ -978,3 +1017,83 @@ func (c *client) SocketPath() string { func (c *client) IsStatsSocket() bool { return !c.runtime.masterWorkerMode } + +func (c *client) NewCertEntry(filename string) error { + if !c.runtime.IsValid() { + return errors.New("no valid runtime found") + } + if err := c.runtime.NewCertEntry(filename); err != nil { + return fmt.Errorf("%s %w", c.runtime.socketPath, err) + } + + return nil +} + +func (c *client) SetCertEntry(filename string, payload string) error { + if !c.runtime.IsValid() { + return errors.New("no valid runtime found") + } + if err := c.runtime.SetCertEntry(filename, payload); err != nil { + return fmt.Errorf("%s %w", c.runtime.socketPath, err) + } + + return nil +} + +func (c *client) CommitCertEntry(filename string) error { + if !c.runtime.IsValid() { + return errors.New("no valid runtime found") + } + if err := c.runtime.CommitCertEntry(filename); err != nil { + return fmt.Errorf("%s %w", c.runtime.socketPath, err) + } + + return nil +} + +func (c *client) AbortCertEntry(filename string) error { + if !c.runtime.IsValid() { + return errors.New("no valid runtime found") + } + if err := c.runtime.AbortCertEntry(filename); err != nil { + return fmt.Errorf("%s %w", c.runtime.socketPath, err) + } + + return nil +} + +func (c *client) AddCrtListEntry(crtList string, entry CrtListEntry) error { + if !c.runtime.IsValid() { + return errors.New("no valid runtime found") + } + + if err := c.runtime.AddCrtListEntry(crtList, entry); err != nil { + return fmt.Errorf("%s %w", c.runtime.socketPath, err) + } + + return nil +} + +func (c *client) DeleteCrtListEntry(crtList, filename string, lineNumber *int64) error { + if !c.runtime.IsValid() { + return errors.New("no valid runtime found") + } + + if err := c.runtime.DeleteCrtListEntry(crtList, filename, lineNumber); err != nil { + return fmt.Errorf("%s %w", c.runtime.socketPath, err) + } + + return nil +} + +func (c *client) DeleteCertEntry(filename string) error { + if !c.runtime.IsValid() { + return errors.New("no valid runtime found") + } + + if err := c.runtime.DeleteCertEntry(filename); err != nil { + return fmt.Errorf("%s %w", c.runtime.socketPath, err) + } + + return nil +} diff --git a/runtime/runtime_const.go b/runtime/runtime_const.go index 0a55ca70..6d3d70c4 100644 --- a/runtime/runtime_const.go +++ b/runtime/runtime_const.go @@ -63,8 +63,8 @@ func ServerHealthValid(health string) bool { func ServerWeightValid(weight string) bool { var n int64 var err error - if strings.HasSuffix(weight, "%") { - percent := strings.TrimSuffix(weight, "%") + percent, found := strings.CutSuffix(weight, "%") + if found { if n, err = strconv.ParseInt(percent, 10, 64); err != nil { return false } diff --git a/runtime/runtime_single_client.go b/runtime/runtime_single_client.go index 3abb0a16..67df7c3d 100644 --- a/runtime/runtime_single_client.go +++ b/runtime/runtime_single_client.go @@ -16,11 +16,11 @@ package runtime import ( - "context" "errors" "fmt" "net" "strings" + "sync" "time" "github.com/haproxytech/client-native/v6/runtime/options" @@ -35,41 +35,26 @@ const ( type socketType string -// TaskResponse ... -type TaskResponse struct { - err error - result string -} - -// Task has command to execute on runtime api, and response channel for result -type Task struct { - command string - response chan TaskResponse - socket socketType -} - // SingleRuntime handles one runtime API type SingleRuntime struct { - jobs chan Task socketPath string masterWorkerMode bool + mtx sync.RWMutex } -func (s SingleRuntime) IsValid() bool { - return s.socketPath != "" +func (s *SingleRuntime) IsValid() bool { + return s != nil && s.socketPath != "" } // Init must be given path to runtime socket and a flag to indicate if it's in master-worker mode. -func (s *SingleRuntime) Init(ctx context.Context, socketPath string, masterWorkerMode bool, opt ...options.RuntimeOptions) error { +func (s *SingleRuntime) Init(socketPath string, masterWorkerMode bool, opt ...options.RuntimeOptions) error { var runtimeOptions options.RuntimeOptions if len(opt) > 0 { runtimeOptions = opt[0] } s.socketPath = socketPath - s.jobs = make(chan Task) s.masterWorkerMode = masterWorkerMode - go s.handleIncomingJobs(ctx) if !runtimeOptions.DoNotCheckRuntimeOnInit { if runtimeOptions.AllowDelayedStartMax != nil { now := time.Now() @@ -93,26 +78,10 @@ func (s *SingleRuntime) Init(ctx context.Context, socketPath string, masterWorke return nil } -func (s *SingleRuntime) handleIncomingJobs(ctx context.Context) { - for { - select { - case job, ok := <-s.jobs: - if !ok { - return - } - result, err := s.readFromSocket(job.command, job.socket) - if err != nil { - job.response <- TaskResponse{err: err} - } else { - job.response <- TaskResponse{result: result} - } - case <-ctx.Done(): - return - } - } -} - +//nolint:noctx func (s *SingleRuntime) readFromSocket(command string, socket socketType) (string, error) { + s.mtx.Lock() + defer s.mtx.Unlock() var api net.Conn var err error @@ -135,7 +104,7 @@ func (s *SingleRuntime) readFromSocket(command string, socket socketType) (strin fullCommand = fmt.Sprintf("set severity-output number;@%v %s;quit\n", 1, command) } case masterSocket: - fullCommand = fmt.Sprintf("%s;quit", command) + fullCommand = command + ";quit\n" } _, err = api.Write([]byte(fullCommand)) @@ -161,7 +130,7 @@ func (s *SingleRuntime) readFromSocket(command string, socket socketType) (strin result := strings.TrimSuffix(data.String(), "\n> ") result = strings.TrimSuffix(result, "\n") result = strings.TrimSpace(result) - return result, nil //nolint:nilerr + return result, nil } // ExecuteRaw executes command on runtime API and returns raw result @@ -205,17 +174,10 @@ func (s *SingleRuntime) ExecuteMaster(command string) (string, error) { } func (s *SingleRuntime) executeRaw(command string, retry int, socket socketType) (string, error) { - response := make(chan TaskResponse) - task := Task{ - command: command, - response: response, - socket: socket, - } - s.jobs <- task - rsp := <-response - if rsp.err != nil && retry > 0 { + result, err := s.readFromSocket(command, socket) + if err != nil && retry > 0 { retry-- return s.executeRaw(command, retry, socket) } - return rsp.result, rsp.err + return result, err } diff --git a/runtime/servers.go b/runtime/servers.go index 8e07af4b..1ac64e6e 100644 --- a/runtime/servers.go +++ b/runtime/servers.go @@ -20,6 +20,8 @@ import ( "strconv" "strings" + stderrors "errors" + "github.com/haproxytech/client-native/v6/errors" "github.com/haproxytech/client-native/v6/misc" "github.com/haproxytech/client-native/v6/models" @@ -51,7 +53,7 @@ func (s *SingleRuntime) SetServerAddr(backend, server string, ip string, port in // SetServerState set state for server func (s *SingleRuntime) SetServerState(backend, server string, state string) error { if !ServerStateValid(state) { - return fmt.Errorf("bad request") + return stderrors.New("bad request") } cmd := fmt.Sprintf("set server %s/%s state %s", backend, server, state) return s.Execute(cmd) @@ -60,7 +62,7 @@ func (s *SingleRuntime) SetServerState(backend, server string, state string) err // SetServerWeight set weight for server func (s *SingleRuntime) SetServerWeight(backend, server string, weight string) error { if !ServerWeightValid(weight) { - return fmt.Errorf("bad request") + return stderrors.New("bad request") } cmd := fmt.Sprintf("set server %s/%s weight %s", backend, server, weight) return s.Execute(cmd) @@ -69,16 +71,22 @@ func (s *SingleRuntime) SetServerWeight(backend, server string, weight string) e // SetServerHealth set health for server func (s *SingleRuntime) SetServerHealth(backend, server string, health string) error { if !ServerHealthValid(health) { - return fmt.Errorf("bad request") + return stderrors.New("bad request") } cmd := fmt.Sprintf("set server %s/%s health %s", backend, server, health) return s.Execute(cmd) } +// EnableServerHealth enable health check for server +func (s *SingleRuntime) EnableServerHealth(backend, server string) error { + cmd := fmt.Sprintf("enable health %s/%s", backend, server) + return s.Execute(cmd) +} + // SetServerCheckPort set health heck port for server func (s *SingleRuntime) SetServerCheckPort(backend, server string, port int) error { - if !(port > 0 && port <= 65535) { - return fmt.Errorf("bad request") + if port < 1 || port > 65535 { + return stderrors.New("bad request") } return s.Execute(fmt.Sprintf("set server %s/%s check-port %d", backend, server, port)) } @@ -121,7 +129,7 @@ func (s *SingleRuntime) SetServerAgentSend(backend, server string, send string) // GetServersState returns servers runtime state func (s *SingleRuntime) GetServersState(backend string) (models.RuntimeServers, error) { - cmd := fmt.Sprintf("show servers state %s", backend) + cmd := "show servers state " + backend result, err := s.ExecuteWithResponse(cmd) if err != nil { return nil, err @@ -131,7 +139,7 @@ func (s *SingleRuntime) GetServersState(backend string) (models.RuntimeServers, // GetServersState returns server runtime state func (s *SingleRuntime) GetServerState(backend, server string) (*models.RuntimeServer, error) { - cmd := fmt.Sprintf("show servers state %s", backend) + cmd := "show servers state " + backend result, err := s.ExecuteWithResponse(cmd) if err != nil { return nil, err @@ -139,7 +147,7 @@ func (s *SingleRuntime) GetServerState(backend, server string) (*models.RuntimeS lines := strings.Split(result, "\n") if strings.TrimSpace(lines[0]) != "1" { - return nil, fmt.Errorf("unsupported output format version, supporting format version 1") + return nil, stderrors.New("unsupported output format version, supporting format version 1") } for _, line := range lines { @@ -160,7 +168,7 @@ func parseRuntimeServers(output string) (models.RuntimeServers, error) { result := models.RuntimeServers{} if strings.TrimSpace(lines[0]) != "1" { - return nil, fmt.Errorf("unsupported output format version, supporting format version 1") + return nil, stderrors.New("unsupported output format version, supporting format version 1") } for _, line := range lines[1:] { if strings.TrimSpace(line) == "" || strings.HasPrefix(line, "#") || strings.TrimSpace(line) == "1" { diff --git a/runtime/stats.go b/runtime/stats.go index d3c32d61..af8cde20 100644 --- a/runtime/stats.go +++ b/runtime/stats.go @@ -26,7 +26,7 @@ import ( // GetStats fetches HAProxy stats from runtime API func (s *SingleRuntime) GetStats() models.NativeStats { - rAPI := "" + var rAPI string if s.masterWorkerMode { rAPI = fmt.Sprintf("%s@%v", s.socketPath, 1) } else { diff --git a/runtime/stick_tables.go b/runtime/stick_tables.go index f5c8d68b..16838da5 100644 --- a/runtime/stick_tables.go +++ b/runtime/stick_tables.go @@ -16,7 +16,7 @@ func (s *SingleRuntime) SetTableEntry(table, key string, dataType models.StickTa if err != nil { return err } - var marshalDataType map[string]interface{} + var marshalDataType map[string]any if err = json.Unmarshal(b, &marshalDataType); err != nil { return err } @@ -51,8 +51,8 @@ func (s *SingleRuntime) ShowTable(name string) (*models.StickTable, error) { return nil, err } - lines := strings.Split(response, "\n") - for _, line := range lines { + lines := strings.SplitSeq(response, "\n") + for line := range lines { stkT := s.parseStickTable(line) if stkT == nil || stkT.Name != name { continue @@ -64,7 +64,7 @@ func (s *SingleRuntime) ShowTable(name string) (*models.StickTable, error) { // GetTableEntries returns Stick Tables entries func (s *SingleRuntime) GetTableEntries(name string, filter []string, key string) (models.StickTableEntries, error) { - cmd := fmt.Sprintf("show table %s", name) + cmd := "show table " + name // use only first filter here if len(filter) > 0 { @@ -119,9 +119,9 @@ func (s *SingleRuntime) parseStickTable(output string) *models.StickTable { } stkTable := &models.StickTable{} - stkStrings := strings.Split(output, ",") + stkStrings := strings.SplitSeq(output, ",") - for _, stkT := range stkStrings { + for stkT := range stkStrings { switch { case strings.HasPrefix(stkT, "# table:"): stkTable.Name = strings.TrimSpace(stkT[len("# table:"):]) @@ -139,7 +139,7 @@ func (s *SingleRuntime) parseStickTable(output string) *models.StickTable { return stkTable } -func parseStickTableEntry(output string) *models.StickTableEntry { //nolint:gocognit,gocyclo,cyclop +func parseStickTableEntry(output string) *models.StickTableEntry { //nolint:gocognit,gocyclo,cyclop, maintidx idData := strings.SplitN(output, ":", 2) if len(idData) != 2 { return nil @@ -153,6 +153,27 @@ func parseStickTableEntry(output string) *models.StickTableEntry { //nolint:goco if err == nil { entry.ServerID = &sID } + case strings.HasPrefix(key, "gpc("): + gpc, err := strconv.ParseInt(strings.TrimSpace(v), 10, 64) + if err == nil { + entry.Gpc = &models.StickTableEntryGpc{ + Value: &gpc, + } + if index, ok := parseIndex(key); ok { + entry.Gpc.Idx = index + } + } + case strings.HasPrefix(key, "gpc_rate(") && strings.Contains(key, ","): + gpcRate, err := strconv.ParseInt(strings.TrimSpace(v), 10, 64) + if err == nil { + entry.GpcRate = &models.StickTableEntryGpcRate{ + Value: &gpcRate, + } + if index, ok := parseIndexRate(key); ok { + entry.GpcRate.Idx = index + } + } + case key == "gpc0": gpc0, err := strconv.ParseInt(strings.TrimSpace(v), 10, 64) if err == nil { @@ -168,6 +189,21 @@ func parseStickTableEntry(output string) *models.StickTableEntry { //nolint:goco if err == nil { entry.Gpc1 = &gpc1 } + case key == "gpt0": + gpt0, err := strconv.ParseInt(strings.TrimSpace(v), 10, 64) + if err == nil { + entry.Gpt0 = &gpt0 + } + case strings.HasPrefix(key, "gpt("): + gpt, err := strconv.ParseInt(strings.TrimSpace(v), 10, 64) + if err == nil { + entry.Gpt = &models.StickTableEntryGpt{ + Value: &gpt, + } + if index, ok := parseIndex(key); ok { + entry.Gpt.Idx = index + } + } case strings.HasPrefix(key, "gpc1_rate("): gpc1Rate, err := strconv.ParseInt(strings.TrimSpace(v), 10, 64) if err == nil { @@ -198,6 +234,17 @@ func parseStickTableEntry(output string) *models.StickTableEntry { //nolint:goco if err == nil { entry.SessRate = &sessRate } + case key == "http_fail_cnt": + httpFailCnt, err := strconv.ParseInt(strings.TrimSpace(v), 10, 64) + if err == nil { + entry.HTTPFailCnt = &httpFailCnt + } + case strings.HasPrefix(key, "http_fail_rate("): + httpFailRate, err := strconv.ParseInt(strings.TrimSpace(v), 10, 64) + if err == nil { + entry.HTTPFailRate = &httpFailRate + } + case key == "http_req_cnt": httpReqCnt, err := strconv.ParseInt(strings.TrimSpace(v), 10, 64) if err == nil { @@ -275,3 +322,35 @@ func parseStickTableEntryLine(data string) map[string]string { } return retData } + +func parseIndex(key string) (int64, bool) { + // Extract content between parentheses + indexStr := strings.TrimPrefix(key, "gpc(") + indexStr = strings.TrimSuffix(indexStr, ")") + + index, err := strconv.ParseInt(strings.TrimSpace(indexStr), 10, 64) + if err != nil { + return 0, false + } + + return index, true +} + +func parseIndexRate(key string) (int64, bool) { + // Extract content between parentheses + params := strings.TrimPrefix(key, "gpc_rate(") + params = strings.TrimSuffix(params, ")") + + // Split by comma + parts := strings.Split(params, ",") + if len(parts) != 2 { + return 0, false + } + + index, err := strconv.ParseInt(strings.TrimSpace(parts[0]), 10, 64) + if err != nil { + return 0, false + } + + return index, true +} diff --git a/specification/build/haproxy_spec.yaml b/specification/build/haproxy_spec.yaml index e9333610..faf3b445 100644 --- a/specification/build/haproxy_spec.yaml +++ b/specification/build/haproxy_spec.yaml @@ -1992,6 +1992,8 @@ definitions: pattern: ^[^\s]+$ type: string x-display-name: Group + h1_accept_payload_with_any_method: + type: boolean h1_case_adjust: items: properties: @@ -2009,6 +2011,8 @@ definitions: x-omitempty: true h1_case_adjust_file: type: string + h1_do_not_close_on_insecure_transfer_encoding: + type: boolean h2_workaround_bogus_websocket_clients: type: boolean hard_stop_after: @@ -2171,6 +2175,8 @@ definitions: x-omitempty: true ssl_options: $ref: '#/definitions/ssl_options' + stats_file: + type: string stats_maxconn: type: integer x-display-name: Stats maxconn @@ -3287,8 +3293,7 @@ definitions: type: string x-dependency: cookie: - dynamic: - value: true + dynamic.value: true email_alert: $ref: '#/definitions/email_alert' enabled: @@ -3942,6 +3947,7 @@ definitions: - secure_password - password title: User + type: object users: title: Users description: HAProxy userlist users array @@ -4048,6 +4054,9 @@ definitions: servers: additionalProperties: $ref: '#/definitions/server' + tables: + additionalProperties: + $ref: '#/definitions/table' type: object description: Peer Section with all it's children resources type: object @@ -4187,6 +4196,9 @@ definitions: id: type: integer x-nullable: true + metadata: + additionalProperties: + type: object name: pattern: ^[^\s]+$ type: string @@ -4377,7 +4389,7 @@ definitions: value: capture x-display-name: Capture Len capture_sample: - pattern: ^[^\s]+$ + pattern: ^(?:[A-Za-z]+\("([A-Za-z\s]+)"\)|[A-Za-z]+) type: string x-dependency: type: @@ -4736,6 +4748,14 @@ definitions: value: return x-display-name: Return Error Code x-nullable: true + rst_ttl: + type: integer + x-dependency: + type: + required: true + value: + - silent-drop + x-display-name: RST TTL sc_expr: type: string x-dependency: @@ -4908,12 +4928,10 @@ definitions: - set-tos - set-uri - set-var + - set-var-fmt - silent-drop - strict-mode - tarpit - - track-sc0 - - track-sc1 - - track-sc2 - track-sc - unset-var - use-service @@ -5312,6 +5330,14 @@ definitions: value: return x-display-name: Return Error Code x-nullable: true + rst_ttl: + type: integer + x-dependency: + type: + required: true + value: + - silent-drop + x-display-name: RST TTL sc_expr: type: string x-dependency: @@ -5472,9 +5498,6 @@ definitions: - set-var-fmt - silent-drop - strict-mode - - track-sc0 - - track-sc1 - - track-sc2 - track-sc - unset-var - wait-for-body @@ -5584,7 +5607,7 @@ definitions: value: capture x-display-name: Capture Len capture_sample: - pattern: ^[^\s]+$ + pattern: ^(?:[A-Za-z]+\("([A-Za-z\s]+)"\)|[A-Za-z]+) type: string x-dependency: type: @@ -6220,9 +6243,6 @@ definitions: - set-var-fmt - silent-drop - switch-mode - - track-sc0 - - track-sc1 - - track-sc2 - track-sc - unset-var - use-service @@ -6272,7 +6292,7 @@ definitions: - content x-display-name: Capture Length capture_sample: - pattern: ^[^\s]+$ + pattern: ^(?:[A-Za-z]+\("([A-Za-z\s]+)"\)|[A-Za-z]+) type: string x-dependency: action: @@ -6449,6 +6469,14 @@ definitions: value: - content x-display-name: Variable name + rst_ttl: + type: integer + x-dependency: + type: + required: true + value: + - silent-drop + x-display-name: RST TTL sc_idx: type: string x-dependency: @@ -6568,9 +6596,6 @@ definitions: action: required: true value: - - track-sc0 - - track-sc1 - - track-sc2 - track-sc type: value: @@ -6584,9 +6609,6 @@ definitions: action: required: false value: - - track-sc0 - - track-sc1 - - track-sc2 - track-sc type: value: @@ -6601,9 +6623,6 @@ definitions: action: required: false value: - - track-sc0 - - track-sc1 - - track-sc2 - track-sc type: value: @@ -6828,6 +6847,14 @@ definitions: value: content x-display-name: Nice Value x-nullable: false + rst_ttl: + type: integer + x-dependency: + type: + required: true + value: + - silent-drop + x-display-name: RST TTL sc_expr: type: string x-dependency: @@ -7202,7 +7229,7 @@ definitions: description: HAProxy backend switching rule configuration (corresponds to use_backend directive) example: cond: if - cond_test: '{ req_ssl_sni -i www.example.com }' + cond_test: '{ req.ssl_sni -i www.example.com }' index: 0 name: test_backend properties: @@ -7245,7 +7272,7 @@ definitions: description: HAProxy server switching rule configuration (corresponds to use-server directive) example: cond: if - cond_test: '{ req_ssl_sni -i www.example.com }' + cond_test: '{ req.ssl_sni -i www.example.com }' target_server: www properties: cond: @@ -9121,19 +9148,34 @@ definitions: - conn_cnt - conn_cur - conn_rate + - glitch_cnt + - glitch_rate + - gpc + - gpc_rate - gpc0 - gpc0_rate - gpc1 - gpc1_rate - gpt0 + - gpt - http_req_cnt - http_req_rate - http_err_cnt - http_err_rate + - http_fail_cnt + - http_fail_rate - server_id - sess_cnt - sess_rate type: string + idx: + type: integer + x-dependency: + field: + value: + - gpc + - gpc_rate + - gpt period: type: integer x-dependency: @@ -9199,6 +9241,28 @@ definitions: exp: type: integer x-nullable: true + glitch_cnt: + type: integer + x-nullable: true + glitch_rate: + type: integer + x-nullable: true + gpc: + properties: + idx: + type: integer + value: + type: integer + x-nullable: true + type: object + gpc_rate: + properties: + idx: + type: integer + value: + type: integer + x-nullable: true + type: object gpc0: type: integer x-nullable: true @@ -9211,6 +9275,14 @@ definitions: gpc1_rate: type: integer x-nullable: true + gpt: + properties: + idx: + type: integer + value: + type: integer + x-nullable: true + type: object gpt0: type: integer x-nullable: true @@ -9220,6 +9292,12 @@ definitions: http_err_rate: type: integer x-nullable: true + http_fail_cnt: + type: integer + x-nullable: true + http_fail_rate: + type: integer + x-nullable: true http_req_cnt: type: integer x-nullable: true @@ -9695,7 +9773,7 @@ definitions: type: string interval: type: integer - x-nullable: false + x-nullable: true required: - enabled type: object @@ -21768,7 +21846,7 @@ paths: - $ref: '#/parameters/transaction_id' - $ref: '#/parameters/version' produces: - - application/json + - text/plain responses: "200": description: Operation successful @@ -21783,14 +21861,15 @@ paths: description: Configuration file version type: string schema: - properties: - data: - type: string - required: - - data - type: object + type: string default: - $ref: '#/responses/DefaultError' + description: General Error + headers: + Configuration-Version: + description: Configuration file version + type: string + schema: + type: string summary: Return HAProxy configuration tags: - Configuration @@ -21831,7 +21910,7 @@ paths: - $ref: '#/parameters/version' - $ref: '#/parameters/force_reload' produces: - - application/json + - text/plain responses: "201": description: New HAProxy configuration pushed @@ -21865,9 +21944,21 @@ paths: schema: type: string "400": - $ref: '#/responses/BadRequest' + description: Bad request + headers: + Configuration-Version: + description: Configuration file version + type: string + schema: + type: string default: - $ref: '#/responses/DefaultError' + description: General Error + headers: + Configuration-Version: + description: Configuration file version + type: string + schema: + type: string summary: Push new haproxy configuration tags: - Configuration @@ -23011,6 +23102,7 @@ paths: name: file_upload type: file x-mimetype: text/plain + - $ref: '#/parameters/skip_reload' - $ref: '#/parameters/force_reload' responses: "201": @@ -23151,7 +23243,7 @@ paths: in: formData name: file_upload type: file - x-mimetype: text/plain + x-mimetype: application/octet-stream responses: "201": description: General use file created with its contents @@ -23211,7 +23303,7 @@ paths: - Storage put: consumes: - - text/plain + - multipart/form-data description: Replaces the contents of a managed general use file on disk operationId: replaceStorageGeneralFile parameters: @@ -23220,11 +23312,11 @@ paths: name: name required: true type: string - - in: body - name: data - required: true - schema: - type: string + - description: General use file content + in: formData + name: file_upload + type: file + x-mimetype: application/octet-stream - $ref: '#/parameters/skip_reload' - $ref: '#/parameters/force_reload' produces: diff --git a/specification/models/configuration/backend.yaml b/specification/models/configuration/backend.yaml index 9a17eb28..77befefc 100644 --- a/specification/models/configuration/backend.yaml +++ b/specification/models/configuration/backend.yaml @@ -158,8 +158,7 @@ backend_base: pattern: '^[^\s]+$' x-dependency: cookie: - dynamic: - value: true + dynamic.value: true default_server: $ref: "#/definitions/default_server" check_timeout: diff --git a/specification/models/configuration/global.yaml b/specification/models/configuration/global.yaml index 5d4d2447..29c58492 100644 --- a/specification/models/configuration/global.yaml +++ b/specification/models/configuration/global.yaml @@ -118,6 +118,8 @@ global_base: type: integer x-nullable: true x-display-name: Stats maxconn + stats_file: + type: string thread_group_lines: type: array x-omitempty: true @@ -206,6 +208,10 @@ global_base: type: string h1_case_adjust_file: type: string + h1_accept_payload_with_any_method: + type: boolean + h1_do_not_close_on_insecure_transfer_encoding: + type: boolean http_err_codes: type: array x-display-name: Replace, reduce or extend the list of status codes that define an error diff --git a/specification/models/configuration/http/after_response.yaml b/specification/models/configuration/http/after_response.yaml index fd2ea187..1aff8dfc 100644 --- a/specification/models/configuration/http/after_response.yaml +++ b/specification/models/configuration/http/after_response.yaml @@ -33,7 +33,7 @@ http_after_response_rule: - unset-var x-nullable: false capture_sample: - pattern: '^[^\s]+$' + pattern: '^(?:[A-Za-z]+\("([A-Za-z\s]+)"\)|[A-Za-z]+)' x-display-name: Capture Sample type: string x-dependency: diff --git a/specification/models/configuration/http/request.yaml b/specification/models/configuration/http/request.yaml index b0a6554f..dc28a144 100644 --- a/specification/models/configuration/http/request.yaml +++ b/specification/models/configuration/http/request.yaml @@ -62,12 +62,10 @@ http_request_rule: - set-tos - set-uri - set-var + - set-var-fmt - silent-drop - strict-mode - tarpit - - track-sc0 - - track-sc1 - - track-sc2 - track-sc - unset-var - use-service @@ -76,7 +74,7 @@ http_request_rule: - set-bandwidth-limit x-nullable: false capture_sample: - pattern: '^[^\s]+$' + pattern: '^(?:[A-Za-z]+\("([A-Za-z\s]+)"\)|[A-Za-z]+)' x-display-name: Capture Sample type: string x-dependency: @@ -240,6 +238,13 @@ http_request_rule: type: value: set-log-level required: true + rst_ttl: + type: integer + x-display-name: RST TTL + x-dependency: + type: + value: [silent-drop] + required: true path_match: type: string pattern: '^[^\s]+$' diff --git a/specification/models/configuration/http/response.yaml b/specification/models/configuration/http/response.yaml index 80e931cc..69413a9a 100644 --- a/specification/models/configuration/http/response.yaml +++ b/specification/models/configuration/http/response.yaml @@ -44,9 +44,6 @@ http_response_rule: - set-var-fmt - silent-drop - strict-mode - - track-sc0 - - track-sc1 - - track-sc2 - track-sc - unset-var - wait-for-body @@ -154,6 +151,13 @@ http_response_rule: type: value: set-log-level required: true + rst_ttl: + type: integer + x-display-name: RST TTL + x-dependency: + type: + value: [silent-drop] + required: true var_name: type: string pattern: '^[^\s]+$' diff --git a/specification/models/configuration/misc.yaml b/specification/models/configuration/misc.yaml index dd95982a..3dea16cb 100644 --- a/specification/models/configuration/misc.yaml +++ b/specification/models/configuration/misc.yaml @@ -149,7 +149,7 @@ redispatch: enum: [enabled, disabled] interval: type: integer - x-nullable: false + x-nullable: true errorfile: type: object x-display-name: Error File diff --git a/specification/models/configuration/peers.yaml b/specification/models/configuration/peers.yaml index d45f585d..94922127 100644 --- a/specification/models/configuration/peers.yaml +++ b/specification/models/configuration/peers.yaml @@ -19,6 +19,9 @@ peer_section: servers: additionalProperties: $ref: "#/definitions/server" + tables: + additionalProperties: + $ref: "#/definitions/table" peer_section_base: title: Peer Section Base description: HAProxy peer_section configuration diff --git a/specification/models/configuration/server.yaml b/specification/models/configuration/server.yaml index 98cbacee..8d043f61 100644 --- a/specification/models/configuration/server.yaml +++ b/specification/models/configuration/server.yaml @@ -25,6 +25,9 @@ server: id: type: integer x-nullable: true + metadata: + additionalProperties: + type: object additionalProperties: false example: name: www diff --git a/specification/models/configuration/switching.yaml b/specification/models/configuration/switching.yaml index 45349251..9b90c05f 100644 --- a/specification/models/configuration/switching.yaml +++ b/specification/models/configuration/switching.yaml @@ -33,7 +33,7 @@ backend_switching_rule: index: 0 name: test_backend cond: if - cond_test: "{ req_ssl_sni -i www.example.com }" + cond_test: "{ req.ssl_sni -i www.example.com }" server_switching_rule: title: Server Switching Rule description: HAProxy server switching rule configuration (corresponds to use-server directive) @@ -66,4 +66,4 @@ server_switching_rule: example: target_server: www cond: if - cond_test: "{ req_ssl_sni -i www.example.com }" + cond_test: "{ req.ssl_sni -i www.example.com }" diff --git a/specification/models/configuration/tcp/request.yaml b/specification/models/configuration/tcp/request.yaml index 02efcc10..b2424106 100644 --- a/specification/models/configuration/tcp/request.yaml +++ b/specification/models/configuration/tcp/request.yaml @@ -47,9 +47,6 @@ tcp_request_rule: - set-var-fmt - silent-drop - switch-mode - - track-sc0 - - track-sc1 - - track-sc2 - track-sc - unset-var - use-service @@ -59,7 +56,7 @@ tcp_request_rule: value: [connection, content, session] required: true capture_sample: - pattern: '^[^\s]+$' + pattern: '^(?:[A-Za-z]+\("([A-Za-z\s]+)"\)|[A-Za-z]+)' x-display-name: Capture Sample type: string x-dependency: @@ -210,7 +207,7 @@ tcp_request_rule: x-display-name: Sample expression rule x-dependency: action: - value: [track-sc0, track-sc1, track-sc2, track-sc] + value: [track-sc] required: true type: value: [session, connection, content] @@ -219,7 +216,7 @@ tcp_request_rule: x-display-name: Optional table name x-dependency: action: - value: [track-sc0, track-sc1, track-sc2, track-sc] + value: [track-sc] required: false type: value: [session, connection, content] @@ -229,7 +226,7 @@ tcp_request_rule: x-nullable: true x-dependency: action: - value: [track-sc0, track-sc1, track-sc2, track-sc] + value: [track-sc] required: false type: value: [session, connection, content] @@ -332,6 +329,13 @@ tcp_request_rule: required: true type: value: content + rst_ttl: + type: integer + x-display-name: RST TTL + x-dependency: + type: + value: [silent-drop] + required: true mark_value: type: string pattern: "^(0x[0-9A-Fa-f]+|[0-9]+)$" diff --git a/specification/models/configuration/tcp/response.yaml b/specification/models/configuration/tcp/response.yaml index 8fdc7c7c..bd530f94 100644 --- a/specification/models/configuration/tcp/response.yaml +++ b/specification/models/configuration/tcp/response.yaml @@ -172,6 +172,13 @@ tcp_response_rule: required: true type: value: content + rst_ttl: + type: integer + x-display-name: RST TTL + x-dependency: + type: + value: [silent-drop] + required: true mark_value: type: string pattern: "^(0x[0-9A-Fa-f]+|[0-9]+)$" diff --git a/specification/models/configuration/userlist.yaml b/specification/models/configuration/userlist.yaml index 3439d7b1..608def07 100644 --- a/specification/models/configuration/userlist.yaml +++ b/specification/models/configuration/userlist.yaml @@ -41,6 +41,7 @@ group: user: title: User description: HAProxy userlist user + type: object required: - username - secure_password diff --git a/specification/models/runtime/table.yaml b/specification/models/runtime/table.yaml index 1608276b..67de4a46 100644 --- a/specification/models/runtime/table.yaml +++ b/specification/models/runtime/table.yaml @@ -32,15 +32,22 @@ table: - conn_cnt - conn_cur - conn_rate + - glitch_cnt + - glitch_rate + - gpc + - gpc_rate - gpc0 - gpc0_rate - gpc1 - gpc1_rate - gpt0 + - gpt - http_req_cnt - http_req_rate - http_err_cnt - http_err_rate + - http_fail_cnt + - http_fail_rate - server_id - sess_cnt - sess_rate @@ -52,3 +59,8 @@ table: x-dependency: type: value: rate + idx: + type: integer + x-dependency: + field: + value: [gpc, gpc_rate, gpt] diff --git a/specification/models/runtime/table_entry.yaml b/specification/models/runtime/table_entry.yaml index dd77e68d..89ab5355 100644 --- a/specification/models/runtime/table_entry.yaml +++ b/specification/models/runtime/table_entry.yaml @@ -11,6 +11,28 @@ table_entry: server_id: type: integer x-nullable: true + glitch_cnt: + type: integer + x-nullable: true + glitch_rate: + type: integer + x-nullable: true + gpc: + type: object + properties: + value: + type: integer + x-nullable: true + idx: + type: integer + gpc_rate: + type: object + properties: + value: + type: integer + x-nullable: true + idx: + type: integer gpc0: type: integer x-nullable: true @@ -23,6 +45,14 @@ table_entry: gpc1_rate: type: integer x-nullable: true + gpt: + type: object + properties: + value: + type: integer + x-nullable: true + idx: + type: integer gpt0: type: integer x-nullable: true @@ -41,6 +71,12 @@ table_entry: sess_rate: type: integer x-nullable: true + http_fail_cnt: + type: integer + x-nullable: true + http_fail_rate: + type: integer + x-nullable: true http_req_cnt: type: integer x-nullable: true diff --git a/specification/paths/configuration/raw.yaml b/specification/paths/configuration/raw.yaml index 08886719..3db4121c 100644 --- a/specification/paths/configuration/raw.yaml +++ b/specification/paths/configuration/raw.yaml @@ -8,7 +8,7 @@ configuration: - $ref: "#/parameters/transaction_id" - $ref: "#/parameters/version" produces: - - application/json + - text/plain tags: - Configuration responses: @@ -25,20 +25,21 @@ configuration: description: Configuration file md5 checksum type: string schema: - type: object - required: - - data - properties: - data: - type: string + type: string 'default': - $ref: '#/responses/DefaultError' + description: General Error + headers: + Configuration-Version: + description: Configuration file version + type: string + schema: + type: string post: summary: Push new haproxy configuration description: Push a new haproxy configuration file in plain text operationId: postHAProxyConfiguration produces: - - application/json + - text/plain consumes: - text/plain parameters: @@ -106,8 +107,19 @@ configuration: type: string schema: type: string - '400': - $ref: '#/responses/BadRequest' + description: Bad request + headers: + Configuration-Version: + description: Configuration file version + type: string + schema: + type: string 'default': - $ref: '#/responses/DefaultError' + description: General Error + headers: + Configuration-Version: + description: Configuration file version + type: string + schema: + type: string diff --git a/specification/paths/storage/general_files.yaml b/specification/paths/storage/general_files.yaml index 1b1f0367..237ffe67 100644 --- a/specification/paths/storage/general_files.yaml +++ b/specification/paths/storage/general_files.yaml @@ -26,7 +26,7 @@ general_files: name: file_upload type: file description: General use file content - x-mimetype: text/plain + x-mimetype: application/octet-stream tags: - Storage responses: @@ -90,7 +90,7 @@ general_files_one: produces: - application/json consumes: - - text/plain + - multipart/form-data tags: - Storage parameters: @@ -99,11 +99,11 @@ general_files_one: description: General use file storage_name required: true type: string - - name: data - in: body - required: true - schema: - type: string + - in: formData + name: file_upload + type: file + description: General use file content + x-mimetype: application/octet-stream - $ref: "#/parameters/skip_reload" - $ref: "#/parameters/force_reload" responses: diff --git a/specification/paths/storage/ssl_certificates.yaml b/specification/paths/storage/ssl_certificates.yaml index 307c4393..f5f3312c 100644 --- a/specification/paths/storage/ssl_certificates.yaml +++ b/specification/paths/storage/ssl_certificates.yaml @@ -27,6 +27,7 @@ ssl_certificates: type: file description: The SSL certificate to upload x-mimetype: text/plain + - $ref: "#/parameters/skip_reload" - $ref: "#/parameters/force_reload" tags: - Storage diff --git a/spoe/agent.go b/spoe/agent.go index 6fc3daf3..5500a123 100644 --- a/spoe/agent.go +++ b/spoe/agent.go @@ -16,6 +16,7 @@ package spoe import ( + "errors" "fmt" "github.com/go-openapi/strfmt" @@ -350,7 +351,7 @@ func (c *SingleSpoe) EditAgent(scope string, data *models.SpoeAgent, transaction func (c *SingleSpoe) createEditAgent(scope string, data *models.SpoeAgent, t string, transactionID string, p *spoe.Parser) error { //nolint:gocognit,gocyclo,cyclop,maintidx if data == nil { - return fmt.Errorf("spoe agent not initialized") + return errors.New("spoe agent not initialized") } name := *data.Name @@ -519,7 +520,7 @@ func (c *SingleSpoe) createEditAgent(scope string, data *models.SpoeAgent, t str } if data.HelloTimeout > 0 { - d := &types.StringC{Value: misc.SerializeTime(data.HelloTimeout, c.Transaction.ConfigurationOptions.PreferredTimeSuffix)} + d := &types.StringC{Value: misc.SerializeTime(data.HelloTimeout, c.Transaction.PreferredTimeSuffix)} if err := p.Set(scope, parser.SPOEAgent, name, "timeout hello", d); err != nil { return c.Transaction.HandleError(d.Value, "", "", t, transactionID == "", err) } @@ -528,7 +529,7 @@ func (c *SingleSpoe) createEditAgent(scope string, data *models.SpoeAgent, t str } if data.IdleTimeout > 0 { - d := &types.StringC{Value: misc.SerializeTime(data.IdleTimeout, c.Transaction.ConfigurationOptions.PreferredTimeSuffix)} + d := &types.StringC{Value: misc.SerializeTime(data.IdleTimeout, c.Transaction.PreferredTimeSuffix)} if err := p.Set(scope, parser.SPOEAgent, name, "timeout idle", d); err != nil { return c.Transaction.HandleError(d.Value, "", "", t, transactionID == "", err) } @@ -537,7 +538,7 @@ func (c *SingleSpoe) createEditAgent(scope string, data *models.SpoeAgent, t str } if data.ProcessingTimeout > 0 { - d := &types.StringC{Value: misc.SerializeTime(data.ProcessingTimeout, c.Transaction.ConfigurationOptions.PreferredTimeSuffix)} + d := &types.StringC{Value: misc.SerializeTime(data.ProcessingTimeout, c.Transaction.PreferredTimeSuffix)} if err := p.Set(scope, parser.SPOEAgent, name, "timeout processing", d); err != nil { return c.Transaction.HandleError(d.Value, "", "", t, transactionID == "", err) } diff --git a/spoe/group.go b/spoe/group.go index bfab356a..5d7142b3 100644 --- a/spoe/group.go +++ b/spoe/group.go @@ -16,6 +16,7 @@ package spoe import ( + "errors" "fmt" "github.com/go-openapi/strfmt" @@ -153,7 +154,7 @@ func (c *SingleSpoe) EditGroup(scope string, data *models.SpoeGroup, name, trans func (c *SingleSpoe) createEditGroup(scope string, data *models.SpoeGroup, t string, transactionID string, p *spoe.Parser) error { if data == nil { - return fmt.Errorf("spoe group not initialized") + return errors.New("spoe group not initialized") } name := *data.Name diff --git a/spoe/message.go b/spoe/message.go index c8a9871f..0d539acc 100644 --- a/spoe/message.go +++ b/spoe/message.go @@ -16,6 +16,7 @@ package spoe import ( + "errors" "fmt" "github.com/go-openapi/strfmt" @@ -182,7 +183,7 @@ func (c *SingleSpoe) EditMessage(scope string, data *models.SpoeMessage, name, t func (c *SingleSpoe) createEditMessage(scope string, data *models.SpoeMessage, t string, transactionID string, p *spoe.Parser) error { if data == nil { - return fmt.Errorf("spoe message not initialized") + return errors.New("spoe message not initialized") } name := *data.Name diff --git a/spoe/spoe_single_client.go b/spoe/spoe_single_client.go index a9818d36..5b89ca48 100644 --- a/spoe/spoe_single_client.go +++ b/spoe/spoe_single_client.go @@ -16,6 +16,7 @@ package spoe import ( + "errors" "fmt" "sync" @@ -56,7 +57,7 @@ type Params struct { // newSingleSpoe returns Spoe with default options func newSingleSpoe(params Params) (*SingleSpoe, error) { if params.ConfigurationFile == "" { - return nil, fmt.Errorf("configuration file missing") + return nil, errors.New("configuration file missing") } ss := &SingleSpoe{} ss.Transaction = &conf.Transaction{} @@ -90,7 +91,7 @@ func newSingleSpoe(params Params) (*SingleSpoe, error) { ss.Parser = &spoe.Parser{} if err := ss.Parser.LoadData(params.ConfigurationFile); err != nil { - return nil, conf.NewConfError(conf.ErrCannotReadConfFile, fmt.Sprintf("cannot read %s", ss.Transaction.ConfigurationFile)) + return nil, conf.NewConfError(conf.ErrCannotReadConfFile, "cannot read "+ss.Transaction.ConfigurationFile) } return ss, nil @@ -153,12 +154,13 @@ func (c *SingleSpoe) AddParser(transactionID string) error { c.mu.Lock() _, ok := c.parsers[transactionID] c.mu.Unlock() + if ok { return conf.NewConfError(conf.ErrTransactionAlreadyExists, fmt.Sprintf("transaction %s already exists", transactionID)) } p := &spoe.Parser{} - tFile := "" + var tFile string var err error if c.Transaction.PersistentTransactions { tFile, err = c.Transaction.GetTransactionFile(transactionID) @@ -169,7 +171,7 @@ func (c *SingleSpoe) AddParser(transactionID string) error { tFile = c.Transaction.ConfigurationFile } if err := p.LoadData(tFile); err != nil { - return conf.NewConfError(conf.ErrCannotReadConfFile, fmt.Sprintf("cannot read %s", tFile)) + return conf.NewConfError(conf.ErrCannotReadConfFile, "cannot read "+tFile) } c.mu.Lock() c.parsers[transactionID] = p @@ -228,7 +230,7 @@ func (c *SingleSpoe) InitTransactionParsers() error { return err } if err := p.LoadData(tFile); err != nil { - return conf.NewConfError(conf.ErrCannotReadConfFile, fmt.Sprintf("cannot read %s", tFile)) + return conf.NewConfError(conf.ErrCannotReadConfFile, "cannot read "+tFile) } } return nil @@ -240,7 +242,7 @@ func (c *SingleSpoe) IncrementVersion() error { ver.Value++ if err := c.Parser.Save(c.Transaction.ConfigurationFile); err != nil { - return conf.NewConfError(conf.ErrCannotSetVersion, fmt.Sprintf("cannot set version: %s", err.Error())) + return conf.NewConfError(conf.ErrCannotSetVersion, "cannot set version: "+err.Error()) } return nil } @@ -269,7 +271,7 @@ func (c *SingleSpoe) incrementTransactionVersion(p *spoe.Parser) error { func (c *SingleSpoe) LoadData(filename string) error { err := c.Parser.LoadData(filename) if err != nil { - return conf.NewConfError(conf.ErrCannotReadConfFile, fmt.Sprintf("cannot read %s", filename)) + return conf.NewConfError(conf.ErrCannotReadConfFile, "cannot read version: "+err.Error()) } return nil } @@ -288,7 +290,7 @@ func (c *SingleSpoe) Save(transactionFile, transactionID string) error { func (c *SingleSpoe) GetFailedParserTransactionVersion(transactionID string) (int64, error) { p := &spoe.Parser{} if err := p.LoadData(transactionID); err != nil { - return 0, conf.NewConfError(conf.ErrCannotReadConfFile, fmt.Sprintf("cannot read %s", transactionID)) + return 0, conf.NewConfError(conf.ErrCannotReadConfFile, "cannot read version: "+err.Error()) } data, _ := p.Get("", parser.Comments, parser.CommentsSectionName, "# _version", false) @@ -308,15 +310,15 @@ func (c *SingleSpoe) GetVersion(transactionID string) (int64, error) { func (c *SingleSpoe) getVersion(transactionID string) (int64, error) { p, err := c.GetParser(transactionID) if err != nil { - return 0, conf.NewConfError(conf.ErrCannotReadVersion, fmt.Sprintf("cannot read version: %s", err.Error())) + return 0, conf.NewConfError(conf.ErrCannotReadVersion, "cannot read version: "+err.Error()) } data, err := p.Get("", parser.Comments, parser.CommentsSectionName, "# _version", true) if err != nil { - return 0, conf.NewConfError(conf.ErrCannotReadVersion, fmt.Sprintf("cannot read version: %s", err.Error())) + return 0, conf.NewConfError(conf.ErrCannotReadVersion, "cannot read version: "+err.Error()) } ver, ok := data.(*types.ConfigVersion) if !ok { - return 0, conf.NewConfError(conf.ErrCannotReadVersion, fmt.Sprintf("cannot read version: %s", err.Error())) + return 0, conf.NewConfError(conf.ErrCannotReadVersion, "cannot read version: "+err.Error()) } return ver.Value, nil } diff --git a/storage/cert-info.go b/storage/cert-info.go index 867eb974..871f10b0 100644 --- a/storage/cert-info.go +++ b/storage/cert-info.go @@ -20,6 +20,7 @@ import ( "crypto/sha256" "crypto/x509" "encoding/pem" + "errors" "fmt" "strings" "time" @@ -119,7 +120,9 @@ func (ci *certsInfo) parseCertificate(der []byte) error { ci.Issuers[crt.Issuer.CommonName] = struct{}{} if !crt.IsCA { - ci.DNS[crt.Subject.CommonName] = struct{}{} + if crt.Subject.CommonName != "" { + ci.DNS[crt.Subject.CommonName] = struct{}{} + } // Alternate Subject Names for _, name := range crt.DNSNames { ci.DNS[name] = struct{}{} @@ -145,8 +148,12 @@ func formatFingerprint(fingerprint []byte) string { // findLeafCertificate returns the first leaf certificate in the chain. func findLeafCertificate(certs []*x509.Certificate) (*x509.Certificate, error) { if len(certs) == 0 { - return nil, fmt.Errorf("empty certificate chain") + return nil, errors.New("empty certificate chain") + } + if len(certs) == 1 { + return certs[0], nil } + // Create a map to check if a certificate is someone else's issuer isIssuer := make(map[string]bool) for _, cert := range certs { @@ -155,12 +162,12 @@ func findLeafCertificate(certs []*x509.Certificate) (*x509.Certificate, error) { // Find the starting certificate (a certificate whose issuer is not in the list) for _, cert := range certs { - if !cert.IsCA && cert.Subject.CommonName != "" && !isIssuer[cert.Subject.String()] { + if !cert.IsCA && (cert.Subject.CommonName != "" || len(cert.DNSNames) != 0 || len(cert.IPAddresses) != 0) && !isIssuer[cert.Subject.String()] { return cert, nil } } - return nil, fmt.Errorf("no leaf certificate found") + return nil, errors.New("no leaf certificate found") } // Transform a dirty *certsInfo into a clean *CertificatesInfo for the API. diff --git a/storage/storage.go b/storage/storage.go index 445345d0..aa34940b 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -21,6 +21,7 @@ import ( "crypto/rsa" "crypto/x509" "encoding/pem" + "errors" "fmt" "io" "io/fs" @@ -187,7 +188,7 @@ func (s *storage) Create(name string, readCloser io.ReadCloser) (string, int64, name = misc.SanitizeFilename(name) if s.fileType == MapsType { if !strings.HasSuffix(name, ".map") { - name = fmt.Sprintf("%s.map", name) + name += ".map" } } f := filepath.Join(s.dirname, name) @@ -252,7 +253,7 @@ func readFile(name string) (string, error) { func getFile(dirname, name string) (string, int64, error) { name = misc.SanitizeFilename(name) if name == "" { - return "", -1, fmt.Errorf("no file name") + return "", -1, errors.New("no file name") } f := filepath.Join(dirname, name) finfo, err := os.Stat(f) @@ -288,6 +289,7 @@ func readDir(dirname string) ([]os.FileInfo, error) { } infos = append(infos, info) } + return infos, nil } @@ -295,7 +297,7 @@ func (s storage) validatePEM(raw []byte) error { crtPool := x509.NewCertPool() ok := crtPool.AppendCertsFromPEM(raw) if !ok { - return fmt.Errorf("failed to parse certificate") + return errors.New("failed to parse certificate") } // HAProxy requires private and public key in same pem file hasCertificate := false @@ -315,9 +317,10 @@ func (s storage) validatePEM(raw []byte) error { } raw = rest } - if !(hasCertificate && hasPrivateKey) { - return fmt.Errorf("file should contain both certificate and private key") + if !hasCertificate || !hasPrivateKey { + return errors.New("file should contain both certificate and private key") } + return nil } @@ -330,11 +333,12 @@ func parsePrivateKey(der []byte) (crypto.PrivateKey, error) { case *rsa.PrivateKey, *ecdsa.PrivateKey: return key, nil default: - return nil, fmt.Errorf("found unknown private key type in PKCS#8 wrapping") + return nil, errors.New("found unknown private key type in PKCS#8 wrapping") } } if key, err := x509.ParseECPrivateKey(der); err == nil { return key, nil } - return nil, fmt.Errorf("failed to parse private key") + + return nil, errors.New("failed to parse private key") } diff --git a/storage/storage_test.go b/storage/storage_test.go index ed5b7998..68d0881f 100644 --- a/storage/storage_test.go +++ b/storage/storage_test.go @@ -505,6 +505,10 @@ func Test_storage_getCertificatesInfo(t *testing.T) { filename: "OK-int1_key_crt_int2.pem", dirname: "valid", }, + { + filename: "selfsigned1.pem", + dirname: "valid", + }, } for _, tt := range tests { t.Run(tt.filename, func(t *testing.T) { diff --git a/storage/test-certs/valid/selfsigned1.pem b/storage/test-certs/valid/selfsigned1.pem new file mode 100644 index 00000000..95455ae6 --- /dev/null +++ b/storage/test-certs/valid/selfsigned1.pem @@ -0,0 +1,86 @@ +-----BEGIN PRIVATE KEY----- +MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQCo55THv+XIARRP +Avj1tO3I6gI96/wCx4uOXwZlmQ+wG42M6a2IF4U1eXFfyvIoqqwGoEeFhP71+3tA +bJ5We18oRkEG6CcR35J2UiRxgt3zkvnGBxkoMpWpGP0L/w+WZkw86CAbR9eRf/zB +LOUfKqAXzatXfqdvlfQxF1OjeU6CemcBpPNxHkML73FBRgVezkhj2q0Rdo5sn9TF +b7/nO6biXrV1s4Rkv5Jf70zCKQKIHGNttM0RR13AcDEuY2pqawxVuDTECqlGNMKg +XOc2XKu9OQ1aLytyCKNxwPGC+Ugf9Tu9TD/U0eviUtMCDqn/c4wTa7vVyR7wA4+R +NFPHFwTTxCVkTuAiaU2zaTLGM/sNt8oFu/FXSeTVnnivAwDRtBIRwolw1ZQezDVb +uYKPfSScJ3LvkuBFPfR0Sbhvp5eJ0Ls5yQvXcYurs1BK1SVrS+UFadn5zOwlOOYW +6Q6vw4uVSD5m71eSBEkSy74l1kEiIPzkST6KPlEOOj3g/00YCaRNld/O84hL1O7q +8gS7yyd5viveGd0bDEMjKLnXgEJO6dsCx+mRq1oSNqNvdVFJLMAFHoHRTd/c10uE +Pse2aas1prAy27ocpBpKFo1r8/xivf8iTbl4ymlnWTM5T0mxW0eOqESQrhEO8Slf +nIAxePOOJBbjKDucMLzke4LsHv+FPQIDAQABAoICABFvsrq6MzDl96A+eM/4qRF0 +It4clev9iIkegy0K04VFGuRAnVLuxqgiDNOsQjpzgAXBFxEQDTf8iZk5fVEFNGoW +cpERdzMPpvGDAlMbhOkns5Q/WFf/fNazhy/tWUEX92fUOLhIPtc85K1WgqKohlVe +vIDwSL2qt8Y3l8FI/RNYKnkPe7giPR6mzcTEwzopxmxUf0hNul85UsA9DI0E6fH1 +f/sSGKlD44r2y7BBhorhj1wcbY0KloGOs20MA0jQGzpgJUZVqWrfeHYQkSfaAjqr +AJdeRjhj7ueH2QbB0DHIYa3liLNiJl07WqAcPm1qErxQg1gLBqAVZgVB5yIm3K8K +x/pDmXuhfstSlxU3ofBqbgp1tyE1zgOrlGToLr5PjpoY1q+H672Lq47/aL2ZNmKt +QuEiNDJs4eQj5oOERZG2ySPOnzK9B01IHYKYuh111noFl1j63JN958X5tqQYH4wW +f6b5oF/4M5aM/TFBxcBrnCWOFBLZln4BJhdouH6w+HqaOMIMFTKVLJGzJ7EOMoKP +XL61Pz/SrOa+UVn+ufTJ9/YICQeRyEjV2zf1DVYQhIqrgj+DQqMCMAM/USJp0Up7 +RF/x8Y14HqvlqtXdnlY5aVt/fFxkAnQkUDCYHcGxk9rl9nD4w80MeRI0smjLyrft +XdZ216HKVcYeCG3e0+zhAoIBAQDe2FIIzUTOs4WJlXlWuKQ2K83knx1UKhQp7qbr +hWCGD2YdHOaVcNOCYSbIaJTplKvca+1i42wT0/EeGo94nlM1QGbdSoyRFXpaFcXa +XXrN32xPXljRcvzaFmzg7yfhL382d40mcuyaz6cCvczQZJm/MOoYxV5rANBFZo5W +fhhroXNMUQ3QxfFzb/vwsakieB2JEro4p2+rxdnH38+h1r6F9XoSrWoVaGedMJhm +TrQwbRk8iapxfaCTaKHB2R4GuWkU9M8NnFSOyvrC0pWLy7zYV8o/jFTf54y1lhRP +/Memo788/Z+pt62zGUxmCn/ThiErWsGpkt6OoSIkZlmo9nVxAoIBAQDCCMoEZQsW +VrgVvyxov0Kc3SE0IxAX7XEoQNUeoMob6GKtBNjba0Pk7V0IklNZO+b/f5/cDFan +m7JOiUte5LSA2LykirIwDfjqLcwqL3DmnIFlDLhNWtXTQDO1pgl0OU3cglzxdld6 +yJIc+dSDDTSS4/Es1f45KcZvvRkms+Ph7P9043wavzmd+c0+iIM3IKjRP5T7HLFq +QyZoIdGHbhlBwZ/w9irY1Hzw997JVlpqlTVTi9sMz+H85kE+UBkFqd/r9vDDLlIO +iALSmGca7xkNANFatgvuVbpfCXZW8Pijr6eeiUHB+BpNg/gg9nq3GQR0/P5MMnhG +iRjKdk+gqzaNAoIBAE2sQrO0sIYHhsUU5401oG8NR5+nYjai0BJpj57KB4HSvjnp +h+mQwPhR2o3B/h2IZ3rV15E/Sb2DgyiGA3n8XW5TO0doo6QyQ0pBCox5RsOZW4wy +i2y90qpFZL/mPBU+U+3tL7K2Hgg71q+a7le4qOo+J2po6OcNCosWGwjEvMhPJvvz +yIf7ZpRg9QTJN/W+vjS35Va37bGGrckAFsQHMLNKg7kc3rwFfxAIDyahyiaS8Ffs +eA9ExYJ71t3VSqT3XUwjpEPPOJ3o3AyqD9wBMJqLxv/tbuv4LlBgtkXHCuPncVHV +6R/j2NRzPfDXOgTFXKxa3uO3QIGgYmEjl57QANECggEBAJLVyeMXgBNwnrA+UuIV +0tgYc3ccDaK92gMnROB/t1L1Qi9C2sT5YJDOm7fP2+lMbpvtPdFtOOpv5biPJ41x +L7PN0LwIBZ5eBH9bFwTZj+vEhhstTA+l7OiHzlnpg4ADmYuEz8ce0kaloATzfsGJ +7b43ZxyR+GfT2EpY5L6oJYykKBGR0SoAih6lmo93CS1ftsFbB2gcp5oNpPPqm8CM +LerYFyxnbbdW3hIQ0fS1N4kuzwMhdCw26QLUUI1SWg0yJ7VO05Yw6IH8pX4vPN9i +DygK9WNbHp5HG9mttHNIujBMzmEn565dDbKZat2vCOCkuv25MswA6YofV7ZnYAzr +ZEUCggEAEASYgAZW7FXo13wO/B3GPn4VSo9AwbbFXUYxV2MguID8HKI92uc5xKpF +o+3f7NJiLR7xp6kt8JMzcErFI27tkIE5qerj4j/YOwiAtmSdsYDGZgCORKWGvk3Q +Uvmic0ChydNaTRo+Nb46NAGx/28JZ1X/OHsnw2mazsjCbkTGavsHyuAHSZ8FjaO/ +zzS+X5FG/5xWmd6bBNjqIsy5dzrDY7dtgDbylwscO0ZjZ2jPHUZqcN/0wCecwmcI +s5ylOwxZTUJvoaUfxJJChhx3Aa09Og4VB6Tu5xuwPSCQSCs7BYYVsZOOXyLAxUJQ +Z9dGRClyR8L6zGyIx9IfiHIVbaY2yg== +-----END PRIVATE KEY----- +-----BEGIN CERTIFICATE----- +MIIF2zCCA8OgAwIBAgIURRBDOMWHU/lCFak3Tp/efWcNBDQwDQYJKoZIhvcNAQEL +BQAwfTELMAkGA1UEBhMCWFgxEjAQBgNVBAgMCVN0YXRlTmFtZTERMA8GA1UEBwwI +Q2l0eU5hbWUxFDASBgNVBAoMC0NvbXBhbnlOYW1lMRswGQYDVQQLDBJDb21wYW55 +U2VjdGlvbk5hbWUxFDASBgNVBAMMC2hhcHJveHkub3JnMB4XDTI1MDYyNjA5MzMx +MVoXDTQ0MDgyNTA5MzMxMVowfTELMAkGA1UEBhMCWFgxEjAQBgNVBAgMCVN0YXRl +TmFtZTERMA8GA1UEBwwIQ2l0eU5hbWUxFDASBgNVBAoMC0NvbXBhbnlOYW1lMRsw +GQYDVQQLDBJDb21wYW55U2VjdGlvbk5hbWUxFDASBgNVBAMMC2hhcHJveHkub3Jn +MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqOeUx7/lyAEUTwL49bTt +yOoCPev8AseLjl8GZZkPsBuNjOmtiBeFNXlxX8ryKKqsBqBHhYT+9ft7QGyeVntf +KEZBBugnEd+SdlIkcYLd85L5xgcZKDKVqRj9C/8PlmZMPOggG0fXkX/8wSzlHyqg +F82rV36nb5X0MRdTo3lOgnpnAaTzcR5DC+9xQUYFXs5IY9qtEXaObJ/UxW+/5zum +4l61dbOEZL+SX+9MwikCiBxjbbTNEUddwHAxLmNqamsMVbg0xAqpRjTCoFznNlyr +vTkNWi8rcgijccDxgvlIH/U7vUw/1NHr4lLTAg6p/3OME2u71cke8AOPkTRTxxcE +08QlZE7gImlNs2kyxjP7DbfKBbvxV0nk1Z54rwMA0bQSEcKJcNWUHsw1W7mCj30k +nCdy75LgRT30dEm4b6eXidC7OckL13GLq7NQStUla0vlBWnZ+czsJTjmFukOr8OL +lUg+Zu9XkgRJEsu+JdZBIiD85Ek+ij5RDjo94P9NGAmkTZXfzvOIS9Tu6vIEu8sn +eb4r3hndGwxDIyi514BCTunbAsfpkataEjajb3VRSSzABR6B0U3f3NdLhD7Htmmr +NaawMtu6HKQaShaNa/P8Yr3/Ik25eMppZ1kzOU9JsVtHjqhEkK4RDvEpX5yAMXjz +jiQW4yg7nDC85HuC7B7/hT0CAwEAAaNTMFEwHQYDVR0OBBYEFM/sK4V6m+TDCTtj +vESjXas889RLMB8GA1UdIwQYMBaAFM/sK4V6m+TDCTtjvESjXas889RLMA8GA1Ud +EwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggIBAKHnZkv9bd8O9+90ymOA4vLQ +iuPrcOgMXD9ibC7BgempOCLzFbKL3FMGulJZJy4JLzKhaHVICSITswN81Rsd8NIM +hpGg0Ih/jg25rzNPLKpDe7MSTS73ufTyRtseusQrvIYihAsZrPGl2XR1InuooQ08 +zXqO9mFQbfs7mgFWYbPxqgk/2hm6GG/a0M9asC2oH45mWygOELS05EMh+at97EUD +s7KtM/uJ7+09TjcUD0zcf0c777YL5B050CbedZciObH03AU2P7Qc5LEZck8TEMrw +0i655wWMTuI7wGbVDz1qdBUzc/Q75WKQiRPLVyLixsJmWA+cpZYbWCV0l2hmp2wJ +7l8dV5UwrEwHWwGQbrOzuSjYyzfNXRbNIbnL1UySCMtHFBtOy/RHb2VbAiEZnrMe +xmmNQx+3t7a0OW97iPKRh6K95KdsLaUlyoBCY7Ku3pXd9osj1JjsrDfglWx2PDcc +ENUrBSbJHdf+cK9USNhl8L0FH6U3OSb+iSshznCRfH9i5siKwns0n9nePM6WQXQz +gR0E1E1yeNd/E/lET08RnTwWtlPjZyo7GAkjgOOEAnk1QZqM3/L34ZAXS0+/am+x +lCz4wr3hRdeG/4dfZluPud8fi6Y2ardGUwhlBhlNZKt1d01p8OrAhuuvVRulUKMi +fUlFmL0ypMsujAx1WJxz +-----END CERTIFICATE----- diff --git a/test/backend_test.go b/test/backend_test.go index 24a00f4c..22bdd442 100644 --- a/test/backend_test.go +++ b/test/backend_test.go @@ -217,6 +217,10 @@ func TestCreateEditDeleteBackend(t *testing.T) { {Name: "test_errors_all"}, }, Disabled: true, + Redispatch: &models.Redispatch{ + Enabled: misc.StringP("enabled"), + Interval: misc.Int64P(0), + }, }, } diff --git a/test/configuration_test.go b/test/configuration_test.go index d39c2065..becdf104 100644 --- a/test/configuration_test.go +++ b/test/configuration_test.go @@ -162,6 +162,8 @@ global insecure-setuid-wanted issuers-chain-path issuers-chain-path h2-workaround-bogus-websocket-clients + h1-accept-payload-with-any-method + h1-do-not-close-on-insecure-transfer-encoding lua-load-per-thread file.ext mworker-max-reloads 5 numa-cpu-mapping @@ -184,6 +186,7 @@ global ssl-default-server-options ssl-min-ver TLSv1.1 no-tls-tickets thread-groups 1 thread-group first 1-16 + stats-file /var/haproxy/my-stats stats maxconn 20 ssl-load-extra-files bundle deviceatlas-json-file atlas.json @@ -418,6 +421,7 @@ frontend test http-request allow if src 192.168.0.0/16 http-request set-header X-SSL %[ssl_fc] http-request set-var(req.my_var) req.fhdr(user-agent),lower + http-request set-var-fmt(txn.from) %[src]:%[src_port] http-request set-map(map.lst) %[src] %[req.hdr(X-Value)] http-request del-map(map.lst) %[src] if FALSE http-request del-acl(map.lst) %[src] if FALSE @@ -723,8 +727,8 @@ backend test external-check command /bin/false use-server webserv if TRUE use-server webserv2 unless TRUE - server webserv 192.168.1.1:9200 maxconn 1000 ssl weight 10 inter 2s cookie BLAH slowstart 6000 proxy-v2-options authority,crc32c ws h1 pool-low-conn 128 id 1234 pool-purge-delay 10s tcp-ut 2s curves secp384r1 client-sigalgs ECDSA+SHA256:RSA+SHA256 sigalgs ECDSA+SHA256 log-bufsize 10 set-proxy-v2-tlv-fmt(0x20) %[fc_pp_tlv(0x20)] - server webserv2 192.168.1.1:9300 maxconn 1000 ssl weight 10 inter 2s cookie BLAH slowstart 6000 proxy-v2-options authority,crc32c ws h1 pool-low-conn 128 hash-key akey pool-conn-name apoolconnname + server webserv 192.168.1.1:9200 maxconn 1000 ssl weight 10 inter 2s cookie BLAH slowstart 6000 proxy-v2-options authority,crc32c ws h1 pool-low-conn 128 id 1234 pool-purge-delay 10s tcp-ut 2s curves secp384r1 client-sigalgs ECDSA+SHA256:RSA+SHA256 sigalgs ECDSA+SHA256 log-bufsize 10 set-proxy-v2-tlv-fmt(0x20) %[fc_pp_tlv(0x20)] # my comment + server webserv2 192.168.1.1:9300 maxconn 1000 ssl weight 10 inter 2s cookie BLAH slowstart 6000 proxy-v2-options authority,crc32c ws h1 pool-low-conn 128 hash-key akey pool-conn-name apoolconnname # {"comment": "my structured comment", "id": "my_random_id_for_server"} http-request set-dst hdr(x-dst) http-request set-dst-port int(4000) http-check connect diff --git a/test/expected/structured.json b/test/expected/structured.json index 334d1195..6c0237f5 100644 --- a/test/expected/structured.json +++ b/test/expected/structured.json @@ -170,6 +170,8 @@ "grace": 10000, "group": "anderson", "h1_case_adjust_file": "/etc/headers.adjust", + "h1_accept_payload_with_any_method": true, + "h1_do_not_close_on_insecure_transfer_encoding": true, "h2_workaround_bogus_websocket_clients": true, "hard_stop_after": 2000, "http_client_options": { @@ -248,6 +250,7 @@ "quiet": true, "set_dumpable": true, "setcap": "cap_net_raw,cap_net_bind_service", + "stats_file": "/var/haproxy/my-stats", "stats_maxconn": 20, "strict_limits": true, "thread_groups": 1, @@ -974,7 +977,10 @@ "address": "192.168.1.1", "id": 1234, "name": "webserv", - "port": 9200 + "port": 9200, + "metadata": { + "comment": "my comment" + } }, "webserv2": { "cookie": "BLAH", @@ -993,7 +999,11 @@ "name": "webserv2", "port": 9300, "pool_conn_name": "apoolconnname", - "hash_key": "akey" + "hash_key": "akey", + "metadata": { + "comment": "my structured comment", + "id": "my_random_id_for_server" + } } } }, @@ -1675,6 +1685,12 @@ "var_name": "my_var", "var_scope": "req" }, + { + "type": "set-var-fmt", + "var_format": "%[src]:%[src_port]", + "var_name": "from", + "var_scope": "txn" + }, { "map_file": "map.lst", "map_keyfmt": "%[src]", @@ -1879,7 +1895,6 @@ { "cond": "unless", "cond_test": "src 192.168.0.0/16", - "return_content_type": "", "type": "deny" }, { @@ -3096,6 +3111,36 @@ "port": 1023, "shard": 1 } + }, + "tables": { + "t1": { + "expire": "5m", + "name": "t1", + "no_purge": true, + "size": "200k", + "store": "gpc0,conn_rate(30s)", + "type": "string", + "type_len": 1000 + }, + "t2": { + "expire": "5m", + "name": "t2", + "no_purge": true, + "size": "200k", + "store": "gpc0,gpc1,conn_rate(30s)", + "type": "string", + "type_len": 1000 + }, + "t9": { + "expire": "5m", + "name": "t9", + "no_purge": true, + "size": "200k", + "store": "gpc0,conn_rate(30s)", + "type": "string", + "type_len": 1000, + "write_to": "t2" + } } } }, diff --git a/test/server_test.go b/test/server_test.go index 507c889d..6467f6af 100644 --- a/test/server_test.go +++ b/test/server_test.go @@ -17,7 +17,6 @@ package test import ( "fmt" - "reflect" "testing" "github.com/google/go-cmp/cmp" @@ -143,6 +142,10 @@ func TestCreateEditDeleteServer(t *testing.T) { Name: "created", Address: "192.168.2.1", Port: &port, + Metadata: map[string]interface{}{ + "type": "good type", + "id": "my-id-12", + }, ServerParams: models.ServerParams{ Backup: "enabled", Check: "enabled", @@ -180,12 +183,7 @@ func TestCreateEditDeleteServer(t *testing.T) { if err != nil { t.Error(err.Error()) } - - if !reflect.DeepEqual(server, s) { - fmt.Printf("Created server: %v\n", server) - fmt.Printf("Given server: %v\n", s) - t.Error("Created server not equal to given server") - } + require.True(t, server.Equal(*s), "diff %v", cmp.Diff(server, s)) if v != version { t.Errorf("Version %v returned, expected %v", v, version) @@ -226,12 +224,7 @@ func TestCreateEditDeleteServer(t *testing.T) { if err != nil { t.Error(err.Error()) } - - if !reflect.DeepEqual(server, s) { - fmt.Printf("Edited server: %v\n", server) - fmt.Printf("Given server: %v\n", s) - t.Error("Edited server not equal to given server") - } + require.True(t, server.Equal(*s), "diff %v", cmp.Diff(server, s)) if v != version { t.Errorf("Version %v returned, expected %v", v, version) diff --git a/test/tcp_request_rule_test.go b/test/tcp_request_rule_test.go index 20f6cb76..47614a7c 100644 --- a/test/tcp_request_rule_test.go +++ b/test/tcp_request_rule_test.go @@ -251,39 +251,6 @@ func TestSerializeTCPRequestRule(t *testing.T) { }, expectedResult: "connection track-sc3 src table tr0 if TRUE", }, - { - input: models.TCPRequestRule{ - Type: models.TCPRequestRuleTypeConnection, - Action: models.TCPRequestRuleActionTrackDashSc0, - Cond: "if", - CondTest: "TRUE", - TrackKey: "src", - TrackTable: "tr0", - }, - expectedResult: "connection track-sc0 src table tr0 if TRUE", - }, - { - input: models.TCPRequestRule{ - Type: models.TCPRequestRuleTypeConnection, - Action: models.TCPRequestRuleActionTrackDashSc1, - Cond: "if", - CondTest: "TRUE", - TrackKey: "src", - TrackTable: "tr1", - }, - expectedResult: "connection track-sc1 src table tr1 if TRUE", - }, - { - input: models.TCPRequestRule{ - Type: models.TCPRequestRuleTypeConnection, - Action: models.TCPRequestRuleActionTrackDashSc2, - Cond: "if", - CondTest: "TRUE", - TrackKey: "src", - TrackTable: "tr2", - }, - expectedResult: "connection track-sc2 src table tr2 if TRUE", - }, { input: models.TCPRequestRule{ Type: models.TCPRequestRuleTypeContent, @@ -296,39 +263,6 @@ func TestSerializeTCPRequestRule(t *testing.T) { }, expectedResult: "content track-sc3 src table tr0 if TRUE", }, - { - input: models.TCPRequestRule{ - Type: models.TCPRequestRuleTypeContent, - Action: models.TCPRequestRuleActionTrackDashSc0, - Cond: "if", - CondTest: "TRUE", - TrackKey: "src", - TrackTable: "tr0", - }, - expectedResult: "content track-sc0 src table tr0 if TRUE", - }, - { - input: models.TCPRequestRule{ - Type: models.TCPRequestRuleTypeContent, - Action: models.TCPRequestRuleActionTrackDashSc1, - Cond: "if", - CondTest: "TRUE", - TrackKey: "src", - TrackTable: "tr1", - }, - expectedResult: "content track-sc1 src table tr1 if TRUE", - }, - { - input: models.TCPRequestRule{ - Type: models.TCPRequestRuleTypeContent, - Action: models.TCPRequestRuleActionTrackDashSc2, - Cond: "if", - CondTest: "TRUE", - TrackKey: "src", - TrackTable: "tr2", - }, - expectedResult: "content track-sc2 src table tr2 if TRUE", - }, { input: models.TCPRequestRule{ Type: models.TCPRequestRuleTypeSession, @@ -341,39 +275,6 @@ func TestSerializeTCPRequestRule(t *testing.T) { }, expectedResult: "session track-sc3 src table tr0 if TRUE", }, - { - input: models.TCPRequestRule{ - Type: models.TCPRequestRuleTypeSession, - Action: models.TCPRequestRuleActionTrackDashSc0, - Cond: "if", - CondTest: "TRUE", - TrackKey: "src", - TrackTable: "tr0", - }, - expectedResult: "session track-sc0 src table tr0 if TRUE", - }, - { - input: models.TCPRequestRule{ - Type: models.TCPRequestRuleTypeSession, - Action: models.TCPRequestRuleActionTrackDashSc1, - Cond: "if", - CondTest: "TRUE", - TrackKey: "src", - TrackTable: "tr1", - }, - expectedResult: "session track-sc1 src table tr1 if TRUE", - }, - { - input: models.TCPRequestRule{ - Type: models.TCPRequestRuleTypeSession, - Action: models.TCPRequestRuleActionTrackDashSc2, - Cond: "if", - CondTest: "TRUE", - TrackKey: "src", - TrackTable: "tr2", - }, - expectedResult: "session track-sc2 src table tr2 if TRUE", - }, { input: models.TCPRequestRule{ Type: models.TCPRequestRuleTypeSession, diff --git a/test/version_test.go b/test/version_test.go index 05bf1e41..0701baf4 100644 --- a/test/version_test.go +++ b/test/version_test.go @@ -18,6 +18,9 @@ package test import ( "io/ioutil" "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func generateConfig(config string) (string, error) { @@ -32,6 +35,34 @@ func generateConfig(config string) (string, error) { return f.Name(), nil } +func TestClient_PostRawConfiguration(t *testing.T) { + fVersion, err := generateConfig("") + require.NoError(t, err, "generateConfig") + + t.Cleanup(func() { + assert.NoError(t, deleteTestFile(fVersion), "clean-up") + }) + + c, err := prepareClient(fVersion) + require.NoError(t, err, "prepareClient") + + v, vErr := c.GetVersion("") + assert.Equal(t, int64(1), v, "initialized configuration must be 1") + // The user is providing a raw configuration with a wrong version such as metadata: + // this must be ignored and removed by Client Native + configWithVersion := `# _version=123 +global + daemon` + + err = c.PostRawConfiguration(&configWithVersion, 1, false) + require.NoError(t, err, "PostRawConfiguration") + + v, vErr = c.GetVersion("") + require.NoError(t, vErr, "GetVersion") + + assert.Equal(t, int64(2), v, "123 should be dropped, and version bumped") +} + func TestClient_GetConfigurationVersion(t *testing.T) { configWithVersion := `# _version=10 global