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
14 changes: 6 additions & 8 deletions cmd/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"os"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -96,14 +97,11 @@ func buildChecks(enabled []string, unEnabled []string) ([]apiChecks.CheckName, [
func convertChecks(checks []string) ([]apiChecks.CheckName, error) {
var apiCheckSet []apiChecks.CheckName
for _, check := range checks {
checkFound := false
for _, checkName := range apiChecks.GetChecks() {
if apiChecks.CheckName(check) == checkName {
apiCheckSet = append(apiCheckSet, checkName)
checkFound = true
}
}
if !checkFound {
checkName := apiChecks.CheckName(check)
checkFound := slices.Contains(apiChecks.GetChecks(), checkName)
if checkFound {
apiCheckSet = append(apiCheckSet, checkName)
} else {
return apiCheckSet, fmt.Errorf("enabled check is invalid :%s", check)
}
}
Expand Down
8 changes: 3 additions & 5 deletions internal/chartverifier/checks/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ package checks
import (
"fmt"
"io"
"maps"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"regexp"
"slices"
"strings"

"helm.sh/helm/v3/pkg/chartutil"
Expand Down Expand Up @@ -245,11 +247,7 @@ func getImagesFromContent(content string) ([]string, error) {
imageMap[image] = struct{}{}
}

var images []string
for k := range imageMap {
images = append(images, k)
}

images := slices.Collect(maps.Keys(imageMap))
return images, nil
}

Expand Down
20 changes: 3 additions & 17 deletions internal/chartverifier/profiles/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"path/filepath"
"reflect"
"runtime"
"strings"
"slices"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -45,26 +45,12 @@ func TestProfile(t *testing.T) {
assert.Equal(t, testProfile.Version, diskProfile.Version, "Version mismatch")
assert.Equal(t, len(testProfile.Annotations), len(diskProfile.Annotations), "Annotations number mismatch")
for _, testAnnotation := range testProfile.Annotations {
found := false
for _, diskAnnotation := range diskProfile.Annotations {
if testAnnotation == diskAnnotation {
found = true
break
}
}
found := slices.Contains(diskProfile.Annotations, testAnnotation)
assert.True(t, found, fmt.Sprintf("Annotation not found : %s", testAnnotation))
}
assert.Equal(t, len(testProfile.Checks), len(diskProfile.Checks), "Checks number mismatch")
for _, testCheck := range testProfile.Checks {
found := false
for _, diskCheck := range diskProfile.Checks {
if strings.Compare(testCheck.Name, diskCheck.Name) == 0 {
if testCheck.Type == diskCheck.Type {
found = true
break
}
}
}
found := slices.Contains(diskProfile.Checks, testCheck)
assert.True(t, found, fmt.Sprintf("Check not matched : %s : %s", testCheck.Name, testCheck.Type))
}
assert.True(t, cmp.Equal(diskProfile, testProfile), "profiles do not match")
Expand Down
5 changes: 2 additions & 3 deletions pkg/chartverifier/reportsummary/reportSummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"maps"
"strings"

"golang.org/x/mod/semver"
Expand Down Expand Up @@ -66,9 +67,7 @@ func (r *ReportSummary) SetReport(report *report.Report) APIReportSummary {
}

func (r *ReportSummary) SetValues(values map[string]interface{}) APIReportSummary {
for key, element := range values {
r.options.values[key] = element
}
maps.Copy(r.options.values, values)
return r
}

Expand Down
41 changes: 6 additions & 35 deletions pkg/chartverifier/verifier/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package verifier
import (
"errors"
"fmt"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -119,13 +120,7 @@ type APIVerifier interface {
func validateBooleanKeys(v Verifier) error {
var err error
for key := range v.Inputs.Flags.BooleanFlags {
foundElement := false
for _, sliceElement := range setBooleanKeys {
if sliceElement == key {
foundElement = true
continue
}
}
foundElement := slices.Contains(setBooleanKeys[:], key)
if !foundElement {
err = fmt.Errorf("invalid boolean key name: %s", key)
}
Expand Down Expand Up @@ -153,13 +148,7 @@ func (v *Verifier) SetDuration(key DurationKey, duration time.Duration) APIVerif
func validateDurationKeys(v Verifier) error {
var err error
for key := range v.Inputs.Flags.DurationFlags {
foundElement := false
for _, sliceElement := range setDurationKeys {
if sliceElement == key {
foundElement = true
break
}
}
foundElement := slices.Contains(setDurationKeys[:], key)
if !foundElement {
err = fmt.Errorf("invalid duration key name: %s", key)
}
Expand All @@ -178,13 +167,7 @@ func (v *Verifier) SetString(key StringKey, value []string) APIVerifier {
func validateStringKeys(v Verifier) error {
var err error
for key := range v.Inputs.Flags.StringFlags {
foundElement := false
for _, sliceElement := range setStringKeys {
if sliceElement == key {
foundElement = true
break
}
}
foundElement := slices.Contains(setStringKeys[:], key)
if !foundElement {
err = fmt.Errorf("invalid string key name: %s", key)
}
Expand All @@ -209,13 +192,7 @@ func (v *Verifier) SetValues(valuesFlagName ValuesKey, values map[string]interfa
func validateValuesKeys(v Verifier) error {
var err error
for key := range v.Inputs.Flags.ValuesFlags {
foundElement := false
for _, sliceElement := range setValuesKeys {
if sliceElement == key {
foundElement = true
break
}
}
foundElement := slices.Contains(setValuesKeys[:], key)
if !foundElement {
err = fmt.Errorf("invalid values key name: %s", key)
}
Expand Down Expand Up @@ -261,13 +238,7 @@ func (v *Verifier) UnEnableChecks(checkNames []checks.CheckName) APIVerifier {
func validateChecks(v Verifier) error {
var err error
for checkName := range v.Inputs.Flags.Checks {
isValidCheckName := false
for _, validCheckName := range checks.GetChecks() {
if checkName == validCheckName {
isValidCheckName = true
break
}
}
isValidCheckName := slices.Contains(checks.GetChecks(), checkName)
if !isValidCheckName {
err = fmt.Errorf("invalid check name : %s", checkName)
return err
Expand Down