Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes.d/slices-contains.change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace manual slice membership checks with `slices.Contains`
8 changes: 2 additions & 6 deletions internal/exec/stages/disks/luks.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"path"
"path/filepath"
"regexp"
"slices"
"strconv"
"strings"

Expand Down Expand Up @@ -572,12 +573,7 @@ func newLuksDump(devAlias string) (LuksDump, error) {
}

func (d LuksDump) hasFlag(flag string) bool {
for _, v := range d.Config.Flags {
if v == flag {
return true
}
}
return false
return slices.Contains(d.Config.Flags, flag)
}

// collect the cex card domains xx.xxxx
Expand Down
9 changes: 2 additions & 7 deletions internal/resource/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"net/http"
"net/url"
"os"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -306,13 +307,7 @@ func shouldRetryHttp(statusCode int, opts FetchOptions) bool {
return true
}

for _, retryCode := range opts.RetryCodes {
if statusCode == retryCode {
return true
}
}

return false
return slices.Contains(opts.RetryCodes, statusCode)
}

// httpReaderWithHeader performs an HTTP request on the provided URL with the
Expand Down
44 changes: 44 additions & 0 deletions internal/resource/http_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2026 Red Hat, Inc.
//
// 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 resource

import "testing"

func TestShouldRetryHttp(t *testing.T) {
tests := []struct {
name string
statusCode int
retryCodes []int
out bool
}{
{"nil", 429, nil, false},
{"empty", 429, []int{}, false},
{"one", 429, []int{429}, true},
{"first", 408, []int{408, 429}, true},
{"last", 429, []int{408, 429}, true},
{"missing", 404, []int{408, 429}, false},
{"below server error", 499, nil, false},
{"server error", 500, nil, true},
{"higher server error", 503, []int{}, true},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
opts := FetchOptions{RetryCodes: test.retryCodes}
if got := shouldRetryHttp(test.statusCode, opts); got != test.out {
t.Errorf("shouldRetryHttp(%d, %+v) = %t, want %t", test.statusCode, opts, got, test.out)
}
})
}
}
9 changes: 3 additions & 6 deletions internal/util/str.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@

package util

import "slices"

func StrSliceContains(slice []string, s string) bool {
for _, e := range slice {
if e == s {
return true
}
}
return false
return slices.Contains(slice, s)
}
Loading