From 5d431e5612194466c6b1ebee27abc85331f94df1 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Fri, 23 Apr 2021 14:30:49 +0200 Subject: [PATCH] Lint prometheus stats. --- mcu_common_test.go | 30 ++++++++++++++++++++++++++++++ mcu_janus_test.go | 2 ++ mcu_proxy_test.go | 4 ++++ stats_prometheus_test.go | 14 ++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 mcu_common_test.go diff --git a/mcu_common_test.go b/mcu_common_test.go new file mode 100644 index 0000000..0609ef3 --- /dev/null +++ b/mcu_common_test.go @@ -0,0 +1,30 @@ +/** + * Standalone signaling server for the Nextcloud Spreed app. + * Copyright (C) 2021 struktur AG + * + * @author Joachim Bauch + * + * @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 . + */ +package signaling + +import ( + "testing" +) + +func TestCommonMcuStats(t *testing.T) { + collectAndLint(t, commonMcuStats...) +} diff --git a/mcu_janus_test.go b/mcu_janus_test.go index 1d5321e..975089b 100644 --- a/mcu_janus_test.go +++ b/mcu_janus_test.go @@ -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...) } diff --git a/mcu_proxy_test.go b/mcu_proxy_test.go index 8fc3422..1232602 100644 --- a/mcu_proxy_test.go +++ b/mcu_proxy_test.go @@ -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) diff --git a/stats_prometheus_test.go b/stats_prometheus_test.go index f573629..3031d41 100644 --- a/stats_prometheus_test.go +++ b/stats_prometheus_test.go @@ -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) + } + } +}