*: avoid using default wmi client. (#1590)

This commit is contained in:
Jan-Otto Kröpke
2024-08-30 00:26:15 +02:00
committed by GitHub
parent 3ce25ff1ef
commit 4f6e6e8b77
74 changed files with 558 additions and 655 deletions

View File

@@ -3,24 +3,11 @@
package utils
import (
"slices"
"sort"
"strings"
"github.com/prometheus-community/windows_exporter/pkg/types"
)
// ExpandEnabledChildCollectors used by more complex Collectors where user input specifies enabled child Collectors.
// Splits provided child Collectors and deduplicate.
func ExpandEnabledChildCollectors(enabled string) []string {
result := slices.Compact(strings.Split(enabled, ","))
// Result must order, to prevent test failures.
sort.Strings(result)
return result
}
func ExpandEnabledCollectors(enabled string) []string {
expanded := strings.ReplaceAll(enabled, types.DefaultCollectorsPlaceholder, types.DefaultCollectors)
separated := strings.Split(expanded, ",")

View File

@@ -1,7 +1,6 @@
package utils_test
import (
"reflect"
"sort"
"strings"
"testing"
@@ -10,38 +9,6 @@ import (
"github.com/prometheus-community/windows_exporter/pkg/utils"
)
func TestExpandChildCollectors(t *testing.T) {
t.Parallel()
cases := []struct {
name string
input string
expectedOutput []string
}{
{
name: "simple",
input: "testing1,testing2,testing3",
expectedOutput: []string{"testing1", "testing2", "testing3"},
},
{
name: "duplicate",
input: "testing1,testing2,testing2,testing3",
expectedOutput: []string{"testing1", "testing2", "testing3"},
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
t.Parallel()
output := utils.ExpandEnabledChildCollectors(c.input)
if !reflect.DeepEqual(output, c.expectedOutput) {
t.Errorf("Output mismatch, expected %+v, got %+v", c.expectedOutput, output)
}
})
}
}
func TestExpandEnabled(t *testing.T) {
t.Parallel()

View File

@@ -13,10 +13,6 @@ func BoolToFloat(b bool) float64 {
return 0.0
}
func HasValue(v *string) bool {
return !IsEmpty(v)
}
func IsEmpty(v *string) bool {
return v == nil || *v == ""
}