chore(reposerver): Fix modernize linter (#26315)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Blake Pettersson <blake.pettersson@gmail.com>
This commit is contained in:
Matthieu MOREL
2026-02-07 18:34:35 +01:00
committed by GitHub
parent 6b2b0668be
commit 342aea457f
5 changed files with 15 additions and 22 deletions

View File

@@ -7,7 +7,7 @@ import (
"fmt"
"hash/fnv"
"math"
"sort"
"slices"
"strings"
"time"
@@ -151,9 +151,7 @@ func clusterRuntimeInfoKey(info ClusterRuntimeInfo) uint32 {
// check if info is nil, the caller must do that.
func clusterRuntimeInfoKeyUnhashed(info ClusterRuntimeInfo) string {
apiVersions := info.GetApiVersions()
sort.Slice(apiVersions, func(i, j int) bool {
return apiVersions[i] < apiVersions[j]
})
slices.Sort(apiVersions)
return info.GetKubeVersion() + "|" + strings.Join(apiVersions, ",")
}

View File

@@ -1122,9 +1122,9 @@ func getHelmDependencyRepos(appPath string) ([]*v1alpha1.Repository, error) {
repos = append(repos, &v1alpha1.Repository{
Name: r.Repository[1:],
})
} else if strings.HasPrefix(r.Repository, "alias:") {
} else if after, ok := strings.CutPrefix(r.Repository, "alias:"); ok {
repos = append(repos, &v1alpha1.Repository{
Name: strings.TrimPrefix(r.Repository, "alias:"),
Name: after,
})
} else if u, err := url.Parse(r.Repository); err == nil && (u.Scheme == "https" || u.Scheme == "oci") {
repo := &v1alpha1.Repository{

View File

@@ -949,7 +949,7 @@ func TestManifestGenErrorCacheFileContentsChange(t *testing.T) {
PauseGenerationOnFailureForRequests: 4,
}
for step := 0; step < 3; step++ {
for step := range 3 {
// step 1) Attempt to generate manifests against invalid helm chart (should return uncached error)
// step 2) Attempt to generate manifest against valid helm chart (should succeed and return valid response)
// step 3) Attempt to generate manifest against invalid helm chart (should return cached value from step 2)
@@ -1028,7 +1028,7 @@ func TestManifestGenErrorCacheByMinutesElapsed(t *testing.T) {
}
// 1) Put the cache into the failure state
for x := 0; x < 2; x++ {
for x := range 2 {
res, err := service.GenerateManifest(t.Context(), &apiclient.ManifestRequest{
Repo: &v1alpha1.Repository{},
AppName: "test",
@@ -1088,7 +1088,7 @@ func TestManifestGenErrorCacheRespectsNoCache(t *testing.T) {
}
// 1) Put the cache into the failure state
for x := 0; x < 2; x++ {
for x := range 2 {
res, err := service.GenerateManifest(t.Context(), &apiclient.ManifestRequest{
Repo: &v1alpha1.Repository{},
AppName: "test",
@@ -4337,10 +4337,8 @@ func TestGetRefs_CacheWithLockDisabled(t *testing.T) {
t.Cleanup(cacheMocks.mockCache.StopRedisCallback)
var wg sync.WaitGroup
numberOfCallers := 10
for i := 0; i < numberOfCallers; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for range numberOfCallers {
wg.Go(func() {
client, err := git.NewClient("file://"+dir, git.NopCreds{}, true, false, "", "", git.WithCache(cacheMocks.cache, true))
require.NoError(t, err)
refs, err := client.LsRefs()
@@ -4348,7 +4346,7 @@ func TestGetRefs_CacheWithLockDisabled(t *testing.T) {
assert.NotNil(t, refs)
assert.NotEmpty(t, refs.Branches, "Expected branches to be populated")
assert.NotEmpty(t, refs.Branches[0])
}()
})
}
wg.Wait()
// Unlock should not have been called
@@ -4393,10 +4391,8 @@ func TestGetRefs_CacheWithLock(t *testing.T) {
t.Cleanup(cacheMocks.mockCache.StopRedisCallback)
var wg sync.WaitGroup
numberOfCallers := 10
for i := 0; i < numberOfCallers; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for range numberOfCallers {
wg.Go(func() {
client, err := git.NewClient("file://"+dir, git.NopCreds{}, true, false, "", "", git.WithCache(cacheMocks.cache, true))
require.NoError(t, err)
refs, err := client.LsRefs()
@@ -4404,7 +4400,7 @@ func TestGetRefs_CacheWithLock(t *testing.T) {
assert.NotNil(t, refs)
assert.NotEmpty(t, refs.Branches, "Expected branches to be populated")
assert.NotEmpty(t, refs.Branches[0])
}()
})
}
wg.Wait()
// Unlock should not have been called

View File

@@ -36,7 +36,7 @@ func getApplicationRootPath(q *apiclient.ManifestRequest, appPath, repoPath stri
}(len(commonParts), len(parts))
// check if diverge /disjoint in some point
for i := 0; i < minLen; i++ {
for i := range minLen {
if commonParts[i] != parts[i] {
commonParts = commonParts[:i]
disjoint = true
@@ -55,7 +55,7 @@ func getApplicationRootPath(q *apiclient.ManifestRequest, appPath, repoPath stri
// getPaths retrieves all absolute paths associated with the generation of application manifests.
func getPaths(q *apiclient.ManifestRequest, appPath, repoPath string) []string {
var paths []string
for _, annotationPath := range strings.Split(q.AnnotationManifestGeneratePaths, ";") {
for annotationPath := range strings.SplitSeq(q.AnnotationManifestGeneratePaths, ";") {
if annotationPath == "" {
continue
}

View File

@@ -34,7 +34,6 @@ func TestGetCommonRootPath(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()