Lint prometheus stats.

This commit is contained in:
Joachim Bauch 2021-04-23 14:30:49 +02:00
parent 70f9f7ea91
commit 5d431e5612
No known key found for this signature in database
GPG Key ID: 77C1D22D53E15F02
4 changed files with 50 additions and 0 deletions

30
mcu_common_test.go Normal file
View File

@ -0,0 +1,30 @@
/**
* Standalone signaling server for the Nextcloud Spreed app.
* Copyright (C) 2021 struktur AG
*
* @author Joachim Bauch <bauch@struktur.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package signaling
import (
"testing"
)
func TestCommonMcuStats(t *testing.T) {
collectAndLint(t, commonMcuStats...)
}

View File

@ -106,4 +106,6 @@ func TestPublisherStatsCounter(t *testing.T) {
checkStatsValue(t, statsMcuPublisherStreamTypesCurrent.WithLabelValues("video"), 0)
checkStatsValue(t, statsMcuSubscriberStreamTypesCurrent.WithLabelValues("audio"), 0)
checkStatsValue(t, statsMcuSubscriberStreamTypesCurrent.WithLabelValues("video"), 0)
collectAndLint(t, commonMcuStats...)
}

View File

@ -25,6 +25,10 @@ import (
"testing"
)
func TestMcuProxyStats(t *testing.T) {
collectAndLint(t, proxyMcuStats...)
}
func newProxyConnectionWithCountry(country string) *mcuProxyConnection {
conn := &mcuProxyConnection{}
conn.country.Store(country)

View File

@ -37,3 +37,17 @@ func checkStatsValue(t *testing.T, collector prometheus.Collector, value float64
t.Errorf("Expected value %f for %s, got %f", value, desc, v)
}
}
func collectAndLint(t *testing.T, collectors ...prometheus.Collector) {
for _, collector := range collectors {
problems, err := testutil.CollectAndLint(collector)
if err != nil {
t.Errorf("Error linting %+v: %s", collector, err)
continue
}
for _, problem := range problems {
t.Errorf("Problem with %s: %s", problem.Metric, problem.Text)
}
}
}