Skip to content

Commit

Permalink
Update GolangCI-lint to v1.58.1 (#2054)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrandon1 authored May 9, 2024
1 parent 52c32ae commit deca85b
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pre-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 16 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -63,7 +63,7 @@ linters:
- gocyclo
- gofmt
- goimports
- gomnd
- mnd
- goprintffuncname
- gosec
- gosimple
Expand Down Expand Up @@ -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
Expand All @@ -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"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
6 changes: 3 additions & 3 deletions cmd/tnf/check/results/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}

Expand Down
8 changes: 6 additions & 2 deletions cmd/tnf/generate/qe_coverage/qe_coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down
12 changes: 5 additions & 7 deletions cnf-certification-test/lifecycle/scaling/crd_scaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions cnf-certification-test/webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type webServerContextKey string

const (
logTimeout = 1000

readTimeoutSeconds = 10
)

var (
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/test-standalone.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const (
CheckResultTagRunning = Cyan + "RUNNING" + Reset
CheckResultTagAborted = Red + "ABORTED" + Reset
CheckResultTagError = Red + "ERROR" + Reset

tickerPeriodSeconds = 10
lineLength = 5
)

var CliCheckLogSniffer = &cliCheckLogSniffer{}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions internal/clientsholder/clientsholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion pkg/compatibility/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit deca85b

Please sign in to comment.