Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jan-Otto Kröpke <[email protected]>
  • Loading branch information
jkroepke committed Dec 1, 2024
1 parent 010af98 commit 5cab7f3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/collector/mssql/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
// Collect sends the metric values for each metric
// to the provided prometheus Metric channel.
func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
if len(c.mssqlInstances) == 0 {
return fmt.Errorf("no SQL instances found: %w", perfdata.ErrNoData)
}

errCh := make(chan error, len(c.collectorFns))
errs := make([]error, 0, len(c.collectorFns))

Expand Down
7 changes: 5 additions & 2 deletions internal/collector/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ var ConfigDefaults = Config{
scrapeInterval: 6 * time.Hour,
}

var ErrNoUpdates = errors.New("pending gather update metrics")
var (
ErrNoUpdates = errors.New("pending gather update metrics")
ErrUpdateServiceDisabled = errors.New("windows updates service is disabled")
)

type Collector struct {
config Config
Expand Down Expand Up @@ -234,7 +237,7 @@ func (c *Collector) scheduleUpdateStatus(ctx context.Context, logger *slog.Logge
}(hc)

if err != nil {
initErrCh <- fmt.Errorf("windows updates service is disabled: %w", err)
initErrCh <- ErrUpdateServiceDisabled

return
}
Expand Down
4 changes: 3 additions & 1 deletion internal/utils/testutils/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ func TestCollector[C collector.Collector, V interface{}](t *testing.T, fn func(*
errors.Is(err, perfdata.ErrNoData),
errors.Is(err, mi.MI_RESULT_INVALID_NAMESPACE),
errors.Is(err, mi.MI_RESULT_INVALID_QUERY),
errors.Is(err, update.ErrNoUpdates):
errors.Is(err, update.ErrNoUpdates),
errors.Is(err, update.ErrUpdateServiceDisabled):
t.Skip("collector not supported on this system")
default:
require.NoError(t, err)
}
Expand Down

0 comments on commit 5cab7f3

Please sign in to comment.