test: added unit tests for the pkg/util package (#894)

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>
This commit is contained in:
Vaibhav Malik
2024-02-22 21:51:33 +05:30
committed by GitHub
parent 98286a965e
commit 6e640e6921
2 changed files with 544 additions and 4 deletions

View File

@@ -23,6 +23,7 @@ import (
"fmt"
"os"
"regexp"
"strings"
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
v1 "k8s.io/api/core/v1"
@@ -216,11 +217,18 @@ func EnsureDirExists(dir string) error {
}
func MapToString(m map[string]string) string {
var result string
for k, v := range m {
result += fmt.Sprintf("%s=%s,", k, v)
// Handle empty map case
if len(m) == 0 {
return ""
}
return result[:len(result)-1]
var pairs []string
for k, v := range m {
pairs = append(pairs, fmt.Sprintf("%s=%s", k, v))
}
// Efficient string joining
return strings.Join(pairs, ",")
}
func LabelsIncludeAny(predefinedSelector, Labels map[string]string) bool {