Files
threshold/internal/daemon/metric/testing.go
T
429247f407 [COMPLIANCE] Update Copyright Headers (#6282)
* [COMPLIANCE] Update Copyright and License Headers

* chore: make gen to generate files with copyright headers

* chore: update missed copyright headers

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Justin Nguyen <justin.nguyen@hashicorp.com>
2026-01-28 11:05:07 -06:00

51 lines
1.1 KiB
Go

// Copyright IBM Corp. 2020, 2025
// SPDX-License-Identifier: BUSL-1.1
package metric
import (
"context"
"testing"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
)
// testableObserverVec allows us to assert which observations are being made
// with which labels.
type TestableObserverVec struct {
Observations []*testableObserver
prometheus.ObserverVec
}
func (v *TestableObserverVec) With(l prometheus.Labels) prometheus.Observer {
ret := &testableObserver{Labels: l}
v.Observations = append(v.Observations, ret)
return ret
}
type testableObserver struct {
Labels prometheus.Labels
Observation float64
}
func (o *testableObserver) Observe(f float64) {
o.Observation = f
}
type TestInvoker struct {
T *testing.T
Called bool
RetErr error
}
func (i *TestInvoker) Invoke(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
i.Called = true
require.NotNil(i.T, ctx)
require.NotEmpty(i.T, method)
require.NotNil(i.T, req)
return i.RetErr
}