| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package vsphere |
| 4 | |
| 5 | import ( |
| 6 | "sort" |
| 7 | "testing" |
| 8 | |
| 9 | "github.com/netdata/netdata/go/plugins/pkg/metrix" |
| 10 | rs "github.com/netdata/netdata/go/plugins/plugin/go.d/collector/vsphere/resources" |
| 11 | "github.com/stretchr/testify/require" |
| 12 | ) |
| 13 | |
| 14 | func firstSortedHost(t *testing.T, collr *Collector) *rs.Host { |
| 15 | t.Helper() |
| 16 | |
| 17 | hosts := make([]*rs.Host, 0, len(collr.resources.Hosts)) |
| 18 | for _, host := range collr.resources.Hosts { |
| 19 | hosts = append(hosts, host) |
| 20 | } |
| 21 | sort.Slice(hosts, func(i, j int) bool { |
| 22 | return hosts[i].ID < hosts[j].ID |
| 23 | }) |
| 24 | require.NotEmpty(t, hosts) |
| 25 | return hosts[0] |
| 26 | } |
| 27 | |
| 28 | func firstSortedVM(t *testing.T, collr *Collector) *rs.VM { |
| 29 | t.Helper() |
| 30 | |
| 31 | vms := sortedVMs(collr.resources.VMs) |
| 32 | require.NotEmpty(t, vms) |
| 33 | return vms[0] |
| 34 | } |
| 35 | |
| 36 | func countMetricSeries(reader metrix.Reader, name string) (count int) { |
| 37 | reader.ForEachByName(name, func(metrix.LabelView, metrix.SampleValue) { |
| 38 | count++ |
| 39 | }) |
| 40 | return count |
| 41 | } |
| 42 | |
| 43 | //go:fix inline |
| 44 | func boolPtr(value bool) *bool { |
| 45 | return new(value) |
| 46 | } |