Skip to content

Commit

Permalink
test: added unit tests for the pkg/util package (#894)
Browse files Browse the repository at this point in the history
This commit adds new unit tests for the `pkg/util` package bumping the
code coverage to 84%

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
  • Loading branch information
VaibhavMalik4187 and AlexsJones committed Feb 22, 2024
1 parent 98286a9 commit 6e640e6
Show file tree
Hide file tree
Showing 2 changed files with 543 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"os"
"regexp"
"strings"

"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -216,11 +217,18 @@ func EnsureDirExists(dir string) error {
}

func MapToString(m map[string]string) string {
var result string
// Handle empty map case
if len(m) == 0 {
return ""
}

var pairs []string
for k, v := range m {
result += fmt.Sprintf("%s=%s,", k, v)
pairs = append(pairs, fmt.Sprintf("%s=%s", k, v))
}
return result[:len(result)-1]

// Efficient string joining
return strings.Join(pairs, ",")
}

func LabelsIncludeAny(predefinedSelector, Labels map[string]string) bool {
Expand Down
Loading

0 comments on commit 6e640e6

Please sign in to comment.