diff --git a/.github/workflows/pre-main.yaml b/.github/workflows/pre-main.yaml index e8c2769df..ab3b742a5 100644 --- a/.github/workflows/pre-main.yaml +++ b/.github/workflows/pre-main.yaml @@ -79,7 +79,7 @@ jobs: - name: Golangci-lint uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1 with: - version: v1.56 + version: v1.58 args: --timeout 10m0s - name: Checkmake diff --git a/.golangci.yml b/.golangci.yml index 131ef118e..3b3cd95ba 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -22,7 +22,7 @@ linters-settings: min-complexity: 20 goimports: local-prefixes: github.com/golangci/golangci-lint - gomnd: + mnd: settings: mnd: # do not include the "operation" and "assign" @@ -63,7 +63,7 @@ linters: - gocyclo - gofmt - goimports - - gomnd + - mnd - goprintffuncname - gosec - gosimple @@ -106,9 +106,21 @@ issues: # Ignore magic numbers, inline strings and function length in tests. - path: _test\.go linters: - - gomnd + - mnd - goconst - funlen + - path: config/config.go + linters: + - mnd + - path: _scaling.go + linters: + - gocritic + - path: hugepages.go + linters: + - mnd + - path: scheduling.go + linters: + - mnd # Ignore line length for string assignments (do not try and wrap regex definitions) - linters: - lll @@ -123,6 +135,6 @@ issues: # golangci.com configuration # https://github.com/golangci/golangci/wiki/Configuration service: - golangci-lint-version: 1.56.x # use the fixed version to not introduce new linters unexpectedly + golangci-lint-version: 1.58.x # use the fixed version to not introduce new linters unexpectedly prepare: - echo "here I can run custom commands, but no preparation needed for this repo" diff --git a/Makefile b/Makefile index a8c68ba31..ab8624429 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ GIT_COMMIT=$(shell script/create-version-files.sh) GIT_RELEASE=$(shell script/get-git-release.sh) GIT_PREVIOUS_RELEASE=$(shell script/get-git-previous-release.sh) CLAIM_FORMAT_VERSION=$(shell script/get-claim-version.sh) -GOLANGCI_VERSION=v1.56.2 +GOLANGCI_VERSION=v1.58.1 LINKER_TNF_RELEASE_FLAGS=-X github.com/test-network-function/cnf-certification-test/pkg/versions.GitCommit=${GIT_COMMIT} LINKER_TNF_RELEASE_FLAGS+= -X github.com/test-network-function/cnf-certification-test/pkg/versions.GitRelease=${GIT_RELEASE} LINKER_TNF_RELEASE_FLAGS+= -X github.com/test-network-function/cnf-certification-test/pkg/versions.GitPreviousRelease=${GIT_PREVIOUS_RELEASE} diff --git a/cmd/tnf/check/results/results.go b/cmd/tnf/check/results/results.go index 2635387ef..1f8d4f2f2 100644 --- a/cmd/tnf/check/results/results.go +++ b/cmd/tnf/check/results/results.go @@ -152,9 +152,9 @@ func getExpectedTestResults(templateFileName string) (map[string]string, error) func printTestResultsMismatch(mismatchedTestCases []string, actualResults, expectedResults map[string]string) { fmt.Printf("\n") - fmt.Println(strings.Repeat("-", 96)) //nolint:gomnd // table line + fmt.Println(strings.Repeat("-", 96)) //nolint:mnd // table line fmt.Printf("| %-58s %-19s %s |\n", "TEST_CASE", "EXPECTED_RESULT", "ACTUAL_RESULT") - fmt.Println(strings.Repeat("-", 96)) //nolint:gomnd // table line + fmt.Println(strings.Repeat("-", 96)) //nolint:mnd // table line for _, testCase := range mismatchedTestCases { expectedResult, exist := expectedResults[testCase] if !exist { @@ -165,7 +165,7 @@ func printTestResultsMismatch(mismatchedTestCases []string, actualResults, expec actualResult = resultMiss } fmt.Printf("| %-54s %19s %17s |\n", testCase, expectedResult, actualResult) - fmt.Println(strings.Repeat("-", 96)) //nolint:gomnd // table line + fmt.Println(strings.Repeat("-", 96)) //nolint:mnd // table line } } diff --git a/cmd/tnf/generate/qe_coverage/qe_coverage.go b/cmd/tnf/generate/qe_coverage/qe_coverage.go index 9e4d2bc86..73425b913 100644 --- a/cmd/tnf/generate/qe_coverage/qe_coverage.go +++ b/cmd/tnf/generate/qe_coverage/qe_coverage.go @@ -10,6 +10,10 @@ import ( "github.com/test-network-function/test-network-function-claim/pkg/claim" ) +const ( + multiplier = 100.0 +) + type TestCoverageSummaryReport struct { CoverageByTestSuite map[string]TestSuiteQeCoverage TotalCoveragePercentage float32 @@ -98,14 +102,14 @@ func GetQeCoverage(catalog map[claim.Identifier]claim.TestCaseDescription) TestC } // Update this test suite's coverage percentage - tsQeCoverage.Coverage = 100.0 * (float32(tsQeCoverage.TestCasesWithQe) / float32(tsQeCoverage.TestCases)) + tsQeCoverage.Coverage = multiplier * (float32(tsQeCoverage.TestCasesWithQe) / float32(tsQeCoverage.TestCases)) qeCoverageByTestSuite[tsName] = tsQeCoverage } totalCoverage := float32(0) if totalTcs > 0 { - totalCoverage = 100.0 * (float32(totalTcsWithQe) / float32(totalTcs)) + totalCoverage = multiplier * (float32(totalTcsWithQe) / float32(totalTcs)) } return TestCoverageSummaryReport{ diff --git a/cnf-certification-test/lifecycle/scaling/crd_scaling.go b/cnf-certification-test/lifecycle/scaling/crd_scaling.go index b59ff5a3f..525a035b5 100644 --- a/cnf-certification-test/lifecycle/scaling/crd_scaling.go +++ b/cnf-certification-test/lifecycle/scaling/crd_scaling.go @@ -119,15 +119,13 @@ func TestScaleHPACrd(cr *provider.CrScale, hpa *scalingv1.HorizontalPodAutoscale namespace := cr.GetNamespace() hpscaler := clients.K8sClient.AutoscalingV1().HorizontalPodAutoscalers(namespace) - var min int32 + min := int32(1) if hpa.Spec.MinReplicas != nil { min = *hpa.Spec.MinReplicas - } else { - min = 1 } replicas := cr.Spec.Replicas name := cr.GetName() - max := hpa.Spec.MaxReplicas + if replicas <= 1 { // scale up replicas++ @@ -139,7 +137,7 @@ func TestScaleHPACrd(cr *provider.CrScale, hpa *scalingv1.HorizontalPodAutoscale // scale down replicas-- logger.Debug("Scale DOWN HPA %s:%s to min=%d max=%d", namespace, hpa.Name, replicas, replicas) - pass = scaleHpaCRDHelper(hpscaler, hpa.Name, name, namespace, min, max, timeout, groupResourceSchema, logger) + pass = scaleHpaCRDHelper(hpscaler, hpa.Name, name, namespace, min, hpa.Spec.MaxReplicas, timeout, groupResourceSchema, logger) if !pass { return false } @@ -160,8 +158,8 @@ func TestScaleHPACrd(cr *provider.CrScale, hpa *scalingv1.HorizontalPodAutoscale } } // back the min and the max value of the hpa - logger.Debug("Back HPA %s:%s to min=%d max=%d", namespace, hpa.Name, min, max) - return scaleHpaCRDHelper(hpscaler, hpa.Name, name, namespace, min, max, timeout, groupResourceSchema, logger) + logger.Debug("Back HPA %s:%s to min=%d max=%d", namespace, hpa.Name, min, hpa.Spec.MaxReplicas) + return scaleHpaCRDHelper(hpscaler, hpa.Name, name, namespace, min, hpa.Spec.MaxReplicas, timeout, groupResourceSchema, logger) } func scaleHpaCRDHelper(hpscaler hps.HorizontalPodAutoscalerInterface, hpaName, crName, namespace string, min, max int32, timeout time.Duration, groupResourceSchema schema.GroupResource, logger *log.Logger) bool { diff --git a/cnf-certification-test/webserver/webserver.go b/cnf-certification-test/webserver/webserver.go index 28c58e49b..0de8ce064 100644 --- a/cnf-certification-test/webserver/webserver.go +++ b/cnf-certification-test/webserver/webserver.go @@ -33,6 +33,8 @@ type webServerContextKey string const ( logTimeout = 1000 + + readTimeoutSeconds = 10 ) var ( @@ -194,8 +196,8 @@ func installReqHandlers() { func StartServer(outputFolder string) { ctx := context.Background() server := &http.Server{ - Addr: ":8084", // Server address - ReadTimeout: 10 * time.Second, // Maximum duration for reading the entire request + Addr: ":8084", // Server address + ReadTimeout: readTimeoutSeconds * time.Second, // Maximum duration for reading the entire request BaseContext: func(l net.Listener) context.Context { ctx = context.WithValue(ctx, outputFolderCtxKey, outputFolder) return ctx diff --git a/docs/test-standalone.md b/docs/test-standalone.md index 7a917a713..608017e5f 100644 --- a/docs/test-standalone.md +++ b/docs/test-standalone.md @@ -28,7 +28,7 @@ need to be installed in your environment prior to runtime. Dependency|Minimum Version ---|--- [GoLang](https://golang.org/dl/)|1.22 -[golangci-lint](https://golangci-lint.run/usage/install/)|1.56.2 +[golangci-lint](https://golangci-lint.run/usage/install/)|1.58.1 [jq](https://stedolan.github.io/jq/)|1.6 [OpenShift Client](https://mirror.openshift.com/pub/openshift-v4/clients/ocp/)|4.12 diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 7a12a470e..1f9bdf253 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -46,6 +46,9 @@ const ( CheckResultTagRunning = Cyan + "RUNNING" + Reset CheckResultTagAborted = Red + "ABORTED" + Reset CheckResultTagError = Red + "ERROR" + Reset + + tickerPeriodSeconds = 10 + lineLength = 5 ) var CliCheckLogSniffer = &cliCheckLogSniffer{} @@ -74,7 +77,7 @@ func updateRunningCheckLine(checkName string, stopChan <-chan bool) { tickerPeriod := 1 * time.Second if !isTTY() { // Increase it to avoid flooding the text output. - tickerPeriod = 10 * time.Second + tickerPeriod = tickerPeriodSeconds * time.Second } timer := time.NewTicker(tickerPeriod) @@ -119,7 +122,7 @@ func printRunningCheckLine(checkName string, startTime time.Time, logLine string } // Add check's last log line only if the program is running in a tty/ptty. - maxAvailableWidth := getTerminalWidth() - len(line) - 5 + maxAvailableWidth := getTerminalWidth() - len(line) - lineLength if logLine != "" && maxAvailableWidth > minColsNeededForLogLine { // Append a cropped log line only if it makes sense due to the available space on the right. line += " " + cropLogLine(logLine, maxAvailableWidth) diff --git a/internal/clientsholder/clientsholder.go b/internal/clientsholder/clientsholder.go index 5fe4647fb..d3cca31b0 100644 --- a/internal/clientsholder/clientsholder.go +++ b/internal/clientsholder/clientsholder.go @@ -52,6 +52,10 @@ import ( clientcmdapi "k8s.io/client-go/tools/clientcmd/api" ) +const ( + DefaultTimeout = 10 * time.Second +) + type ClientsHolder struct { RestConfig *rest.Config DynamicClient dynamic.Interface @@ -270,8 +274,6 @@ func newClientsHolder(filenames ...string) (*ClientsHolder, error) { //nolint:fu if err != nil { return nil, fmt.Errorf("failed to get rest.Config: %v", err) } - - DefaultTimeout := 10 * time.Second clientsHolder.RestConfig.Timeout = DefaultTimeout clientsHolder.DynamicClient, err = dynamic.NewForConfig(clientsHolder.RestConfig) diff --git a/internal/log/log.go b/internal/log/log.go index 67ec79668..9227a3a24 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -118,7 +118,7 @@ func Error(msg string, args ...any) { func Fatal(msg string, args ...any) { Logf(globalLogger, LevelFatal, msg, args...) - fmt.Fprintf(os.Stderr, "\nFATAL: "+msg+"\n", args...) //nolint: goconst + fmt.Fprintf(os.Stderr, "\nFATAL: "+msg+"\n", args...) os.Exit(1) } @@ -187,7 +187,7 @@ func Logf(logger *Logger, level, format string, args ...any) { } var pcs [1]uintptr // skip [Callers, Log, LogWrapper] - runtime.Callers(3, pcs[:]) //nolint:gomnd + runtime.Callers(3, pcs[:]) //nolint:mnd r := slog.NewRecord(time.Now(), logLevel, fmt.Sprintf(format, args...), pcs[0]) _ = logger.l.Handler().Handle(context.Background(), r) } diff --git a/pkg/compatibility/compatibility.go b/pkg/compatibility/compatibility.go index 14039eac0..45e45732e 100644 --- a/pkg/compatibility/compatibility.go +++ b/pkg/compatibility/compatibility.go @@ -223,7 +223,7 @@ func IsRHELCompatible(machineVersion, ocpVersion string) bool { lifecycleInfo := GetLifeCycleDates() if entry, ok := lifecycleInfo[ocpVersion]; ok { - if len(entry.RHELVersionsAccepted) >= 2 { //nolint:gomnd + if len(entry.RHELVersionsAccepted) >= 2 { //nolint:mnd // Need to be a specific major.minor version for _, v := range entry.RHELVersionsAccepted { if v == machineVersion {