2020-09-02 15:24:17 +00:00
|
|
|
package usagemetrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/armon/go-metrics"
|
2021-08-18 14:27:15 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-10-23 19:21:37 +00:00
|
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
|
2020-09-02 15:24:17 +00:00
|
|
|
"github.com/hashicorp/consul/agent/consul/state"
|
|
|
|
)
|
|
|
|
|
|
|
|
type mockStateProvider struct {
|
|
|
|
mock.Mock
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockStateProvider) State() *state.Store {
|
|
|
|
retValues := m.Called()
|
|
|
|
return retValues.Get(0).(*state.Store)
|
|
|
|
}
|
|
|
|
|
2021-08-18 14:27:15 +00:00
|
|
|
func assertEqualGaugeMaps(t *testing.T, expectedMap, foundMap map[string]metrics.GaugeValue) {
|
|
|
|
t.Helper()
|
2020-09-02 15:24:17 +00:00
|
|
|
|
2021-08-18 14:27:15 +00:00
|
|
|
for key := range foundMap {
|
|
|
|
if _, ok := expectedMap[key]; !ok {
|
|
|
|
t.Errorf("found unexpected gauge key: %s", key)
|
|
|
|
}
|
|
|
|
}
|
2020-09-02 15:24:17 +00:00
|
|
|
|
2021-08-18 14:27:15 +00:00
|
|
|
for key, expected := range expectedMap {
|
|
|
|
if _, ok := foundMap[key]; !ok {
|
|
|
|
t.Errorf("did not find expected gauge key: %s", key)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
assert.Equal(t, expected, foundMap[key], "gauge key mismatch on %q", key)
|
2020-09-02 15:24:17 +00:00
|
|
|
}
|
|
|
|
}
|