Skip to content

Commit

Permalink
chore(syslog-ng-ctl): do not compare unexported fields in tests
Browse files Browse the repository at this point in the history
Metrics are protobuf structs, they contain internal state, which should
not be compared.

For example, a simple `fmt.Sprint(metric.Label)` call can change the
internal state of `metric`.

Signed-off-by: László Várady <[email protected]>
  • Loading branch information
MrAnno committed Feb 29, 2024
1 parent 8f83483 commit 342649d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/syslog-ng-ctl/stats_prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
io_prometheus_client "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -330,7 +332,7 @@ func TestStatsPrometheus(t *testing.T) {
require.NoError(t, err)
sortMetricFamilies(res)
removeTimestamps(res)
if !assert.ElementsMatch(t, testCase.expected, res) {
if !cmp.Equal(t, testCase.expected, cmpopts.IgnoreUnexported()) {
assert.Equal(t, metricFamiliesToText(testCase.expected), metricFamiliesToText(res))
}
})
Expand Down

0 comments on commit 342649d

Please sign in to comment.