From 7ea616246da3f9f96c34ea8a91a97ae22a68528b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sun, 1 Dec 2024 20:55:21 +0100 Subject: [PATCH] added tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan-Otto Kröpke --- internal/perfdata/collector.go | 2 ++ internal/utils/testutils/testutils.go | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/perfdata/collector.go b/internal/perfdata/collector.go index 1267ba047..c949b0e92 100644 --- a/internal/perfdata/collector.go +++ b/internal/perfdata/collector.go @@ -315,9 +315,11 @@ func (c *Collector) Close() { if c.collectCh != nil { close(c.collectCh) } + if c.counterValuesCh != nil { close(c.counterValuesCh) } + if c.errorCh != nil { close(c.errorCh) } diff --git a/internal/utils/testutils/testutils.go b/internal/utils/testutils/testutils.go index bd87ccd15..89ef9bf44 100644 --- a/internal/utils/testutils/testutils.go +++ b/internal/utils/testutils/testutils.go @@ -21,7 +21,6 @@ import ( "log/slog" "os" "sync" - "syscall" "testing" "time" @@ -32,6 +31,7 @@ import ( "github.com/prometheus-community/windows_exporter/pkg/collector" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/require" + "golang.org/x/sys/windows" ) func FuncBenchmarkCollector[C collector.Collector](b *testing.B, name string, collectFunc collector.BuilderWithFlags[C]) { @@ -92,6 +92,7 @@ func TestCollector[C collector.Collector, V interface{}](t *testing.T, fn func(* }() err = c.Build(logger, miSession) + switch { case err == nil: case errors.Is(err, mi.MI_RESULT_INVALID_NAMESPACE), @@ -108,7 +109,7 @@ func TestCollector[C collector.Collector, V interface{}](t *testing.T, fn func(* switch { // container collector - case errors.Is(err, syscall.Errno(2151088411)), + case errors.Is(err, windows.Errno(2151088411)), errors.Is(err, perfdata.ErrPerformanceCounterNotInitialized), errors.Is(err, perfdata.ErrNoData), errors.Is(err, mi.MI_RESULT_INVALID_NAMESPACE),