// SPDX-License-Identifier: Apache-2.0 // // Copyright The Prometheus Authors // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. //go:build windows package testutils import ( "errors" "fmt" "testing" "github.com/prometheus-community/windows_exporter/internal/pdh" "github.com/prometheus-community/windows_exporter/internal/types" "github.com/stretchr/testify/require" ) func TestNoDataOnly(t *testing.T) { t.Parallel() failure := errors.New("collector failed") for _, tc := range []struct { name string err error want bool }{ {name: "nil"}, {name: "PDH no data", err: pdh.ErrNoData, want: true}, {name: "collector no data", err: types.ErrNoData, want: true}, {name: "wrapped", err: fmt.Errorf("empty instances: %w", pdh.ErrNoData), want: true}, {name: "joined empty groups", err: errors.Join(pdh.ErrNoData, types.ErrNoData), want: true}, {name: "failure", err: failure}, {name: "mixed failures", err: errors.Join(pdh.ErrNoData, failure)}, {name: "nested mixed failures", err: fmt.Errorf("child: %w", errors.Join(pdh.ErrNoData, failure))}, } { t.Run(tc.name, func(t *testing.T) { t.Parallel() require.Equal(t, tc.want, noDataOnly(tc.err)) }) } }